LinuxQuestions.org
Register a domain and help support LQ
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 09-21-2008, 05:37 AM   #1
arubin
Senior Member
 
Registered: Mar 2004
Location: Middx UK
Distribution: Slackware64 14.1 (multilib)
Posts: 1,209

Rep: Reputation: 55
Getting Java program to close properly on logging off kde


I have an accounts program that I have written in Java which I run in kde.

When I close the program all data is saved overwriting the old data file.

If I log off kde without closing the program down first then any changes to the data are lost.

How do I get the program notified of the log off so that it can close down gracefully?

Thanks,

Alan
 
Old 09-21-2008, 11:40 AM   #2
rjlee
Senior Member
 
Registered: Jul 2004
Distribution: Ubuntu 7.04
Posts: 1,990

Rep: Reputation: 66
According to a Google search, if you create a directory called ~/.kde/shutdown, and put a program in there, it will be run on shutdown. (http://linux.derkeiler.com/Mailing-L...4-08/2313.html)

To use that, You would need to write a program that would connect to your program and tell it to save its data. This might be a little more difficult in Java, depending on how you're running the program, but there are some IPC tools to help you with that (http://www.velocityreviews.com/forum...c-in-java.html).

However, nothing beats auto-saving: if you kill the X server with ctrl+alt+backspace, then all your programs will die, and if the program crashes then you've lost all your data anyway. My advice would be to periodically save to a fixed auto-save file, and then load from that if it exists. (This is more or less what Firefox does; even if you kill the program, you can still start it again right from where you left off.) Of course, that could be impractical for your application since I don't know what size of program you're dealing with.

Hope that helps,

—Robert J Lee
 
Old 09-21-2008, 01:40 PM   #3
jay73
Guru
 
Registered: Nov 2006
Location: Belgium
Distribution: Ubuntu 11.04, Debian testing
Posts: 5,019

Rep: Reputation: 130Reputation: 130
You could create a temporary file to store new data and use flushing to make sure that all data are written out as soon as possible. Then, when you restart the application, you could have an option to overwrite the original with the last temporary file, clear the temporary file or create a new one, etc. As rjlee says, there is a lot that can go wrong in between logging on and off.
 
Old 09-22-2008, 03:19 AM   #4
arubin
Senior Member
 
Registered: Mar 2004
Location: Middx UK
Distribution: Slackware64 14.1 (multilib)
Posts: 1,209

Original Poster
Rep: Reputation: 55
Thanks. The answers are not quite what I was looking for. No doubt autosaving and temporary backups are a good idea but other programs seem to 'know' that you are logging off and prompt you to save data.

This is a further prompt for me to take a very different approach and put all my data in a mysql database so everything is updated as the program runs.

Alan
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
I cannot close applictions properly zzcranjo Linux - Software 2 07-01-2008 07:04 PM
rsyncd: stopped logging properly hamish Linux - Software 0 01-23-2005 11:08 AM
Can't close a program.. why? how? brynjarh Linux - Newbie 7 08-12-2004 01:12 AM
how do i close a program lol Longinus Linux - Newbie 5 02-15-2004 12:10 AM
Gtk-Warning but program still works... I close konsole, program closes Laptop2250 Linux - Software 2 11-14-2003 11:18 PM


All times are GMT -5. The time now is 04:29 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration