Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Number of threads

 
A. Goyal
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1557
5
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Please check your private message for an administrative matter.

Please note that it is not optional.
 
Anayonkar Shivalkar
Bartender
Posts: 1557
5
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Posts: 2756
32
Eclipse IDE Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic