This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Java in General and the fly likes When you run a program how many threads will  create ?. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "When you run a program how many threads will  create ?." Watch "When you run a program how many threads will  create ?." New topic
Author

When you run a program how many threads will create ?.

Praveen Kumar
Ranch Hand

Joined: Nov 06, 2006
Posts: 133
Hi

Suppose If run a program , I am sure that JVM will create main thread to execute the program. But I would like that to know that internally how many threads JVM will create ?. I know that GC is daemon thread. So when it will create ?. Like GC , JVM will create any more threads ?

Please let me know how many threads( including daemon) JVM will create ? and how to find out the running threads in JVM.



Thanks
Praveen
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11161
    
  16

wouldn't the number of threads created depend on the specific program being run?


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Lester Burnham
Rancher

Joined: Oct 14, 2008
Posts: 1337
See this previous discussion which includes a useful code example.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19655
    
  18

Praveen Kumar wrote:and how to find out the running threads in JVM.

Use a profiler.

I'm not sure, but the following also seems to return a Set<Thread> snapshot of the current threads: And ThreadMXBean also seems to be able to return them, although you'll need a bit more code.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Soumyajit Hazra
Ranch Hand

Joined: Jun 26, 2007
Posts: 136
Yes Rob. If we print it it gives
[Thread[main,5,main], Thread[Attach Listener,5,system], Thread[Reference Handler,10,system], Thread[Signal Dispatcher,9,system], Thread[Finalizer,8,system]]


Java Programmer | SCJP 1.5 | SCWCD 1.4
Praveen Kumar
Ranch Hand

Joined: Nov 06, 2006
Posts: 133
Thanks a lot for all for wonderful answers :-) . I got much info..
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: When you run a program how many threads will create ?.
 
Similar Threads
Thread.currentThread.getID()
Doubts in threads !
what are the Threads runs when a java program running?
Daemon threads
Daemon Thread