Solved

Threads - reconnecting to threads.

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Free Alternative to JIRA 4 91
Java Server Faces parameter pass? 6 39
Java Options in Zimbra Server 2 47
reverse digits of a number using for loop 5 36
After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

864 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

19 Experts available now in Live!

Get 1:1 Help Now