How to list all Threads in the JVM? (Includes suggestion.)

2002-06-05 Thread Janek Bogucki

Hi,

We are trying to monitor the set of Threads in the JVM running Tomcat in order to fix 
a resource
exhaustion problem we have. (Tomcat and/or our code is increasing the number of 
threads until the
hard nproc limit in /etc/security/limits.conf for the user is reached. Red Hat Linux 
7.2)

How can I code this? This is probably a basic Java question but how do I reference to 
the top
level ThreadGroup? With this code

ThreadGroup tg = Thread.currentThread().getThreadGroup() ;
while ( tg.getParent() != null)
tg = tg.getParent() ;

/* walk hierachy from tg */

would the code encounter problems with security manager restrictions when methods are 
invoked on
the root object?

In addition to the actual code to walk the Thread tree does anyone have a suggestion 
as to which
classloader I should put the code in? Does it matter?

Many Thanks for any suggestions,
Janek

__
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:[EMAIL PROTECTED]
For additional commands, e-mail: mailto:[EMAIL PROTECTED]




Re: How to list all Threads in the JVM? (Includes suggestion.)

2002-06-05 Thread peter lin


use an application like optimizeIt or JProbe to profile the thread
usage. Warning though, don't try running it on a system with less than
128mb of ram.

peter


Janek Bogucki wrote:
 
 Hi,
 
 We are trying to monitor the set of Threads in the JVM running Tomcat in order to 
fix a resource
 exhaustion problem we have. (Tomcat and/or our code is increasing the number of 
threads until the
 hard nproc limit in /etc/security/limits.conf for the user is reached. Red Hat Linux 
7.2)
 
 How can I code this? This is probably a basic Java question but how do I reference 
to the top
 level ThreadGroup? With this code
 
 ThreadGroup tg = Thread.currentThread().getThreadGroup() ;
 while ( tg.getParent() != null)
 tg = tg.getParent() ;
 
 /* walk hierachy from tg */
 
 would the code encounter problems with security manager restrictions when methods 
are invoked on
 the root object?
 
 In addition to the actual code to walk the Thread tree does anyone have a suggestion 
as to which
 classloader I should put the code in? Does it matter?
 
 Many Thanks for any suggestions,
 Janek
 
 __
 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:[EMAIL PROTECTED]
 For additional commands, e-mail: mailto:[EMAIL PROTECTED]

--
To unsubscribe, e-mail:   mailto:[EMAIL PROTECTED]
For additional commands, e-mail: mailto:[EMAIL PROTECTED]




Re: How to list all Threads in the JVM? (Includes suggestion.)

2002-06-05 Thread Janek Bogucki

 --- peter lin [EMAIL PROTECTED] wrote:  
 use an application like optimizeIt or JProbe to profile the thread
 usage. Warning though, don't try running it on a system with less than
 128mb of ram.
 
 peter

Thanks for the links:

http://www.sitraka.com/software/jprobe/
http://www.borland.com/optimizeit/

It's not really what I need right now. If I had a simple class that formed the basis 
of a Thread
which periodically dumped a list of all Threads in the JVM I'd be satified (for 
now...JProbe
Threadalyzer looks very useful!).

Thanks,
Janek

__
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:[EMAIL PROTECTED]
For additional commands, e-mail: mailto:[EMAIL PROTECTED]




RE: How to list all Threads in the JVM? (Includes suggestion.)

2002-06-05 Thread Shapira, Yoav

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


-Original Message-
From: Janek Bogucki [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, June 05, 2002 9:05 AM
To: [EMAIL PROTECTED]
Subject: How to list all Threads in the JVM? (Includes suggestion.)

Hi,

We are trying to monitor the set of Threads in the JVM running Tomcat
in
order to fix a resource
exhaustion problem we have. (Tomcat and/or our code is increasing the
number of threads until the
hard nproc limit in /etc/security/limits.conf for the user is reached.
Red
Hat Linux 7.2)

How can I code this? This is probably a basic Java question but how do
I
reference to the top
level ThreadGroup? With this code

ThreadGroup tg = Thread.currentThread().getThreadGroup() ;
while ( tg.getParent() != null)
tg = tg.getParent() ;

/* walk hierachy from tg */

would the code encounter problems with security manager restrictions
when
methods are invoked on
the root object?

In addition to the actual code to walk the Thread tree does anyone have
a
suggestion as to which
classloader I should put the code in? Does it matter?

Many Thanks for any suggestions,
Janek

__
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-
[EMAIL PROTECTED]
For additional commands, e-mail: mailto:tomcat-user-
[EMAIL PROTECTED]




SystemThreadList.java
Description: SystemThreadList.java

--
To unsubscribe, e-mail:   mailto:[EMAIL PROTECTED]
For additional commands, e-mail: mailto:[EMAIL PROTECTED]


Re: How to list all Threads in the JVM? (Includes suggestion.)

2002-06-05 Thread anette mysel

PLEASE REMOVE ME FROM YOUR MAILING LIST. I DO NOT KNOW WHO YOU ARE. THANK
YOU...
- Original Message -
From: Shapira, Yoav [EMAIL PROTECTED]
To: Tomcat Users List [EMAIL PROTECTED]
Sent: Wednesday, June 05, 2002 9:29 AM
Subject: RE: How to list all Threads in the JVM? (Includes suggestion.)


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


-Original Message-
From: Janek Bogucki [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, June 05, 2002 9:05 AM
To: [EMAIL PROTECTED]
Subject: How to list all Threads in the JVM? (Includes suggestion.)

Hi,

We are trying to monitor the set of Threads in the JVM running Tomcat
in
order to fix a resource
exhaustion problem we have. (Tomcat and/or our code is increasing the
number of threads until the
hard nproc limit in /etc/security/limits.conf for the user is reached.
Red
Hat Linux 7.2)

How can I code this? This is probably a basic Java question but how do
I
reference to the top
level ThreadGroup? With this code

ThreadGroup tg = Thread.currentThread().getThreadGroup() ;
while ( tg.getParent() != null)
tg = tg.getParent() ;

/* walk hierachy from tg */

would the code encounter problems with security manager restrictions
when
methods are invoked on
the root object?

In addition to the actual code to walk the Thread tree does anyone have
a
suggestion as to which
classloader I should put the code in? Does it matter?

Many Thanks for any suggestions,
Janek

__
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-
[EMAIL PROTECTED]
For additional commands, e-mail: mailto:tomcat-user-
[EMAIL PROTECTED]








 --
 To unsubscribe, e-mail:
mailto:[EMAIL PROTECTED]
 For additional commands, e-mail:
mailto:[EMAIL PROTECTED]


--
To unsubscribe, e-mail:   mailto:[EMAIL PROTECTED]
For additional commands, e-mail: mailto:[EMAIL PROTECTED]




Re: How to list all Threads in the JVM? (Includes suggestion.)

2002-06-05 Thread anette mysel

PLEASE REMOVE ME FROM YOUR MAILING LIST. I DO NOT KNOW WHO YOU ARE. THANK
YOU...
- Original Message -
From: Janek Bogucki [EMAIL PROTECTED]
To: Tomcat Users List [EMAIL PROTECTED]
Sent: Wednesday, June 05, 2002 8:21 AM
Subject: Re: How to list all Threads in the JVM? (Includes suggestion.)


 --- peter lin [EMAIL PROTECTED] wrote: 
  use an application like optimizeIt or JProbe to profile the thread
  usage. Warning though, don't try running it on a system with less than
  128mb of ram.
 
  peter

 Thanks for the links:

 http://www.sitraka.com/software/jprobe/
 http://www.borland.com/optimizeit/

 It's not really what I need right now. If I had a simple class that formed
the basis of a Thread
 which periodically dumped a list of all Threads in the JVM I'd be satified
(for now...JProbe
 Threadalyzer looks very useful!).

 Thanks,
 Janek

 __
 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:[EMAIL PROTECTED]
 For additional commands, e-mail:
mailto:[EMAIL PROTECTED]



--
To unsubscribe, e-mail:   mailto:[EMAIL PROTECTED]
For additional commands, e-mail: mailto:[EMAIL PROTECTED]




RE: How to list all Threads in the JVM? (Includes suggestion.)

2002-06-05 Thread Janek Bogucki

Hi Yoav,

 --- Shapira, Yoav [EMAIL PROTECTED] 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:[EMAIL PROTECTED]
For additional commands, e-mail: mailto:[EMAIL PROTECTED]