|
From: Leif M. <le...@ta...> - 2003-04-23 23:23:07
|
Andy,
The Wrapper is never going to be able work around every problem
with a user application. The problems that you are talking about are
bugs in your application. The filters are designed to help in cases
where the user does not have complete control over an application's
source.
If you are having a problem with code throwing uncaught exceptions,
then catch them at the thread's root. I usually set up daemon threads
as follows:
public run()
{
while ( !m_shutdown )
{
try
{
// Real code goes here.
}
catch ( Throwable t )
{
System.out.println( "Unexpected error in xxx daemon:" );
t.printStackTrace();
// May want to wait a few seconds to avoid thrashing...
}
}
}
The above code is a last line of protection to prevent a critical thread
from terminating abnormally. This method has always worked for me
as there is no way for the thread to die without being caught by the
throwable catch. The thread can be stopped, but that method is
deprecated and does not usually happen unless you mean to.
Andy Barnett wrote:
> Now my application is restarted appropriately when a NPE occurs;
> however, I don't think this is a robust enough solution for my
> situation. If my application's main thread dies due to any exception,
> I need the Wrapper to restart it. I don't think I can express that
> completely with wrapper.filter properties.
If you have specific cases that you are worried about, I will look into the
feasibility of adding features to the Wrapper.
> Do I have other options?
The above code is simply a safety net. Neither this nor the protections
provided by the Wrapper are a replacement for fixing bugs in your
program.
Cheers,
Leif
|