File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes Bodgitt & Scarper contractor booking Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "Bodgitt & Scarper contractor booking" Watch "Bodgitt & Scarper contractor booking" New topic

Bodgitt & Scarper contractor booking

joe jones

Joined: Jan 29, 2005
Posts: 1
Hi all,
I am working on B&S version 2.2.1 and have a few questions about booking of contractors. At the moment, I have a table of contractors from the database, and a client is able to select a particular row and click 'Book', which then generates a random long (representing the CSR number), and updates the table, displaying this long in the 'Owner' column. The book() method uses a lock(), update(), unlock() sequence of operations, synchronized on a hashmap of currently locked records.

My question is this -- are other clients able to book contractors which are already booked? So if Client1 books contractor 5, is Client2 then allowed to overwrite this booking? If not, should a message be shown to the client that the contractor is already booked???

Thanks for any tips...

Frans Janssen
Ranch Hand

Joined: Dec 29, 2004
Posts: 357
Hi Joe,

I have assumed that it is not allowed to book an already booked client. What would be the purpose of booking if the booking can be overwritten?

I made the book functionality perform the sequence lock - read - update - unlock, where the read call is to verify that the contractor is not booked yet. If the contractor is already booked, the booking is aborted of course.

IMHO, this sequence is the primary reason why we need to have lock/unlock methods to begin with: only when the record is locked can we be certain that no other client has just booked the contractor.


Clivant Yeo
Ranch Hand

Joined: May 22, 2004
Posts: 124
Hi Joe,

Just make sure that the first thread to book a record gets to book the record. The rest of the thread which wants to book the record afterwards should be denied.


Clivant Yeo
My Personal Website
Paul Bourdeaux
Ranch Hand

Joined: May 24, 2004
Posts: 783
which then generates a random long (representing the CSR number),
I am slightly off topic, but I noticed this and wondered why you decided to generate a random number instead of letting the user enter one in. My instructions state
Note that for this application, you should assume that customers and CSRs know their customer ids.
I would hate to see you lose any unneccessary points.

“Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.” - Rich Cook
I agree. Here's the link:
subject: Bodgitt & Scarper contractor booking
It's not a secret anymore!