File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
A friendly place for programming greenhorns!
Big Moose Saloon
Search
|
Java FAQ
|
Recent Topics
Register / Login
Win a copy of
The Mikado Method
this week in the
Agile and other Processes
forum!
JavaRanch
»
Java Forums
»
Java
»
Threads and Synchronization
Author
java threads
jignesh soni
Ranch Hand
Joined: Dec 10, 2007
Posts: 147
posted
Jul 06, 2008 17:47:00
0
which are the two threads always running in
java
?
Norm Radder
Ranch Hand
Joined: Aug 10, 2005
Posts: 681
posted
Jul 06, 2008 18:59:00
0
I give up.
Is it the white one and the black one?
Ulf Dittmer
Marshal
Joined: Mar 22, 2005
Posts: 35252
7
posted
Jul 06, 2008 22:07:00
0
Here's some code that will come in handy if you want to investigate what threads are active at any given time.
private void getThreadInfo (PrintWriter output) { // Get the top level thread group ThreadGroup adam = getAdam(Thread.currentThread().getThreadGroup()); // Get the count of active threads in the system int num = adam.activeCount(); // Get all of the active threads in the system Thread list[] = new Thread[num]; int x = adam.enumerate(list); // if (x != num) //return; // Display all of the active threads in the system output.println("<p><b>Threads</b><table border=1><tr>"); output.println("<th>Group</th><th>Name</th><th>Priority</th><th>Daemon</th><th>Alive</th></tr>"); for (int i = 0; i < x; i++) { if (list[i] == null) continue; String threadName = list[i].getName(); String groupName = list[i].getThreadGroup().getName(); output.println("<tr><td>" + groupName + "</td><td>" + threadName + "</td><td>" + list[i].getPriority() + "</td><td>" + (list[i].isDaemon() ? "Yes" : "No") + "</td><td>" + (list[i].isAlive() ? "Yes" : "No") + "</td></tr>"); } output.println("</table>"); } // Recursively calls itself to find the top level thread group private ThreadGroup getAdam (ThreadGroup tg) { ThreadGroup parent = tg.getParent(); if (parent == null) return tg; return getAdam(parent); }
Android apps
–
ImageJ plugins
–
Java web charts
Nitesh Kant
Bartender
Joined: Feb 25, 2007
Posts: 1638
I like...
posted
Jul 06, 2008 23:02:00
0
Alternatively, take a thread dump(CTRL-Break(Win systems) or CTRL-/(Unix)) and find it for yourself how many threads are alive and they are in what states!!
apigee
, a better way to API!
I agree. Here's the link:
http://zeroturnaround.com/jrebel
- it saves me about five hours per week
subject: java threads
Similar Threads
New to using a profiler .Please help
Synchronized methods
Two threads of same class instance to wait separately
threads
Threads
All times are in JavaRanch time: GMT-6 in summer, GMT-7 in winter