| Author |
Applet Threads
|
Drew Lane
Ranch Hand
Joined: May 13, 2001
Posts: 296
|
|
How would I get a hold of the main thread of an applet from another applet? For example, there are two applets and the first applet wants to control the main thread of the second applet. How would you reference it? Lets assume there are no security restrictions! Thanks! Drew
|
 |
Rob Ross
Bartender
Joined: Jan 07, 2002
Posts: 2205
|
|
First, in the start() method of each applet, set the thread name to something unique you can recognize. Usually, the name is already the name of the class that's running your main() method so that might be good enough. Then, to find the other applet's main thread, call Then you loop over this array and look for the name of the thread you want, and that's the index of the Thread you use. You will have dependancies on the loading order of the applets, so you should make sure when you make the call to enumerate() that all the applets have been loaded. Good luck! Rob
|
Rob
SCJP 1.4
|
 |
Drew Lane
Ranch Hand
Joined: May 13, 2001
Posts: 296
|
|
Thanks for the reply! However, what if you don't have the source for the second applet and you can't set the Thread name? I believe getName() will return something like "Thread-2". Is there any guarantee that the second applet would always have the same thread name (i.e. "Thread-2")? Again, assume no security problems. Thanks! Drew
|
 |
Rob Ross
Bartender
Joined: Jan 07, 2002
Posts: 2205
|
|
No there's no guarantees. But in my tests, the names of the main applet threads have always been the fully qualified class names of the class with the start() method. when you're doing a hack, sometimes you have to live with "the best you can do". Rob
|
 |
 |
|
|
subject: Applet Threads
|
|
|