• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

about lock/unlock question

 
Jofer Chan
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,every one:
who can give me a code about lock/unlock,
I don't know to write that code about lock/unlock.
or give me a URL about this.
thanks.
 
Andrew Monkhouse
author and jackaroo
Marshal Commander
Pie
Posts: 12007
215
C++ Firefox Browser IntelliJ IDE Java Mac Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Jofer,
You have to write the code yourself - you are not allowed to submit someone else's code.
Plus - any code offered here may not work for you: There are at least (to my knowledge) 3 different assignments, and there are multiple variations on each of these assignments, all with different requirements for locking and unlocking (our JavaRanch SCJD FAQ page has a question How may assignments are there? (What is an NX assignment?) which shows some of those different lock signatures).
In general the way this forum works is that you can post a general question which will get a general answer (or a link to something you can read), or you can post small sections of code for others here to critique.
The locking concept is fairly easy (but getting the implementation right can be tricky ).
  • The user will provide you with the number of the record they want locked.
  • You will have to verify that it is not currently locked (so you are going to have to track which record numbers are currently locked
  • If the record is currently locked the client will have to wait until it is unlocked.
  • Then the client can lock the record and return.


  • Note that your lock signature may or may not use cookies to identify the client who has locked the record. If so, then you are going to have to track the cookie as well as the record number. If not then you are going to have to track the owner of the lock some other way.
    When the client modifies a record you are going to have to check if that particular client has locked the record.
    When the client unlocks the record you are going to have to notify all the clients who are wait ing for the lock.
    Does that give you some ideas to start with?
    Regards, Andrew
     
    Jofer Chan
    Ranch Hand
    Posts: 49
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Hi,Andrew:
    you said is very good.
    I knowe.
    Thank you very much!
    Is lock/unlock synchronization/notify mechanism?
    Would you give me a location(URL) to study this?
     
    Andrew Monkhouse
    author and jackaroo
    Marshal Commander
    Pie
    Posts: 12007
    215
    C++ Firefox Browser IntelliJ IDE Java Mac Oracle
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Hi Jofer,
    Is lock/unlock synchronization/notify mechanism?

    The lock and unlock methods you write will use synchronization/notification.
    Would you give me a location(URL) to study this?

    A location to study synchronization? You should be able to look at your resources for SCJP for that.
    Or a location to study how to do locking in this assignment? I don't know of any online resources for that. Max describes a similar concept in his book The Sun Certified Java Developer Exam with J2SE 1.4. Alternatively, if you look at the description of what I wrote above, and look at synchronization and collections from your SCJP notes, and you should start having some ideas. Then come back to this forum with those ideas.
    Regards, Andrew
     
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic