• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Getting number of active threads and open sockets

 
Victor Ho
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Are their any APIs from the JDK that can retrieve the number of active threads and open sockets used by the VM. (not using any native code).

Thanks
Victor
 
Henry Wong
author
Marshal
Pie
Posts: 21490
84
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Victor Ho:
Hi,

Are their any APIs from the JDK that can retrieve the number of active threads and open sockets used by the VM. (not using any native code).

Thanks
Victor


The Thread class has an enumerate() method that returns the number of threads in the current thread group and all sub-groups. Just call the method from a thread in the main thread group, (or any thread if your application doesn't create any threadgroups) and you'll get all the threads for you application.

You'll be missing some threads above your application, but for security reasons, you should not be accessing those threads anyway.

Henry
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic