• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

thread newbie

 
Ranch Hand
Posts: 240
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Ranch Hand
Posts: 1873
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 240
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks. After a quick google search I ended up using a Thread.sleep(), seems to do the trick.
 
Ranch Hand
Posts: 1170
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
consider investigating Object.notify()
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic