LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
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 15.0 (multilib)
Posts: 1,350

Rep: Reputation: 75
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,994

Rep: Reputation: 76
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
LQ Guru
 
Registered: Nov 2006
Location: Belgium
Distribution: Ubuntu 11.04, Debian testing
Posts: 5,019

Rep: Reputation: 133Reputation: 133
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 15.0 (multilib)
Posts: 1,350

Original Poster
Rep: Reputation: 75
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



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

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 01:27 PM.

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration