snippetjournal

– notes, snippet codes, and my journal

“pessimistic locking” and “optimistic locking.”

leave a comment »

Pessimistic Locking :
Pessimistic locking is when a transaction occurs, and then the resource is locked from the time it is first accessed. Until the transaction finished another transaction cant accessed the resources.

Optimistic Locking :
Optimistic locking applied a fail safe way. The state of resource is locked as soon the transaction occurs. But when another transaction occurs and attempting to accessed the resource it will result a delayed. Until the first accessed resources finished and unlock the resources.
The lock exists until the transaction committed or rolled back. If the resource is released. It will be compare the state which has been changed to the state when the time its locked. If the state differ it will rolled back the resource.

It compare the state of resource instead compare the changed data.
Some article defined a state as a version.

http://docs.jboss.org/jbossas/docs/Server_Configuration_Guide/4/html/TransactionJTA_Overview-Pessimistic_and_optimistic_locking.html

Written by snippetjournal

September 29, 2012 at 2:02 pm

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: