• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

client locking row twice

 
Karen Smrha
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am worried about following my instructions correctly and would appreciate your opinion.

I don't want a client to wait on a locked record if that same client already has the lock. So instead of making the client wait, I ignore the request and return.

I documented this in javadoc and choices.

My instructions contain:


Your data access class must be called "Data.java", must be in a package called "suncertify.db", and must implement the following interface:
.
.
//If the specified record is already locked, the current thread gives up
//the CPU and consumes no CPU cycles until the record is unlocked.
public void lock(int recNo) throws RecordNotFoundException;
.
.
"Any attempt to lock a resource that is already locked should cause the current thread to give up the CPU, consuming no CPU cycles until the desired resource becomes available."


I am worried about flunking a "must do". Do you think this means I really have to make the client wait on a lock it already has?

Thank you for your help,
Karen Smrha
[ November 26, 2008: Message edited by: Karen Smrha ]
 
Roberto Perillo
Bartender
Posts: 2271
3
Eclipse IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey, partner.

Here's what I did: each client can own only one lock at a time. If a particular client tries to lock a record, and this client already owns the lock of a record, I throw an IllegalStateException.
 
Karen Smrha
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bob,

Do your instructions have something like this?


//If the specified record is already locked, the current thread gives up
//the CPU and consumes no CPU cycles until the record is unlocked.
public void lock(int recNo) throws RecordNotFoundException;


or do you have something like this?


//If the specified record is already locked by another client,
// the current thread gives up
//the CPU and consumes no CPU cycles until the record is unlocked.
public void lock(int recNo) throws RecordNotFoundException;


I have the first one. I worry about flunking if I miss a SUN "must" requirement.

The method description does not say "must", but I have a "must" implement this interface so I am unsure if this only means "must" implement method signature (I do) or if it also means "must" implement method description (I don't make clients wait on locks they have).

Thanks,
Karen Smrha
 
Roberto Perillo
Bartender
Posts: 2271
3
Eclipse IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is the signature of my lock method:

 
Jeffry Kristianto Yanuar
Ranch Hand
Posts: 759
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The word "the CPU must give up the CPU and consumes no CPU cycle" means that the client thread must wait undefinitely until the other client release the lock.

I use interface Lock and Condition to achieve this.

So if you simply return the method, I'm afraid you will violate the interface.

Hope that will help you
Good luck on your exam and wish me luck too !!!

Jeffry Kristianto Yanuar (Java Instructor)
SCJP 5.0, SCJA, SCJD (UrlyBird 1.3.2) --> Waiting for the result
 
Karen Smrha
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bob,

Thanks!!

I see from your signature you have have passed. Congratulations!

If SUN did not force you to make clients to wait on locks they aready have, I should be ok. It's a relief to hear from someone who has passed. I plan to upload in a couple weeks so I am getting nervous.

Congratulations and have a great summer!
Karen
P.S. Can you send some Brasilian sun to the Netherlands. It's cold here.


-----------------


From Jeffry Kristianto Yanuar
The word "the CPU must give up the CPU and consumes no CPU cycle" means that the client thread must wait undefinitely until the other client release the lock.


Jeffry,

I do make clients wait if "a different client" has locked the record.

It's only when the same client already has the lock that I return successfully. I don't make them wait on a lock they already have.

My instructions say "wait if locked" (not "wait if locked by other client) so I was unsure if SUN's instructions force me to make a client wait on a lock it already has.

I hope you get your results quickly and they are good!
GOOD LUCK!
Karen
 
Roberto Perillo
Bartender
Posts: 2271
3
Eclipse IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey, my buddy! Thanks!

And you know, during this summer, some days have been very hot here in Sao Paulo, and others have been kindda cold. There's a state here in Brazil called Santa Catarina that has been through a pretty sad catastrofic flood season: At least 50 dead in Brazil flooding. I blame the global warming.

But, regarding your assignment, make sure your locking mechanism works properly in both local and networked mode. If that's ok, then your chances of passing are almost 100%. Good luck to you and Jeffry!!!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic