Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Thread set as Null

 
Steve Jiang
Ranch Hand
Posts: 127
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For the following sample code



After t= null; I guess the thread will still run? but not sure if there is other efftect for set thread as null. Any comments for that?


Thanks
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I wouldn't set it to null unless setting it to null had some special purpose in the code.
Otherwise it serves no real purpose and worse could be misleading.
 
Steve Jiang
Ranch Hand
Posts: 127
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks, and yes, it is not a normal and good way to do it. But I also hope to understand what is the result ( or no affect ) with this way for thread.

Thanks,
 
Sriram Naga
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The thread gets executed anyway. But you can't refer to that thread object once you assign it to null. You will get a Null Pointer exception if you do so.
 
Abimaran Kugathasan
Ranch Hand
Posts: 2066
Clojure IntelliJ IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think, there should be an internal reference to the threads. So, nothing will happen, thread terminates normally.

Try to invoke this code in your thread's run method.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic