This week's giveaway is in the Spring forum.
We're giving away four copies of REST with Spring (video course) and have Eugen Paraschiv on-line!
See this thread for details.
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes Why are lock methods required? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "Why are lock methods required?" Watch "Why are lock methods required?" New topic

Why are lock methods required?

Millicent Bare

Joined: Feb 27, 2007
Posts: 2
In the URLyBird project, the requirements specify an interface that includes
lock(recNo), unlock(recNo), and isLocked(recNo).

The way I'm implementing things, I don't see why the lock methods are required.
Can someone please explain?

First, it looks like only update() and find() are even needed by the
application. Obviously these methods are synchronized so that the file
pointer is not disturbed while seeking/reading/writing. Now, assuming
update() always checks the "owner" field before overwriting, then I've
guaranteed not to overbook on top of another reservation. Therefore, why
is lock needed? My synchronized methods ensure only one update() runs at
a time anyway.

The other problem is that lock() doesn't have a parameter to specify the
client requesting the lock. I can't use thead information here because a
client can connect to any server thread.

Can someone help me, please?

Petr Hejl
Ranch Hand

Joined: Feb 26, 2006
Posts: 68
You are asking for something discussed for million times...
Try to search the forum.
subject: Why are lock methods required?
It's not a secret anymore!