Solved

Threads - reconnecting to threads.

Posted on 1998-05-23
3
243 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
Comment Utility
how about the thread.sleep() method?
0
 
LVL 1

Accepted Solution

by:
dufort earned 100 total points
Comment Utility
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
Comment Utility
Thanks for the ideas - and for confirming reconnecting cannot be done!
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…

744 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now