Win a copy of Java Mock Exams (software) this week in the Programmer Certification (OCPJP) forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Threading

 
Tim Adam Cooper
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In the Java Developer project (FBNS),it stated that I am required to do lock/unlocking by blocking etc.
Must I use Threading to achieve locking/unlocking? I ask this question because I have done locking/unlocking without using Threading and the program work fine in that only one user can update a record at a time.
 
Philippe Maquet
Bartender
Posts: 1872
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Tim,

Must I use Threading to achieve locking/unlocking? I ask this question because I have done locking/unlocking without using Threading and the program work fine in that only one user can update a record at a time.

What do you mean exactly ? If you mean implement locking/unlocking within a multithreading environment, the answer is YES : "Your server must be capable of handling multiple concurrent requests".
In your lock method, the calling thread must acquire a lock (monitor) on some object, and wait() ("consuming no CPU cycles) till it's notified, and there are multiple ways to achieve this.
The fact that only one user can update a record at a time has no influence (IMO) on the way locking must be implemented according to its own specs.
Regards,
Phil.
 
Mike Southgate
Ranch Hand
Posts: 183
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you're using RMI, then your server side will be implicitly multithreaded anyway. You just need to ensure that the server can handle it without data corruption.
ms
 
Mark Spritzler
ranger
Sheriff
Posts: 17309
11
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
es, getting an Object's lock and calling wait() and notifyAll() are the ways to meet the requirements. Thats the quick answer.
Mark
 
Happiness is not a goal ... it's a by-product of a life well lived - Eleanor Roosevelt. Tiny ad:
the new thread boost feature: great for the advertiser and smooth for the coderanch user
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!