• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

locks.notifyAll()

 
Daniela Ch
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I am calling those lines of code from my Lockmanager::lock() wich is a syncrhonized method

anybody have a clue?
/Daniela
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not much to go on in your code sample, just three lines.
But, are you 100% positive you have the lock on the locks Object that the variable refers to? If not, I would expect an exception to be raised when you try to notifyAll. which would make the next line not run, because it would jump out of your Try statement and into a Catch.
Mark
 
Daniela Ch
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

i read it many many times in the book that I should only call wait/notify/notifyAll inside synchronized code, and that synchronizing a methode give you the lock of "this", not the lock of the object on which you are calling .notifyall, and i *did* the mistake that i should not do.
I lost 8 hours .
8 precious hours trying to figure that *&!#*(@ bug.
I fixed it...
but thanx anyways
btw, I signed your guestbook
ps: peter is not bartending anymore?
 
Peter den Haan
author
Ranch Hand
Posts: 3252
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Daniela Ch:
ps: peter is not bartending anymore?
Assuming I'm the one you're referring to -- it's been quite a while since I've been bartending this particular venue. Which doesn't stop me dropping in at times, having a pint or two and sharing stories with Mark and some of the regulars and not so regulars, only to stumble off again later. And occasionally there's real life to attend to as well of course
- Peter
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Note that the real problem here is not so much the fact that you called notifyAll() without acquiring the lock first, but the fact that somehow your code allows an exception to be thrown without being logged. Typically this means that somewhere there's something like

Tracking this down and fixing it will be well worth your time.
 
Daniela Ch
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you Mark Peter and Jim (hey, I have friends on the forum now )
Jim, I used to have a System.out.println() in the catch (please dont comment on this )
Peter, I was wondering where you were because they changed this a few days ago :
Developer Certification
(Moderated by: Mark Spritzler, Junilu Lacar)
/Daniela
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nothing wrong with using System.out.println(), at least temporarily while you're developing and testing. It's usually worthwhile to eventually set up logging using java.util.logging, Log4J or something similar - but if you haven't done so yet, any error message is better than none. I usually just put in e.printStackTrace() so that I know exactly where the error occurred - it may look ugly, but it works.
As for Peter, well, ever since the press conference where he made those unfortunate comments about VB programmers, the JavaRanch offices were being picketed by outraged ranchers demanding his resignation. We feel it best if Peter lies low for a while until the current scandal dies down.
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
few days ago

Wow, that sure was a very long few days.
And they say time flies when your having fun.
Mark
 
Daniela Ch
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
non non...a few days ago it was Mark and Peter...
I have been on JavaRanch since december 13...how would I know that Peter was bartending if it wasn't there a few days ago?
/Daniela
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic