This week's giveaway is in the EJB and other Java EE Technologies forum.
We're giving away four copies of EJB 3 in Action and have Debu Panda, Reza Rahman, Ryan Cuprak, and Michael Remijan on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Thread::setName(string) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Thread::setName(string)" Watch "Thread::setName(string)" New topic
Author

Thread::setName(string)

Aby Krishna
Greenhorn

Joined: Jul 10, 2010
Posts: 7
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

Joined: Nov 24, 2005
Posts: 14687
    
  16

If the current thread is allowed to access the thread that you are trying to rename, yes.


[My Blog]
All roads lead to JavaRanch
Abimaran Kugathasan
Ranch Hand

Joined: Nov 04, 2009
Posts: 2066

Don't you try it? Have a look on this API


|BSc in Electronic Eng| |SCJP 6.0 91%| |SCWCD 5 92%|
subodh k kumar
Greenhorn

Joined: Aug 19, 2009
Posts: 16

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");

SCJP1.4 , SCWCD 5
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Thread::setName(string)
 
Similar Threads
Threads
can we use setPriority inside a synchronized block
Thread names??
Concurency logic
How can I get a run() method to return a string variable, when run() method is required to be void ?