jPOS
jPOS copied to clipboard
The Q2 based system stops working through TimerTask
It is quite easy to stop the system by using DefaultTimer.schedule(). The TimerTask passed there cannot throw any exceptions or errors (e.g. SpaceError).
It is documented in Timer javadoc
If the timer's task execution thread terminates unexpectedly, for example, because its stop method is invoked, any further attempt to schedule a task on the timer will result in an IllegalStateException, as if the timer's cancel method had been invoked.
As example the JDMBSpace implement TimerTasks
public void run () {
try {
gc();
} catch (Exception e) {
e.printStackTrace(); // this should never happen
}
}
but at the end of the gc() method we have ... SpaceError
public void gc () {
final String GCKEY = "GC$" + Integer.toString (hashCode());
final long TIMEOUT = 24 * 3600 * 1000;
Object obj;
try {
synchronized (this) {
...
}
...
} catch (IOException e) {
throw new SpaceError (e);
}
}
To force this error for JDBMSpace, just change the name (in operation) of the directory where space is saved.
This type of error often appears and causes the DefaultTimer singleton to stop working.
I think that the passed TimerTask should be protected against such a situation. You would have to add a wrapper to TimerTask with error handling with e.printStackTrace() logging;
On the other hand, SpaceError itself doesn't seem like a good idea to me. See PMD DoNotExtendJavaLangError and Error javadoc
is also a subclass of Error because most applications should not try to catch it.
and should be converted to unchecked eg. SpaceException.
I think we should never use the DefaultTimer and move to private scheduled executors. Thanks for raising this issue.