Results 1 to 3 of 3
  1. #1
    rajinder5 is offline Member
    Join Date
    Oct 2010
    Posts
    17
    Rep Power
    0

    Default thread ref assigned to null

    Hi!

    Thread t = new Thread(); t.start(); t = null;

    now what will happen to the created thread?... i mean will thread stops running after "t" gets garbage collected????

    Thanks...

  2. #2
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,874
    Rep Power
    8

    Default

    Is that what you would expect to happen? Why?

    What happened when you created a small example (an SSCCE) that tested this out?

  3. #3
    toadaly is offline Senior Member
    Join Date
    Jan 2009
    Posts
    671
    Rep Power
    6

    Default

    When you create a thread, a reference to it is maintained by the appropriate ThreadGroup (either the one used to construct the Thread, or the parent ThreadGroup if null was used) until the run method returns and the thread exits. So it will not be garbage collected while active.

Similar Threads

  1. Replies: 6
    Last Post: 10-18-2010, 10:40 AM
  2. Replies: 2
    Last Post: 03-19-2010, 05:30 PM
  3. Replies: 0
    Last Post: 01-28-2008, 07:02 AM
  4. FInal field cannot be assigned
    By ravian in forum New To Java
    Replies: 3
    Last Post: 12-13-2007, 02:26 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
  •