need some help. i have to create an object, one of the arguments in the constructor is a directory. however the directory must be "unlocked". there is another object in the program that holds the lock on the file.
basically i want to say, "before you create this object wait for the lock to be released on the folder". here is what i am trying:
//create the writer System.out.println("Creating a new writer."); System.out.println("The index is locked: " + IndexReader.isLocked(indexFileLocation)); while (IndexReader.isLocked(indexFileLocation)) { try { System.out.println("Waiting for the reader to release the lock on the index"); Thread.sleep(10000); } catch (InterruptedException e2) { System.out.println("INDEX ERROR: There was a problem waiting for the lock to release. " + e2.getMessage()); } }
do i need a notify somewhere? will this sleep forever?
thanks,
luke [ November 12, 2004: Message edited by: Luke Shannon ]
Luke
SCJP
Maulin Vasavada
Ranch Hand
Joined: Nov 04, 2001
Posts: 1865
posted
0
Hi Luke,
It seems you need Locking and not much of a threading. Locking would be required as your object/direcotry will be accessed by multiple threads.
Currently I am unable to throw more ideas on here but I would do that soon.
Meanwhile, you can google on how to locking in Java and think more while anybody else can give you more details about locking and all..