• Post Reply Bookmark Topic Watch Topic
  • New Topic

Counting Threads

 
J Mangual
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How does one count the number of threads in a program? I want to modify the method below so that when a new socket connects (and a new thread is opened) the count increases by 1 and when the thread ends it decreases by 1. Alternatively, I would like to store all the active threads in an array. Is there a standard way of doing this?

 
Campbell Ritchie
Marshal
Posts: 52549
119
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sounds a more complicated question than we usually get here on beginners'. Moving.
 
Steve Luke
Bartender
Posts: 4181
22
IntelliJ IDE Java Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can use ThreadGroups to do this. Your best bet would be to make a new ThreadGroup that you would add all the Threads of interest in:


Then you can get the count from the group like:


 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!