tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Janek Bogucki <jane...@yahoo.co.uk>
Subject RE: How to list all Threads in the JVM? (Includes suggestion.)
Date Wed, 05 Jun 2002 16:00:28 GMT
Hi Yoav,

 --- "Shapira, Yoav" <Yoav.Shapira@mpi.com> wrote: > Howdy,
> Your basic code snippet worked relatively well.  In fact, I liked it
> enough to start using it, with a few modifications and enhancements.
> I'm attaching a more fully developed class to do some more, e.g. get a
> list of all threads, etc.
> 
> You WILL get security (e.g. ThreadIllegalStateException) exceptions if
> you try to modify thread groups outside your own.  For kicks, try the
> destroyRootThreadGroup() method in the attached class. ;)
> 
> Yoav Shapira
> Millennium ChemInformatics
> 

Thanks for posting the class, it was really good. (If anyone is having trouble with Exercise
10.9
in The Java Programming Language Third Edition I reccommend a look at Yoav's class!).

I've integrated it in the web app. This is what I get shortly after starting Tomcat. It's
a good
starting point.

Many Thanks,
Janek

[SystemThreadList:
 ThreadGroup 0= java.lang.ThreadGroup[name=main,maxpri=10], activeCount = 46
 ThreadGroup 1= java.lang.ThreadGroup[name=system,maxpri=10], activeCount = 50
 totalActiveCount = 96
 (End of SystemThreadList)]Thread 0 = Thread[Reference Handler,10,system]
Thread 1 = Thread[Finalizer,8,system]
Thread 2 = Thread[Signal Dispatcher,10,system]
Thread 3 = Thread[CompileThread0,10,system]
Thread 4 = Thread[main,5,main]
Thread 5 = Thread[Thread-0,5,main]
Thread 6 = Thread[Thread-1,5,main]
Thread 7 = Thread[StandardManager[],5,main]
Thread 8 = Thread[Thread-2,5,main]
Thread 9 = Thread[Thread-3,5,main]
Thread 10 = Thread[Thread-4,5,main]
Thread 11 = Thread[Thread-5,5,main]
Thread 12 = Thread[Thread-6,5,main]
Thread 13 = Thread[Thread-7,5,main]
Thread 14 = Thread[Thread-8,5,main]
Thread 15 = Thread[Thread-9,5,main]
Thread 16 = Thread[Thread-10,5,main]
Thread 17 = Thread[Thread-11,5,main]
Thread 18 = Thread[Thread-12,5,main]
Thread 19 = Thread[Thread-13,5,main]
Thread 20 = Thread[Thread-14,5,main]
Thread 21 = Thread[Thread-15,5,main]
Thread 22 = Thread[Thread-16,5,main]
Thread 23 = Thread[Thread-17,5,main]
Thread 24 = Thread[Thread-18,5,main]
Thread 25 = Thread[Thread-19,5,main]
Thread 26 = Thread[Thread-20,5,main]
Thread 27 = Thread[Thread-21,5,main]
Thread 28 = Thread[StandardManager[],5,main]
Thread 29 = Thread[Thread-22,5,main]
Thread 30 = Thread[Thread-23,5,main]
Thread 31 = Thread[Thread-24,5,main]
Thread 32 = Thread[Thread-25,5,main]
Thread 33 = Thread[Thread-26,5,main]
Thread 34 = Thread[Thread-27,5,main]
Thread 35 = Thread[Thread-28,5,main]
Thread 36 = Thread[Thread-30,5,main]
Thread 37 = Thread[Thread-31,5,main]
Thread 38 = Thread[StandardManager[],5,main]
Thread 39 = Thread[Thread-32,5,main]
Thread 40 = Thread[Thread-33,5,main]
Thread 41 = Thread[Thread-34,5,main]
Thread 42 = Thread[Thread-35,5,main]
Thread 43 = Thread[Thread-37,5,main]
Thread 44 = Thread[Thread-38,5,main]
Thread 45 = Thread[Thread-39,5,main]
Thread 46 = Thread[Thread-40,5,main]
Thread 47 = Thread[Thread-41,5,main]
Thread 48 = Thread[Thread-42,5,main]
Thread 49 = Thread[Thread-43,5,main]

------------------------------------

To dump this into a page, use this abbreviated version of SystemThreadList.main.

xxx () {     
            SystemThreadList stl = new SystemThreadList() ;
            Thread[] allThreads = stl.getAllThreads();
            
            if((allThreads == null) || (allThreads.length < 1))
                return "SystemThreadListSAO: allThreads is null or length < 1.";
            
            StringBuffer sb = new StringBuffer(stl.toString() );
            sb.append ( "\n" ) ;
            
            // Individual thread info
            Thread t = null;
            for(int i = 0; i < allThreads.length; i++) {
                t = allThreads[i];
                sb.append("Thread " + i + " = " + t.toString());
                sb.append ( "\n" ) ;
            }
            
            return sb.toString() ;
}


__________________________________________________
Do You Yahoo!?
Everything you'll ever need on one web page
from News and Sport to Email and Music Charts
http://uk.my.yahoo.com

--
To unsubscribe, e-mail:   <mailto:tomcat-user-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:tomcat-user-help@jakarta.apache.org>


Mime
View raw message