Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Getting thread info from sub-threads.



Hello:

I have several questions:

We have an application that is using reflection to load a method and then execute it. From the parent thread, we use the following code snippet to get a list of the threads BEFORE we call load and execute the class and the target method:

           //Initially assign topLevel to null and get the current group
           ThreadGroup topLevel = null;
           ThreadGroup tg = Thread.currentThread ().getThreadGroup();

//Parse up the thread "tree" to get the toplevel thread, which will
//exist when no parent is to be found and topLevel = null;
while (tg != null)
{
topLevel = tg;
tg = tg.getParent ();
}


//Enumerate on all the threads, create strings, and make a message to
//send to the UI.
if (topLevel != null)
{
Thread [] threads = new Thread [topLevel.activeCount ()];
msg = new String[topLevel.activeCount () + 1];


//Create the initial message
msg[0] = "\n\n Currently running threads: \n";
int nthreads = topLevel.enumerate (threads);
for (int i = 0; i < nthreads; i++)
msg[i+1] = new String(" Name: " + threads [i].getName() + ", " +
"Thread Group: " + threads[i].getThreadGroup().getName() + ", " +
"Priority: " + threads[i].getPriority() + ", " +
"Daemon: " + threads [i].isDaemon () + "\n");



Name: Reference Handler, Thread Group: system, Priority: 10, Daemon: true
Name: Finalizer, Thread Group: system, Priority: 8, Daemon: true
Name: Signal Dispatcher, Thread Group: system, Priority: 9, Daemon: true
Name: Java2D Disposer, Thread Group: system, Priority: 10, Daemon: true
Name: AWT-AppKit, Thread Group: main, Priority: 5, Daemon: true
Name: AWT-Shutdown, Thread Group: main, Priority: 5, Daemon: false
Name: AWT-EventQueue-0, Thread Group: main, Priority: 6, Daemon: false
Name: Thread-1, Thread Group: main, Priority: 5, Daemon: false
Name: Thread-0, Thread Group: main, Priority: 5, Daemon: false
Name: DestroyJavaVM, Thread Group: main, Priority: 5, Daemon: false
Name: TimerQueue, Thread Group: main, Priority: 5, Daemon: true


If the method we launch creates another thread within it, I would like to be able to list that thread and any other threads it may launch as well. I assumed that if we used the same code from withing the thread launched in the loaded class/launched method it would produce a list of more threads....namely all the threads etc it has generated itself PLUS all of those above. Instead what we get is the exact same list.

Does anyone know why this is ? Would it possibly be caused by the fact the method is static? Also, does anyone know if there is a way that the method that loads the class and launches the method can "parse into" the newly launched method and obtain a list of all it's threads without putting any of this thread listing code into the method?

Thanks in advance.

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Java-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/java-dev/email@hidden

This email sent to email@hidden


Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.