Page 2 of 2 FirstFirst 12
Results 21 to 32 of 32
Like Tree1Likes

Thread: Stop Thread

  1. #21
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,305
    Rep Power
    25

    Default Re: Stop Thread

    Thrown to indicate that a thread is not in an appropriate state for the requested operation. See, for example, the suspend and resume methods in class Thread.
    What class or method is that from?

    Have you read the API doc for the Thread class's start() method? Look at the bottom of the section for start to see what exceptions it throws and why.

  2. #22
    TyCox94's Avatar
    TyCox94 is offline Member
    Join Date
    Sep 2011
    Posts
    38
    Rep Power
    0

    Default Re: Stop Thread

    Thread.start();

    Ok it says it throws IllegalThreadStateException if the thread was already started.

    IllegalThreadStateException: Thrown to indicate that a thread is not in an appropriate state for the requested operation. See, for example, the suspend and resume methods in class Thread.

  3. #23
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,305
    Rep Power
    25

    Default Re: Stop Thread

    throws IllegalThreadStateException if the thread was already started.
    Do you call start() more than once on that thread? The second call should throw the above exception.

    What are you trying to do with threads?

  4. #24
    TyCox94's Avatar
    TyCox94 is offline Member
    Join Date
    Sep 2011
    Posts
    38
    Rep Power
    0

    Default Re: Stop Thread

    This is because I haven't "destroyed" the first thread. How do I complete stop this thread?

    I'm trying to be able to start and stop the thread.

  5. #25
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,305
    Rep Power
    25

    Default Re: Stop Thread

    To stop a thread, let the execution exit from the run() method or do a return.
    To pause and restart a thread's execution you can use the Object class's wait() and notify() methods.

  6. #26
    TyCox94's Avatar
    TyCox94 is offline Member
    Join Date
    Sep 2011
    Posts
    38
    Rep Power
    0

    Default Re: Stop Thread

    can you start(); a thread that is TERMINATED?

  7. #27
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,305
    Rep Power
    25

    Default Re: Stop Thread

    No, you create a new one.
    Again read the API doc for the start() method.

  8. #28
    TyCox94's Avatar
    TyCox94 is offline Member
    Join Date
    Sep 2011
    Posts
    38
    Rep Power
    0

    Default Re: Stop Thread

    Is it possible to return my object "public mainBot mainBot = new mainBot();" to state NEW again after being TERMINATED?
    Last edited by TyCox94; 09-30-2011 at 04:31 AM.

  9. #29
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,305
    Rep Power
    25

    Default Re: Stop Thread

    Sorry, I don't understand what you are trying to do.
    If you create a new instance of the MainBot class in a method, you can return that instance to the caller of the method.

    What do you mean by "to NEW"?

    NOTE: Its poor coding style to have a class name and a variable name be the same. Class names should start with capital letters.
    TyCox94 likes this.

  10. #30
    TyCox94's Avatar
    TyCox94 is offline Member
    Join Date
    Sep 2011
    Posts
    38
    Rep Power
    0

    Default Re: Stop Thread

    I will keep this in mind for now on.

    I mean back to the NEW state.

  11. #31
    TyCox94's Avatar
    TyCox94 is offline Member
    Join Date
    Sep 2011
    Posts
    38
    Rep Power
    0

    Default Re: Stop Thread

    How can I turn the state of my object back to NEW after i have TERMINATED it?

  12. #32
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,305
    Rep Power
    25

    Default Re: Stop Thread

    How can I turn the state of my object back to NEW after i have TERMINATED it?
    What object?
    Where is the "state of the object"?
    What does "NEW" mean here?
    Why is the word TERMINATED in captial letters?

    What are you trying to do?
    When a thread exits, its death, done, finished, caput.
    If you need another one, create it with the new statement.

Page 2 of 2 FirstFirst 12

Similar Threads

  1. Thread help - how to stop?
    By scheffetz in forum New To Java
    Replies: 3
    Last Post: 04-10-2011, 01:14 PM
  2. How to stop Thread
    By ersachinjain in forum Threads and Synchronization
    Replies: 2
    Last Post: 11-30-2009, 07:11 PM
  3. Thread won't stop
    By bubbless in forum Threads and Synchronization
    Replies: 15
    Last Post: 10-20-2009, 10:58 PM
  4. Help to stop a thread
    By raghu_lzybns in forum New To Java
    Replies: 4
    Last Post: 07-09-2009, 04:39 PM
  5. how to stop a thread
    By willemjav in forum Advanced Java
    Replies: 19
    Last Post: 09-10-2008, 07:11 AM

Posting Permissions

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