wood burning stoves 2.0
The moose likes Threads and Synchronization and the fly likes thread newbie Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Java » Threads and Synchronization
Bookmark "thread newbie" Watch "thread newbie" New topic

thread newbie

Luke Shannon
Ranch Hand

Joined: Sep 30, 2004
Posts: 239
hi all;

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");
} 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?


[ November 12, 2004: Message edited by: Luke Shannon ]

Maulin Vasavada
Ranch Hand

Joined: Nov 04, 2001
Posts: 1873
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..

Luke Shannon
Ranch Hand

Joined: Sep 30, 2004
Posts: 239
Thanks. After a quick google search I ended up using a Thread.sleep(), seems to do the trick.
Mr. C Lamont Gilbert
Ranch Hand

Joined: Oct 05, 2001
Posts: 1170

consider investigating Object.notify()
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
subject: thread newbie
It's not a secret anymore!