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

Thread::setName(string)

 
Aby Krishna
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
A quick question, what will happen if i invoke setName(String) API on a thread instance after it has been started via "start()". Will the name be at on the thread and printing it would print the new name? or the name can not be set after the thread has been started?
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If the current thread is allowed to access the thread that you are trying to rename, yes.
 
Abimaran Kugathasan
Ranch Hand
Posts: 2066
Clojure IntelliJ IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Don't you try it? Have a look on this API
 
subodh k kumar
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Yes,Inside your run() method you can access the Current thread and reset the name of it.This will print the new Thread Name.
Thread currentThread = Thread.currentThread();
currentThread .setName("newName");
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic