Mailing Lists: Apple Mailing Lists

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

Re: Getting thread info from sub-threads....problem solved



bsd5tu1 wrote:

>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?

Look at the ThreadGroup class, then look at the Thread constructors.

All the Thread constructors that lack a ThreadGroup param use the current
Thread's ThreadGroup.  So, if the "method that loads the class" does the
following, you can get what you want (if I understand your question
correctly).

  1. Create a ThreadGroup; call it newGroup.
  2. Create a Thread with newGroup as its ThreadGroup.
  3. Create a Runnable that either loads the class and launches the method,
or just launches the method.
  4. Start the Thread on the Runnable.

After #4, all the Threads created by the running of the method will have a
parent ThreadGroup of newGroup.  The only exceptions to this rule would be
if some code executed by the method created a different ThreadGroup and
spawned Threads on that.

Think of the ThreadGroup class as the "parent" or "shepherd" of some
collection of Threads.  As already noted, the parent/child connection
directly between Threads is tenuous.  However, the connection between a
Thread and its ThreadGroup is strong.  And ThreadGroups can contain other
ThreadGroups, in a tree.

You can also operate on the whole group of Threads via a ThreadGroup.  For
example, to find how many Threads are still running.  This can be useful in
some cases.  See ThreadGroup's API docs for more information on what it can
do.

  -- GG


 _______________________________________________
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.