This week's book giveaway is in the Kotlin forum.
We're giving away four copies of Kotlin in Action and have Dmitry Jemerov & Svetlana Isakova on-line!
See this thread for details.
Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Automatic logout  RSS feed

 
Anthony Kwok
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am developing an application using SWING, as this program will open a db connection and it may waste the resource when the user is left without quitting the application. Any good tips to make the application quit automatically after a specific period of idle time?
Anthony
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
All you really have to do is create a boolean variable and a thread in your program. Start the boolean out as true. Have the thread run at specified intervals, like every 5 minutes or so, and check the boolean and set the boolean to false. Have all your action listeners set the boolean to true before doing what you want with them. If the thread checks the boolean and it is still false from the last time it checked it and set it to false, there has been no activity, so it can clean up the resources, or exit the program, or do whatever you want.
HTH,
-Nate
P.S. - This question didn't really have anything to do with Swing... but why am I complaining... It helps me get more chances to win the prize, too...
 
Anthony Kwok
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your reply but it is the exact thing I wanted. If I only reset the flag from the action listeners, that means the thread will still close the application if the user only viewing a record, moving the mouse, or navigating using cursor key. I think the method suggested should like a screen saver. Activated after a specific period of 'TRUE' idle period. That's why I asked if Swing has some channels that I can insert the code.
Anthony
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!