Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 5 of 5

Thread: How to Stop a Thread Safley

  1. #1
    Junior Member viper_07's Avatar
    Join Date
    Jul 2011
    Location
    manchester
    Posts
    23
    My Mood
    Cheerful
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default How to Stop a Thread Safley

    hi guys i was wonderig what the best way to stop (kill) a thread any ideas ?


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,162
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: How to Stop a Thread Safley

    In the thread, test if a flag is set asking the thread to exit and exit/return.

  3. The Following User Says Thank You to Norm For This Useful Post:

    viper_07 (July 14th, 2011)

  4. #3
    Junior Member viper_07's Avatar
    Join Date
    Jul 2011
    Location
    manchester
    Posts
    23
    My Mood
    Cheerful
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Re: How to Stop a Thread Safley

    thanks mate thats what i used in the end

  5. #4
    Junior Member
    Join Date
    May 2011
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: How to Stop a Thread Safley

    or you could do something like this:
    public void stop()
    {
        thread = null;
        stop = true;
    }
    as in, set your thread to null and your stop flag to true... just to double make sure...

  6. #5
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,162
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: How to Stop a Thread Safley

    What does setting the variable: thread to null do?

Similar Threads

  1. [SOLVED] Make it stop looping! please. :)
    By Hallowed in forum What's Wrong With My Code?
    Replies: 11
    Last Post: May 7th, 2011, 11:20 AM
  2. Button Won't Stop Animation.
    By SyntheticD in forum What's Wrong With My Code?
    Replies: 5
    Last Post: March 24th, 2011, 02:27 PM
  3. Cant get my code to stop jumping
    By Mob31 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: March 2nd, 2011, 07:03 AM
  4. Code Stop working after converting to jar?
    By Ron6566 in forum What's Wrong With My Code?
    Replies: 2
    Last Post: August 16th, 2010, 12:17 PM
  5. Replies: 4
    Last Post: April 27th, 2010, 01:18 AM