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

NX: doubts on lock/unlock approaches

 
Manoj Gundawar
Ranch Hand
Posts: 169
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,
Here are my doubts about the two different approaches for contractor assignment.
Singleton Design Pattern :
One data object (the member of the object is actual file)
If I Synchronize on that object while doing read, write then why there is need to provide lock and unlock methods, as given in the interface.
Even read can't be possible during update as file pointer will get shifted.
So all the public method in the provided interface needs to be performed on synchronized object.

Design with Multiple data objects:
Here I can have One single vector (shared by all the clients) to add objects (record no) to lock during update. (private static vector)

But what about read then? How to handle the read? The same way as update? (lock, read, unlock?) Doesn't make much sense to me. But as the file pointer will be shifted during read, we can't also allow to read one record (by one client) and update other record (by other client) at the same time.
Same problem will occur even for update, even though the locking is in effect.
For client A wants to update rec. no 1, which is not locked.
For client B wants to update rec. no 2, which is not locked.
Then these two will try to write to the file at the same time (and that we are allowing) as there are many data objects. But this will corrupt the file.
(I guess I can solve this by synchronizing the Vector while update, so no other thread can access this vector, if it is in use. So they will have to wait to do their update, while this vector is in use)
Thanks for being patient to read the whole stuff.
Manoj
[ July 29, 2003: Message edited by: Jmannu gundawar ]
 
Tony Collins
Ranch Hand
Posts: 435
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Use filechannels to write to db, multiple file channels can access same file.
 
Manoj Gundawar
Ranch Hand
Posts: 169
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Tony,
That is another option. Actually I am aware of it. But I want to keep simpler design and I know all the developers are not using fine channels. I want to know how they are handling these situations without using file channels.
Thanks,
manoj
 
Mike Southgate
Ranch Hand
Posts: 183
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I just synchronized all of the IO methods.
ms
 
Manoj Gundawar
Ranch Hand
Posts: 169
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Mike,
Thanks. But then how did you use (implement) the lock and unlock methods? or did you just ignore them? (gave some no-use implementation?)
Manoj
[ July 29, 2003: Message edited by: Jmannu gundawar ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic