• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to dectect the existence applet instance from the same class?

 
SoonAnn Lim
Ranch Hand
Posts: 155
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I have an applet that runs in a thread. Somehow, when i refresh my browser, another instance of applet is initialized before the old one is killed and destroyed. I am thinking to put a simple checking mechanism in applet init method which will look for the applet instance from the same class. If the old instance still exists, wait until the old one is killed before the new instance is initialized. Can i do that?
Thanks,
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You possibly could, but you might end up waiting a long time as you have no guarantees about when garbage collection will occur. One thing that might help is to set a boolean value to tell the old applet thread to end under certain conditions - such as when a new applet thread is created.
You might also want to track whether another instance was created using a static boolean or int variable. If the boolean is true or the int is greater than zerio, then try to stop any other of these threads by setting their stop switch (the aforementioned boolean value).
You might also need to create a static data structure that stores references to already created applet instances.
Don't forget to synchronize everything properly.
Good Luck.
 
SoonAnn Lim
Ranch Hand
Posts: 155
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Thank you very much for the reply. I have solved this problem. The method i used is very close to your suggestion. So i think i am doing the right thing. I create a static counter in the applet which is incremented in the init() and decremented in stop(). It works very fine. However, i need to synchronize the applet as you mentioned. I forget that part at all.
Thank you very much..
Regards,
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic