Javamex

Java discussion forum to accompany the Javamex web site.

I see recommendation of handling InterruptedException to keep the interrupt flag,  like this:

catch (InterruptedException iex) {

   Thread.currentThread().interrupt();

}

 

But, if you do this, the thread ends immediately. If you have a finally clause after catch clause, it won't run. Even worse, all statements after the try/catch/finally won't run. I said, this ends the thread immediately, the whole stach cleared, no Exception rethrown. I feel this is an odd sematics - a big bug.

I am attaching two files. Compile them and run. (java 1.5).  Please comment.

 

InterruptOther.java

InterruptSelf.java

 

 

 

Views: 284

Reply to This

Replies to This Discussion

In terms of its defined behaviour, calling interrupt() on a thread does not make the thread end and doesn't prevent the finally clause from being executed. So you either have another bug in your code or a bug in your VM.

Have you tried running your code on a different VM?

Neil, right I posted my question. I tried compiling and running them in Windows where java 1.6 HAPPENED to be used to do so. I did not see the problem in java 1.6. So this is bug in java 1.5.  Thanks for getting back so quickly.

Reply to Discussion

RSS

© 2024   Created by Neil Coffey.   Powered by

Badges  |  Report an Issue  |  Terms of Service