File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Threads and Synchronization and the fly likes Number of threads Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Threads and Synchronization
Bookmark "Number of threads" Watch "Number of threads" New topic
Author

Number of threads

A. Goyal
Greenhorn

Joined: Jul 28, 2012
Posts: 2
Hello everyone!!
I am using Windows 7 64-bit Home Premium and every time I run a Java Program which has only one thread(the default Main thread), the Resource Monitor shows that process corresponding to this program has but 13 threads. Can someone shed a light on that ??



regards,
ankit
Anayonkar Shivalkar
Bartender

Joined: Dec 08, 2010
Posts: 1510
    
    5

Hi,

Please check your private message for an administrative matter.

Please note that it is not optional.


Regards,
Anayonkar Shivalkar (SCJP, SCWCD, OCMJD, OCEEJBD)
Anayonkar Shivalkar
Bartender

Joined: Dec 08, 2010
Posts: 1510
    
    5

Hi,

The number of threads created by JVM (i.e. java.exe) depend upon few factors:

1) What all applications are using JVM? e.g. is Java plugin for web browser currently operational?
2) Number of threads created by your code
3) Number of threads created by other code - please note that all Java application almost use a common JVM on a system
4) Number of threads created by JVM itself - e.g. GC daemon thread etc.

I hope this helps.
A. Goyal
Greenhorn

Joined: Jul 28, 2012
Posts: 2
Hi,
Anayonkar Shivalkar wrote:

2) Number of threads created by your code
3) Number of threads created by other code - please note that all Java application almost use a common JVM on a system


I am not creating any explicit thread and when I am executing two java programs using two different DOS terminals at the same time, I see two different "java.exe" in the resource monitor both having same number of threads(13 in this case). So how can we say that "all Java application almost use a common JVM on a system" ?? And does that mean we cannot have more than one instance of JVM in RAM?? And if dats possible please tell me how can we do that(creating more than one instance of JVM)?


4) Number of threads created by JVM itself - e.g. GC daemon thread etc.


How many threads does the garbage collector require?? Does it depend on the native OS on which JVM is running or the is JVM specific??

Thanks,
regards,
ankit goyal


Jayesh A Lalwani
Bartender

Joined: Jan 17, 2008
Posts: 2434
    
  28

There are 3 ways to find out
a) Take a thread dump
On the console where you started java press ctrl + Break. It will tell you the name ofeach thread and what each thread is doing
b) Use jstack
You can use jstack to get the thread dump
b) Use Jconsole
You can fire up JConsole and monitor your java process. It tels you what each thread is doing
 
Consider Paul's rocket mass heater.
 
subject: Number of threads