Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Deleting a lock file not working.

 
Skip Cole
Ranch Hand
Posts: 177
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

I am using synchronized methods to prevent multiple threads from accessing the same records, but since my assignment calls it to be able to run locally and remotely, I wanted to create a lock file - to show one application that the database is already in use.
(I know this is overkill. I figured it would be simple, plus I figured it would be a nice thing to know how to do.)
Anyway, creating the lock file is simple. But getting rid of it has been impossible.
----------------------
To Create:
String lockFileName = dataBaseFileName + "_lock";
File lockFile = new File(lockFileName);
clobberName = lockFile.getAbsolutePath();
----------------------
To Remove:
public void removeLockFile() {
File lockFile = new File(clobberName);
System.out.println("attempted to delete " + lockFile);
boolean bresult = lockFile.delete();
System.out.println("results of removing: " + bresult);
}
-----------------------
I get the right path back and everything, but the results of trying to delete this file are always false.
Any Ideas?
Thanks in Advance,
Skip (www.skipcole.com)
 
davidlong
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
For your information, did you know when you declare:
File lockFile=new File();
the lockFile dose not really exist in any sense, if you delete such a file, you never get "true".
hope this will remind you some thought
David
 
Skip Cole
Ranch Hand
Posts: 177
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oh, I left out that I do the following:
FileOutputStream fos = new FileOutputStream(lockFileName);
fos.write('O');
This actually does create the file, and put the single character 'O' for open, inside of it.
The file does get created. I can see it and actually the program won't start again unless I delete it.
Thanks for pointing out that I hadn't mentioned this. So now, how do you delete the file?
Skip
 
Jeff Holmes
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Trying either closing your stream to the file or set the othe File to null once it is created. Just check for it when doing the check. I believe this is where your problem lies. But aside from this, Why create a Lock file? It's not a requirement and you don't score extra credit for it? The ONLY thing this can do to you is hurt you.
 
Skip Cole
Ranch Hand
Posts: 177
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I will try that. Thanks for the ideas.
I know, its probably not necessary. I'm doing it because I want to know how to do it, and if it is done correctly, I don't think I'll lose points for it.
Skip
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic