Discuss Exiting a Runnable in the Java Help forum on Dev Shed. Exiting a Runnable Java Help forum discussing all Java platforms - J2ME, J2SE and J2EE - as well as relevant standards, APIs and frameworks such as Swing, Servlets, JSPs, Applets, Struts, Spring, Hibernate, ANT, EJB, and other Java-related topics.
Posts: 2,877
Time spent in forums: 1 Year 2 Weeks 21 h 28 m 20 sec
Reputation Power: 581
Exiting a Runnable
I have a runnable method that I want to exit immediately (not System.exit). It seems like it should be a trivial thing but I cannot find anything on doing that other than using something called 'interrupt' which I cannot come up with the right syntax to use. Using 'interrupt();' or 'this.interrupt()' is undefined for type runnable. What do I use? TIA.
__________________
There are 10 kinds of people in the world. Those that understand binary and those that don't.
Posts: 2,877
Time spent in forums: 1 Year 2 Weeks 21 h 28 m 20 sec
Reputation Power: 581
Thanks for the suggestion. I thought I figured out what was wrong. The interrupt method is part of the thread class and I needed to properly reference it which I was not doing before.
Code:
Thread.getCurrentThread().interrupt();
Unfortunately that seemed to behave like a noop. The runnable just kept going (yes, I verified that the interrupt was executed). Since I was under a time constraint I wound up changing the logic and rewrote everything so that there was no circumstance where I needed to interrupt the runnable like that.