• Post Reply Bookmark Topic Watch Topic
  • New Topic

Applet Threads  RSS feed

 
Drew Lane
Ranch Hand
Posts: 296
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2205
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Drew Lane
Ranch Hand
Posts: 296
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2205
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!