Results 1 to 3 of 3
  1. #1
    kailash is offline Member
    Join Date
    Feb 2011
    Posts
    3
    Rep Power
    0

    Default stopping the thread

    how can we stop the thread, without using stop method.

  2. #2
    Petr's Avatar
    Petr is offline Senior Member
    Join Date
    Jan 2011
    Location
    Russia
    Posts
    618
    Rep Power
    4

    Default

    What you mean "stop the thread"? You can create boolean variable and check it in run() method your thread.
    Skype: petrarsentev
    http://TrackStudio.com

  3. #3
    Hibernate's Avatar
    Hibernate is offline Senior Member
    Join Date
    Dec 2010
    Location
    Stockholm, Sweden
    Posts
    222
    Blog Entries
    9
    Rep Power
    4

    Default

    You can use the 'stop' method, but doing so may lead to arbitrary behaviour from the program, as resources may be distributed erroneously, if not doing it perfectly.

    You should used the 'interrupt' method.
    If the thread is about to sleep, or alike, InterruptedException will thrown if 'interrupt' has been called. You can also check manually of it has been called.
    Ex animo! Hibernate
    Java, Arch Linux, C, GPL v3, Bash, Eclipse, Linux VT, GNOME 2 and many buttons on windows.

Similar Threads

  1. Stopping a thread using a stop button - GUI
    By Ben1 in forum New To Java
    Replies: 5
    Last Post: 01-27-2011, 04:21 PM
  2. Stopping a thread
    By Arne in forum Threads and Synchronization
    Replies: 9
    Last Post: 10-21-2010, 10:26 AM
  3. Stopping a thread
    By userj2ee in forum New To Java
    Replies: 3
    Last Post: 08-13-2010, 07:57 PM
  4. Replies: 11
    Last Post: 01-26-2009, 12:22 AM
  5. stopping thread...using flags
    By rstepler in forum New To Java
    Replies: 1
    Last Post: 07-31-2008, 09:36 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •