Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

[B&S] Lock calling...

 
Marco Santinon
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,
I have a question about lock() and unlock() methods.

These method have to be called inside others methods in the Data class, or is the user of the Data class that must call them?

I mean, when updating data on the file, is the method update() that must call lock()/unlock(), or is the caller of the method update() that must call them?

I think about Sun automatic test for the Data class: what will it do? It calls lock(), update() and unlock() or only update()?


Thanks for your help.


Marco
 
Lucy Hummel
Ranch Hand
Posts: 232
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Marco,

I have never thought that the update internally calls lock and unlock.

I think that the method should not call lock/unlock. At least in my comments that Sun gave me is that stuff not mentioned.

The client calls lock, update and unlock.

But please check your requirements, perhaps I am wrong on that regarding your requirements.
 
Bod Toki
Ranch Hand
Posts: 95
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1. lock() and unlock() are both public methods, meaning that they will be, (and I believe) meant to be called from some external code.

2. Sun doesn't say anything about update() not calling lock()/unlock(), so i believe you would get away with doing this.

3. I, however, believe that the idea of these methods is to have some external code call lock(), update(), then unlock(). Code that doesn't honor this sequence would not be "multi-user" safe and will not be the problem of the designer of the class. I don't think Sun would expect your update() code to be "multi-user" safe. They would be expecting the "safeness" to come from the lock() and unlock() methods.
Remeber: ArrayList and Vector? Vector is concurrency safe, while the newer ArrayList is not. Some folks might need the ArryaList. Think about this.
 
Marco Santinon
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,
thaks for your replies.


I got the point.

Another little question: should the client call lock()/unlock() when reading data?

Thaks,

Marco
 
Lucy Hummel
Ranch Hand
Posts: 232
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Marco,

My architecture does not assume that reading needs a lock.
 
Bod Toki
Ranch Hand
Posts: 95
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In my instructions, write methods such as update(), and delete() throw an exception when lock is not owned, but read methods such as find() and read() do not. I believe this means that read() and find() do not need a lock for access - so no need for lock()/unlock() with read methods.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic