Blocking Behavior with Threads and lost updates

by leeand00   Last Updated July 31, 2018 19:05 PM

I have three examples of what I think to be kind of the same thing:

In an SQL database, using either:

  • Optimistic Locking
  • Pessimistic Locking

..can prevent a database thread from losing an update from a separate database thread.


Likewise, using the synchronized keyword in Java can prevent a global session or static variable from losing an update by ensuring that only one Java thread at a time can access the variable to change it's value.


And finally a network shared physical resource, such as a printer can receive multiple requests to print a job, but can really only print one job a time. However, when more than one job is requested, the print queue adds the job to the list of existing jobs waiting to be processed.


Now my question is are all of these examples of a similar pattern in computer programming, or are they different? And if so what are this/these pattern(s) called?

I've seen that the SQL example is refered to as "avoiding the lost update", and the Java synchronized example is more along the lines of "blocking" or "locking" or "semiphore"

The printer example seems like it's something else since the other incoming jobs are placed into a queue waiting for the opportunity to use the resouce.



Related Questions


Running two pieces of code simultaneously?

Updated March 15, 2016 08:02 AM


Get service data of future iterations

Updated March 10, 2017 03:05 AM

Parallel Image Processing Best Practices

Updated December 17, 2017 05:05 AM