#1
  1. No Profile Picture
    Contributing User
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Jul 2003
    Posts
    3,230
    Rep Power
    593

    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.
  2. #2
  3. Java Junkie
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Jan 2004
    Location
    Mobile, Alabama
    Posts
    4,020
    Rep Power
    1285
    You could use a boolean to control your loop, and if you want to exit, set the boolean to false and use continue.
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Jul 2003
    Posts
    3,230
    Rep Power
    593
    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.
    There are 10 kinds of people in the world. Those that understand binary and those that don't.

IMN logo majestic logo threadwatch logo seochat tools logo