[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 532
  • Last Modified:

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().interrupt();
    }
    public void run() {
        try {
            int iTimeout = 3000;
            AbcTimerManager.getInstance().register(this, iTimeout);
            try {
                execProcAndMapResult();
            } catch (Exception ex) {
                // should catch InterruptedException here
            }
            AbcTimerManager.getInstance().unregister(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|AbcTimerManager|D|
   Registered listener 'com.xxx.SomeClass' to be interrupted in 3000 milliseconds.
|08/01/2007 18:20:39:772 AbcSingletonThreadPool.000|com.xxx.AbcTimerManager|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.InterruptedException

jkavx
0
jkavx
Asked:
jkavx
  • 4
  • 3
  • 2
1 Solution
 
asood314Commented:
Sounds like the exception is occuring in the outer try block.  Check your catch statement for that block.
0
 
jkavxAuthor Commented:
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.
0
 
asood314Commented:
Where does the stack trace say the exception is occuring?
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
jkavxAuthor Commented:
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().interrupt()" 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.InterruptedException
0
 
objectsCommented:
interrupt() does not necessarily cause an exception to be thrown. u need to handle throwing it yourself.

http://java.sun.com/docs/books/tutorial/essential/concurrency/interrupt.html
0
 
jkavxAuthor Commented:
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?
0
 
objectsCommented:
> 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
0
 
jkavxAuthor Commented:
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.
0
 
objectsCommented:
if the method is not interuptable then theres nothing u can do
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 4
  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now