Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

"Value Object" pattern---problem  RSS feed

 
Edward Chen
Ranch Hand
Posts: 798
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am thinking the "Value Object" pattern. I have one question
if we have two client to access the same bean at same time, so, each client will get same "value object " stored in each local machine. But the problem is , when one client update the "value object " state, say, update the street of address, how does the other client know that the "value object " has been updated by the first client already?
I hope I make my question clear.
Thanks
 
Maulin Vasavada
Ranch Hand
Posts: 1873
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Edward,
Its not problem related to "Value object". Application has to deal with such simultaneous updates via some lock or something. So, application must enforce that no two persons have value objects for same entity in backend.
Thanks
Maulin
 
Kyle Brown
author
Ranch Hand
Posts: 3892
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is usually a case where optimistic concurrency (using a timestamp or an overqualified update) is the best option for keeping clients out of each other's way.
Kyle
 
Edward Chen
Ranch Hand
Posts: 798
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks, Kyle, could you tell me more about "optimistic concurrency " , timestamp, you are talking about NTP, RMID ?
Thanks.
Originally posted by Kyle Brown:
This is usually a case where optimistic concurrency (using a timestamp or an overqualified update) is the best option for keeping clients out of each other's way.
Kyle
 
Kyle Brown
author
Ranch Hand
Posts: 3892
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Read my book -- chapter 28, or find a standard database text and look it up there. Adequately explaining optimistic and pessimistic concurrency takes longer than you can spend in a JavaRanch posting. The core of the idea of optimistic concurrency is that your look for a particular value in a row before updating it (Either a timestamp you set when you last read the row, or some other combination of values).
Kyle
 
Luigi Smith
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Kyle,

I read your sample chapter 28. This has greatly increased my understanding of optimistic locking, but I have a few questions:

You mention when using optimistic locking it could throw an error on an overqualified update if the record is updated during the transaction. I was reading in the C.J. Date book on optimistic locking and he makes a suggestion of retrying the request.

I was wondering if this type of mechanism comes out-of-the-box with WebSphere or could I code something where I catch the exception and retry with a new overqualified update. Although, in the latter I wonder how the container would view the transaction (i.e., stop the old/failed one and start a new one, or other?)

Basically, I am trying to mitigate the risk of several exceptions occuring because you can't update, but then I guess you would have to be concerned about how many retries do you attempt before you give up. Thoughts?

TIA!
 
Kyle Brown
author
Ranch Hand
Posts: 3892
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Luigi Smith:
Kyle,

I read your sample chapter 28. This has greatly increased my understanding of optimistic locking, but I have a few questions:

You mention when using optimistic locking it could throw an error on an overqualified update if the record is updated during the transaction. I was reading in the C.J. Date book on optimistic locking and he makes a suggestion of retrying the request.

I was wondering if this type of mechanism comes out-of-the-box with WebSphere or could I code something where I catch the exception and retry with a new overqualified update. Although, in the latter I wonder how the container would view the transaction (i.e., stop the old/failed one and start a new one, or other?)

Basically, I am trying to mitigate the risk of several exceptions occuring because you can't update, but then I guess you would have to be concerned about how many retries do you attempt before you give up. Thoughts?

TIA!



Yes, WebSphere handles overqualified updates out of the box. The remainder of Chapter 28 (the part not in the excerpt) actually deals with that. Retry is not handled -- that must be done by your application code. I do cover the subject in general terms (when I discuss the Command pattern) in Chapter 30, I believe.

Kyle
[ May 14, 2004: Message edited by: Kyle Brown ]
 
Anselm Paulinus
Ranch Hand
Posts: 390
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just wondering if a modified form of Observer pattern could be useful here. This is a case where two different clients serve as the observers while the value object is the subject. I do not think one would experience more network traffic than currently been experienced.
 
Kyle Brown
author
Ranch Hand
Posts: 3892
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Anselm Paulinus:
Just wondering if a modified form of Observer pattern could be useful here. This is a case where two different clients serve as the observers while the value object is the subject. I do not think one would experience more network traffic than currently been experienced.


In general, Observer is very difficult to make work in distributed environments due to the nature of the protocols. This might work if your application only ever ran in one application server instance, but this is generally not a good assumption -- you should always plan for clustering.

Kyle
 
Anselm Paulinus
Ranch Hand
Posts: 390
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Mr. Kyle Brown
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!