Solved

Threads - reconnecting to threads.

Posted on 1998-05-23
3
254 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
3 Comments
 

Expert Comment

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

Accepted Solution

by:
dufort earned 100 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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
java 8 lambda expresssions exception handling 3 90
Windows 10 IE Certificate Issue 10 45
Java exception bubble up 2 18
Glassfish admin console not working 1 12
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
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 will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…

773 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