Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

How are thread identified in threadpool  RSS feed

 
Abrahim Daver
Ranch Hand
Posts: 69
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

I would like to know, if I set same name for each thread created in thread pool using Thread.currentThread().setName(). Will it cause any problem?
How are threads recognized in threadpool ? by Name OR id OR ???

Thanking you in advance.
Abra
 
Edward Harned
Ranch Hand
Posts: 291
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try it and find out.

(Hint: you need to set the name in the constructor.)
 
Nitesh Kant
Bartender
Posts: 1638
IntelliJ IDE Java MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Abrahim:
How are threads recognized in threadpool ?


I am not sure what do you intend by saying "recognized".
I assume you are talking about the ThreadPool Implementation in the jdk, so, I would answer in terms of ThreadPoolExecutor.
It maintains a HashSet of workers(A runnable implementation) and there is no reference to the Thread created. Workers pull tasks from the work queue and execute them.
There is no managing entity that picks up a thread and instructs to execute a task. So, I dont think anybody needs to recognize any thread as such.

Every thread in the JVM is assigned a unique identifier, so, assigning same name does no harm to the thread execution/management but it will create problems for people debugging the thread dumps.
[ July 23, 2008: Message edited by: Nitesh Kant ]
 
Abrahim Daver
Ranch Hand
Posts: 69
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you very much for the information
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!