LinuxQuestions.org
Share your knowledge at the LQ Wiki.
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 05-07-2009, 06:20 PM   #16
David1357
Senior Member
 
Registered: Aug 2007
Location: South Carolina, U.S.A.
Distribution: Ubuntu, Fedora Core, Red Hat, SUSE, Gentoo, DSL, coLinux, uClinux
Posts: 1,302
Blog Entries: 1

Rep: Reputation: 107Reputation: 107

Quote:
Originally Posted by amysaraantony View Post
Ensure at the time of closing the application this entry is set to false.
This method fails in the event that the application crashes. All further instances (even a valid one) will think another instance is running.

On the other hand, if you keep the file handle open after creat (something I forgot), no one else will be able to create the file, but if you crash, the O/S should clean up after you.

This doesn't work so well on Windows, because Windows is horrible about trying to clean up after crashed applications.
 
Old 05-08-2009, 03:21 AM   #17
abhinav.zoso
LQ Newbie
 
Registered: Jan 2009
Posts: 14

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by David1357 View Post
This method fails in the event that the application crashes. All further instances (even a valid one) will think another instance is running.

On the other hand, if you keep the file handle open after creat (something I forgot), no one else will be able to create the file, but if you crash, the O/S should clean up after you.

This doesn't work so well on Windows, because Windows is horrible about trying to clean up after crashed applications.
You are spot on. The problem would arise if the program crashes or if the computer shuts down improperly (in case of power failure).
 
Old 05-08-2009, 03:52 PM   #18
abhinav.zoso
LQ Newbie
 
Registered: Jan 2009
Posts: 14

Original Poster
Rep: Reputation: 0
Well, I have found another workaround. Using sockets is an option. So when the jar (java app) is started, bind it to an arbitrary, high port (high port is to ensure that the port is free and available to be used). When the application exits, close the port. Whenever the application is run, bind it to the same port. So this ensures another instance is not open when one is already running.

Advantage is that it is much easier when compared to the file opening/locking method.

Disadvantage is that the program won't run if the port is already in use. So use a high end port (for ex, 50000 or higher) as the chances of these ports being used are less.
 
  


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
Error tryin to install jar Executable khalil_noura Linux - Newbie 1 12-15-2008 02:13 PM
Java: executable jar files on xp mac and linux redmoon zero Programming 9 03-18-2008 01:35 PM
Fedora Core 1 Associating .jar files with java -jar command pymehta Fedora 0 01-13-2005 05:26 AM
Cannot not run executable jar file after set content type for download antony_csf Programming 1 12-08-2004 12:22 AM
executable jar in java (cannot double click) spyghost Programming 3 09-29-2003 09:13 AM

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

All times are GMT -5. The time now is 01:13 AM.

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