• Post Reply Bookmark Topic Watch Topic
  • New Topic

thread name

 
Robert Kennedy
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I create a thread (as below) in one class and try to get its name via:

Thread.currentThread().getName()

in another class (when a thread accesses a method) but instead I get Thread-14 (for example). Is there a way to get thread name without a direct reference to the object which created the thread?

runnable....
void start () {
Thread thread = new Thread(this, "ActionManager");
thread.start();
}
 
Steve Luke
Bartender
Posts: 4181
22
IntelliJ IDE Java Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Robert Kennedy:
I create a thread (as below) in one class and try to get its name via:

Thread.currentThread().getName()

in another class (when a thread accesses a method) but instead I get Thread-14 (for example). Is there a way to get thread name without a direct reference to the object which created the thread?

runnable....
void start () {
Thread thread = new Thread(this, "ActionManager");
thread.start();
}

What your code is telling you is the Thread that is accessing the method that calls Thread.currentThread().getName() is not the thread you create like Thread thread = new Thread(this, "ActionManager").

Can you reproduce the problem in a small example that we can copy, compile, and run (but doesn't do anything more than show your problem)?
 
Robert Kennedy
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes you are right, and a few little tests prove it. Thank you
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!