• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

detect Applet user inactivity

 
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,
I need some advise on the issue, of detecting user inactivity on my applet.
My current scenario is, my applet is hosted from a jsp page on the client machine, the applet contains a lot swing components (many jframes).
I want to somehow detect the user inactivity on that page hosting the applet.
Say for example if the user doesnt perform any action (like a mouse click) on the main applet or any of the child jframes spawned from it, for say 15 mins. I want to close the applet and the jframe saying Session Timeout.
Or other than this is there any way for applet to deal with session parameters to perform the timeouts, when no user activity takes place, on the JSP holding the applet.

Hope i am clear enough in my scenario.

Please advise.

Thanks,
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You could keep a timer thread that starts running once the applet is initialized. After 15 minutes, it would trigger whatever you want to do on session timeout.

Then you add event listeners (a MouseMotionListener is probably sufficient) -which restart the timer thread each time they're invoked- to all frames.
 
Amit Hetawal
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,
So i followed your approach for creating a timeout thread. And on my timeout thread i destroy the applet in my jsp and navigate to a new jsp.
But my timeout thread is still alive ven when i destroy my applet. So my question is how do i kill or stop this thread.

Below is the code :

void init(){
Thread lastNavActionThread = new Thread(this);
lastNavActionThread.start();
}

public void run(){
boolean shouldrun = true;
try{
long staticTimeVar = 30000;

while (shouldrun) {
logger.info("i am ruuning");
long timeElapsed = Calendar.getInstance().getTime().getTime() - getLastNavAction().getTime();
logger.info("time is" + timeElapsed);
if (timeElapsed > staticTimeVar){
logger.info("i am quititng");
shouldrun = false;
timeOut();

}

Thread.sleep(staticTimeVar);
}
}catch(Exception e){
logger.error("sorry error");
}
}

But the problem now is even when i destroy my applet this timeout thread still remains. How can i kill it too along with the destroy.

Please help.

Thanks
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Any cleanup should be done in the Applet.stop method.
 
Amit Hetawal
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,
Can you please elaborate on the cleanup on Apple stop method. basically i want to stop this thread in my applet stop/destroy method. Any idea how can i do that.
public void destroy() {
logger.info("Executing applet destroy.");
Container c = this;
c.removeAll();
quit(false);
logger.info("Ending Execution of applet destroy.");
super.destroy();
}
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I suppose both Applet.stop and Applet.destroy can be used. In your code, you'd set the "shouldrun" boolean to true, so that the thread terminates itself next time it runs. You should also call its interrupt() method, in case it's sleeping.
reply
    Bookmark Topic Watch Topic
  • New Topic