Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Current thread not owner.

 
Wilder C Rodrigues
Ranch Hand
Posts: 107
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi!
I'm having problems with synchronized blocks.
If I try to do that:

An exception is thrown with the message: current thread not owner.
If I use synchronized in the method singnature, it works. However the system freeze waiting for someone unlock the record locked.
I think that there is no reason to use wait() and notifyAll() methods. Why?!
Because whether I lock a record for 5 hours someone will wait for it.
The synchronized blocks will help with that. Even without wait() and notifyAll() methods.
My english is bad. Does anyone understand me?
thanks,
Wilder
SCPJ
SCWCD
[Andrew: Put code between [code] and [/code] UBB tags]
[ October 23, 2003: Message edited by: Andrew Monkhouse ]
 
Michael Fitzmaurice
Ranch Hand
Posts: 168
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Wilder
You are getting this error because a thread can only call wait on an object that it currently holds the lock for. In this case, the thread obtains the lock for the object named 'lockedFields', but then tries to call wait on the class enclosing this method (a different object).
I think you need to have a careful rethink of your locking strategy. You definitely have to develop a mechanism using wait & notify/notifyAll, as made clear in the answers to your previous post (the one where you asked if you should be using wait & notify). If you don't do this, I am certain you will fail the assignment.
Maybe go back to your SCJP notes and revise multi-threading - do some reading around this to make sure you really understand it. Sorry to be the harbinger of doom, but I feel that you have no choice but to redesign some fundamental parts of your project.
Michael
 
Philippe Maquet
Bartender
Posts: 1872
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Wilder,
Michael is right at 100%.
This may help you :

Best,
Phil.
 
Wilder C Rodrigues
Ranch Hand
Posts: 107
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks to all of you.
I made the changes and now it is working well.
I still have some small problems, but I'll take care of that.
bye,
Wilder
 
Andrew Monkhouse
author and jackaroo
Marshal Commander
Pie
Posts: 12014
220
C++ Firefox Browser IntelliJ IDE Java Mac Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Wilder,
Why are you calling notifyAll() inside your lock() method? As Phil wrote in his code, the line is useless.
As you can see, I put your code inbetween [code] and [/code] UBB tags. This makes your code much easier to read. Please edit your original post and look at what I did, and/or look at the descriptions for UBB tags.
Regards, Andrew
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic