Results 1 to 4 of 4
  1. #1
    TyCox94's Avatar
    TyCox94 is offline Member
    Join Date
    Sep 2011
    Posts
    38
    Rep Power
    0

    Default Recreating Thread Object After Termination

    Recreating Thread After Termination

    I have created a thread. It can be started and stopped but can't start it again because the thread has been terminated. How can i create the object again so the state will be "NEW".


    Declaring object:
    Java Code:
    public MainBot mainBotObject = new MainBot();
    Start Thread:
    Java Code:
            if(mainBotObject.isInterrupted()) {
                //need to renew the object here
            }
            System.out.println(mainBotObject.getState());//First Run: New,Second Run: Terminated <<state of thread
            mainBotObject.start();
            System.out.println(mainBotObject.getState());//First Run: Runnable <<state of thread
    Stop Thread:
    Java Code:
            System.out.println(mainBotObject.getState());//First Run: Runnable <<state of thread
            mainBotObject.interrupt();
            System.out.println(mainBotObject.getState());//First Run: Runnable <<state of thread
    Last edited by TyCox94; 02-11-2012 at 05:04 AM.

  2. #2
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,581
    Rep Power
    25

    Default Re: Recreating Thread Object After Termination

    How can i create the object again
    To create a Thread object, use the new statement.

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

    Default Re: Recreating Thread Object After Termination

    How can i do this? I need to recreate the object with another statement:
    Java Code:
    public MainBot mainBotObject = new MainBot();
    If so how should I go by calling this statement? I tried putting it into a public void then calling when the object is terminated, but for some reason public objects can't be declared in a void. How can i go about doing this?

    If not what is the best approach?

    Thanks for a reply.

  4. #4
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,423
    Rep Power
    20

    Default Re: Recreating Thread Object After Termination

    how should I go by calling this statement?
    The same way you did it the first time round.

    I tried putting it into a public void then calling when the object is terminated, but for some reason public objects can't be declared in a void
    Trail: Learning the Java Language (The Java™ Tutorials)

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

Similar Threads

  1. Recreating toUpperCase method
    By theoneroo in forum New To Java
    Replies: 1
    Last Post: 01-28-2011, 05:59 AM
  2. How to trap java process termination events?
    By thalupularavi in forum SWT / JFace
    Replies: 0
    Last Post: 03-10-2010, 03:02 PM
  3. Offering Quality Routes & Call Termination
    By taiger786 in forum Reviews / Advertising
    Replies: 0
    Last Post: 02-17-2010, 09:00 AM
  4. Abnormal termination: JDWP Unable to get JNI 1.2 environment
    By KingOfLions in forum Advanced Java
    Replies: 1
    Last Post: 09-09-2009, 05:11 PM
  5. Replies: 0
    Last Post: 01-28-2008, 07:02 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
  •