Solved

Threads - reconnecting to threads.

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
jsp login check 12 62
Crystal Reports Licensing Questions 4 83
Html Table Looping (part 2) 5 39
Java List 4 73
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…
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.
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:
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
Suggested Courses

737 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