• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

About Lock Mechanism

 
Song Lixin
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here is some thoughts about my lock mechanism, Hope some guys can help dig out some holes from it.

If you use RMI and register the DatabaseRMI Object(instead of a factory), then at any time in the server JVM,
there are at most one Data(and maybe accompanied by one Adapter) instanse. So both static member and instance
member has only one copy in memeory.

So the lock machanism can be acheived via 2 ways:
  • Only lock the record that the client is updating(or deleting) and lock the file pointer that the client is using.

  • this way provide a more efficient locking. you can even provide a lock object for every record, so when unlocking,
    no client waiting for other record being notified. In this way, you provide separate protection for

    A) Each of the record
    B) The file pointer(or raf object).
    So there are n(number of the records) + 1 locks. As far as each lock is released before the thread try to gain
    another lock, deadlock would not happen.
  • A more defensive way is to add synchronized to sensitive methods, such as read, update, delete. in this way, you use

  • only one lock, it's more simple and deadlock is absolutly avoided.

    I think you can use either option 1 or option 2, but need not both.

    [ June 23, 2004: Message edited by: Song Lixin ]
    [ June 23, 2004: Message edited by: Song Lixin ]
     
    Ching-Tien Chang
    Greenhorn
    Posts: 16
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Sorry, I have a little question about solution 1:

    there are at most one Data(and maybe accompanied by one Adapter) instanse. So both static member and instance member has only one copy in memeory.

    Only lock the record that the client is updating(or deleting) and lock the file pointer that the client is using.


    question is : how many file pointer in your data instance?
     
    Song Lixin
    Greenhorn
    Posts: 19
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Ching,
    Because I still has not dive into detail, I think One file pointer in memory is enough. Right? You open the file, let a Schema object get it's info first, then you keep the pointer for later use.
    [ June 23, 2004: Message edited by: Song Lixin ]
     
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic