I am trying to get my head around session – timeout – idle handling Multi-treads in Java.
I have a server & client application comunicating via telnet where I need to check if the user has been typing (anything), clicking (anywhere), or moved the mouse within a periode of time.
If not, the user will be prompted with a dialog box, asking if he wants to conntinue session or not. …(and If not, the user will automatically be logged out within the next minute or so.)
My application has multiple threads. ( – One user per thread). So I am not sure how to approatch this the best (and easiest) way?
I know it is a wide and far-fetched question, but I was hoping some of you could give me a pointer or tip in the right direction… 🙂
I was kind of hoping for a simple method that could check:
(a bit pseudo code on the fly:)
if (idle = true){
timer.start();
if (timer > 120sec)
displayWaringJFrame("Continue Session? - YES or NO ?)
displayTimer.start();
if (displayTimer > 30sec)
application.user.closeSession()
…or something like that! 🙂
The simplest solution is a class java.lang.Thread.
You can create class and implements interface Runnable
in main function create class Thread and as constuctor argument set instance of Session class after this importatnt is call method .start()
Much more convenient way to work with threads is java.util.concurrent.ExecutorService and java.util.concurrent.Executors