• Post Reply Bookmark Topic Watch Topic
  • New Topic

Thread doubt

 
aresh babu
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thread t = new Thread(); t.start(); t = null; now what will happen to the created thread?
 
Henry Wong
author
Sheriff
Posts: 22532
109
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
aresh babu wrote:Thread t = new Thread(); t.start(); t = null; now what will happen to the created thread?


A thread's stack is considered as a root for the GC to check for reachibility. Hence, setting t to null doesn't make the thread object unreachable. The thread object can still be reach via the currentThread() method from the newly started thread.

In other words, nothing will happen to the newly created thread.

Henry
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!