Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Threads - reconnecting to threads.

Posted on 1998-05-23
3
Medium Priority
?
286 Views
Last Modified: 2010-04-16
Threads - reconnecting to threads.
Internet Explorer 4.01 - Active desktop Java Applet.

I am currently writing a little java applet which is designed to run on the Internet Explorer 4.01 Active desktop. I have a user interface thread which calls the run method of the applet, and a couple of other
threads which actually do the work. I am not sure why, but now and then the active desktop refreshes,
often when you connect or disconnect from the internet. You can also cause the active desktop to refresh
by select refresh from the desktop context menu. Why this talk about refresh? When you refresh the desktop it causes the applet to reload. Specifially it seems to call the applets destroy method and then
create a new applet instance. I can stop my threads and destroy them in the applets destroy method if
I want, however - what I really want is that the threads keep running (they are timers, loggers) and have
the applet user interface reconnect to them. Looking at one of the daemon threads, I have declared a static variable
in each of the class called 'running', which contains a pointer to the instance of the running thread. I can see
from the Java console, that if I don't call the thread.stop method from the applets destoy method that the
thread keeps running. However, the static variable seems to be reset to null each time the applet is reinitialised.

The question How can I avoid this so I can reconnect to the running thread?

Thanks in advance,
Nicholas Waltham


0
Comment
Question by:nwaltham
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 

Expert Comment

by:sdaxm11
ID: 1221387
how about the thread.sleep() method?
0
 
LVL 1

Accepted Solution

by:
dufort earned 400 total points
ID: 1221388
If your applet is running locally (e.g. no security restrictions), then you can react to the destruction of the applet by serializing the data you need to keep (e.g. put it on safety on disk). When the applet initializes, get back the data you serialized, and you're back to work. Put a "timestamp" variable in your serialized data so that you can verify if data is older than, say, 5 minutes. If the data is too old, your applet should reinitialize with new, fresh values (so when you start your applet on another session it starts with its initial values).

You should know that there is absolutely no way of reconnecting to threads with a new process (it is a question of security, and of pointers); and static variables are kept only in the scope of one instance of an application. Of course, threads can keep running when an app is dead, but they are "lost".

0
 

Author Comment

by:nwaltham
ID: 1221389
Thanks for the ideas - and for confirming reconnecting cannot be done!
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Suggested Courses

604 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question