• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

thread newbie

 
Luke Shannon
Ranch Hand
Posts: 239
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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");
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 ]
 
Maulin Vasavada
Ranch Hand
Posts: 1873
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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..

Regards
Maulin
 
Luke Shannon
Ranch Hand
Posts: 239
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks. After a quick google search I ended up using a Thread.sleep(), seems to do the trick.
 
Mr. C Lamont Gilbert
Ranch Hand
Posts: 1170
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
consider investigating Object.notify()
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic