• 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

Where to call wait()?

 
Ranch Hand
Posts: 223
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am trying to get my locking to work, using synchronized, wait and notifyAll. I had been calling wait inside lock() but it hung my application. (Waiting forever). I have never written multi-threaded code before, and this is pretty confusing. From searching and reading lots of old posts, I am pretty sure I synchronize on my Map of locks, and only call notifyAll from unlock(). I am wondering if I even need to wait? I have the "consume no CPU cycles" in my instructions, so I'm pretty sure setting a timeout is a bad idea, and probably automatic failure. I also understand the notifyAll might consume a few (trivial few), but people generally have passed with full marks and used it. Thanks in advance.
 
Sheriff
Posts: 11604
178
Hibernate jQuery Eclipse IDE Spring MySQL Database AngularJS Tomcat Server Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Anne,

locking is the hardest part in my opinion

you can only wait on an object where you have the lock on.

locking would be something similar to:


and in your unlock method you will have something like


if you have synchronized all your methods, you will call wait and notifyAll on the this-object

good luck!
 
Anne Crace
Ranch Hand
Posts: 223
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks, Roel,

I had a logic error in my code. I had everything you just told me, but this statement: I figured the lock wouldn't be in there yet, because I hadn't put it in there. I guess that is the whole point It works now, at least not throwing any exceptions and hanging. I guess I need to thread thrash it, now.
 
Roel De Nijs
Sheriff
Posts: 11604
178
Hibernate jQuery Eclipse IDE Spring MySQL Database AngularJS Tomcat Server Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
it took me 3-4 weeks to make my Data-implementation (i have fulltime job, so only weekends and evenings), but because i see it as the most important part, i took my time to ensure everything is working as expected (and javadoc'ing everything is also time consuming). I made also a unit test to verify if each method of the data class is doing what the javadoc says (including all possible exceptions that can be thrown). and the lock/unlock methods i tested using the test classes of roberto perillo.
 
Anne Crace
Ranch Hand
Posts: 223
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I got a test harness off this forum. I will grab Roberto's as well. He got 80/80 in Locking. He also synchronized all of Data (I did that, too). I am lucky, I have down time at work right now, so I am working on it at work, and have made major progress this week. I should be getting another project tomorrow or Monday. I don't have time to work on it at home because I am working on my BS degree in Information Systems and my free time is spent working on that.
 
Roel De Nijs
Sheriff
Posts: 11604
178
Hibernate jQuery Eclipse IDE Spring MySQL Database AngularJS Tomcat Server Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Anne Crace wrote: He also synchronized all of Data (I did that, too).



Me too

I'm not that lucky at work, i even have to travel 1.5 - 2h each day, so my time during the week is very limited, but it has a high priority, because i've the assignment already from Q2 2007 and all other projects have lower priority, i hope to finish at the beginning of april

which test harness are you using?

good luck with your assignment (and your bs degree)
regards,
Roel
 
Anne Crace
Ranch Hand
Posts: 223
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I used this one: Take this Testing Tool. Be sure to note the second post. There is a small logic error that needs to be fixed in the original code. I found Roberto's in the process of looking for this one I have had mine out since Spring of 2006, so it is a priority for me, too!
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic