jkavx
asked on
InterruptedException not caught
In the code below, the thread is being interrupted, but the InterruptedException is not being caught. This is legacy code that has been in use for at least 6 years. It was last tested about 2 years ago, at which time the InterruptedException was being handled. At some point, it stopped working. Because timeouts are rare, it hasn't been noticed. The only changes would have been changing to Java 1.4, and upgrading WebLogic servers. Does anyone understand why this InterruptedException would not be caught?
public class SomeClass implements Runnable, AbcTimerListener {
public void timerExpired(AbcTimerEvent event) {
event.getThread().interrup t();
}
public void run() {
try {
int iTimeout = 3000;
AbcTimerManager.getInstanc e().regist er(this, iTimeout);
try {
execProcAndMapResult();
} catch (Exception ex) {
// should catch InterruptedException here
}
AbcTimerManager.getInstanc e().unregi ster(this) ;
Details from the log indicate that the timeout is being handled, the thread is interrupted, but we never enter the catch block in the run() method. The log also indicates an uncaught InterruptedException.
|08/01/2007 18:20:39:713 AbcThreadPool.027|AbcTimer Manager|D|
Registered listener 'com.xxx.SomeClass' to be interrupted in 3000 milliseconds.
|08/01/2007 18:20:39:772 AbcSingletonThreadPool.000 |com.xxx.A bcTimerMan ager|D|
Interrupting listener: com.xxx.SomeClass
08/01/2007 18:20:39:871 AbcThreadPool.027|com.xxx. SomeClass $AbcExecuteThread|E|Thread in
AbcThreadPool had uncaught exception.
java.lang.InterruptedExcep tion
jkavx
public class SomeClass implements Runnable, AbcTimerListener {
public void timerExpired(AbcTimerEvent
event.getThread().interrup
}
public void run() {
try {
int iTimeout = 3000;
AbcTimerManager.getInstanc
try {
execProcAndMapResult();
} catch (Exception ex) {
// should catch InterruptedException here
}
AbcTimerManager.getInstanc
Details from the log indicate that the timeout is being handled, the thread is interrupted, but we never enter the catch block in the run() method. The log also indicates an uncaught InterruptedException.
|08/01/2007 18:20:39:713 AbcThreadPool.027|AbcTimer
Registered listener 'com.xxx.SomeClass' to be interrupted in 3000 milliseconds.
|08/01/2007 18:20:39:772 AbcSingletonThreadPool.000
Interrupting listener: com.xxx.SomeClass
08/01/2007 18:20:39:871 AbcThreadPool.027|com.xxx.
AbcThreadPool had uncaught exception.
java.lang.InterruptedExcep
jkavx
Sounds like the exception is occuring in the outer try block. Check your catch statement for that block.
ASKER
For the sake of brevity, I omitted the full code, but the outer try block would also catch the exception. It's not being caught there, either.
Where does the stack trace say the exception is occuring?
ASKER
There is no stack trace. The thread interruption has no effect. The code in the run() method is not interrupted and runs to completion. Debugging output in the timerExpired method confirms that the method is invoked and that "event.getThread().interru pt()" executes cleanly. This item in the log indicates that there was an uncaught InterruptedException:
08/01/2007 18:20:39:871 AbcThreadPool.027|com.xxx. SomeClass $AbcExecuteThread|E|Thread in
AbcThreadPool had uncaught exception.
java.lang.InterruptedExcep tion
08/01/2007 18:20:39:871 AbcThreadPool.027|com.xxx.
AbcThreadPool had uncaught exception.
java.lang.InterruptedExcep
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
It's possible that the message in the log about uncaught "InterruptedException" is deceptive. The code may be checking the status of the thread and writing the message because the thread's status is interrupted.
But this is code that has worked in the past. So I have 2 questions: what determines whether thread.interrupt() throws an InterruptedException, and did something change in Java 1.4 with regard to this?
But this is code that has worked in the past. So I have 2 questions: what determines whether thread.interrupt() throws an InterruptedException, and did something change in Java 1.4 with regard to this?
> what determines whether thread.interrupt() throws an InterruptedException
whether the method being calleed when interuptteed detects or throws it or not.
eg. sleep() will, but most won't Its up to the application to check for interrupts itself.
> and did something change in Java 1.4 with regard to this?
not that I can remember, but it was a long time ago
whether the method being calleed when interuptteed detects or throws it or not.
eg. sleep() will, but most won't Its up to the application to check for interrupts itself.
> and did something change in Java 1.4 with regard to this?
not that I can remember, but it was a long time ago
ASKER
The timeout being checked for involves the execution of a stored proc. So there's no way to check the status of the thread since there's a single line of code that's executing:
ResultSet rs = stmt.executeQuery();
The timerExpired() method needs to stop this thread. Is there an alternative to thread.interrupt()? I'm trying thread.destroy(), but get a NoSuchMethod error.
ResultSet rs = stmt.executeQuery();
The timerExpired() method needs to stop this thread. Is there an alternative to thread.interrupt()? I'm trying thread.destroy(), but get a NoSuchMethod error.
if the method is not interuptable then theres nothing u can do