Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Thread doubt  RSS feed

 
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: 23275
125
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
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!