File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Lock on the Object creates the Problem.

 
shashikant kale
Greenhorn
Posts: 6
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello friends,
in that i had one problem :
Let say there are 2 thread ReaderThread and WriterThread.and one vector which had some values.
readerth reads from Vector and WriterTh writes into vector .
before reading from vec. i put lock onto vect. and then i read the data from it.so taht no other will access this vect.and after read'g is ok i'll realeas the lock from vector.

code: for Lock is here:

but it wont proplerly. so can u pl. suggest somethins reg. to locking on to the Vector which will be shared by my 2 threads.

thanks in advance,
shashi
[Added code[/code] tags - Jim]
[ August 02, 2002: Message edited by: Jim Yingst ]
 
Michael Morris
Ranch Hand
Posts: 3451
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi shashjava,
First of all you probably need to change your display name per the naming policy at javaranch.
Now for your problem, you may want to try something like this instead:

Your read thread then calls lock, reads the vector and then calls unlock. Your write thread simply calls checkLock() which blocks until the lock is realeased.
Hope this helps,
Michael Morris
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic