reset password
Author Message
calstatelaboy
Posts: 52
Posted 14:42 Aug 10, 2009 |

Java synchronised and sleep wastage of efficiency.

 I think java atomic provide solution for this

and all data type in database should atomic to avoid unnecessary lock and synchronised whenever it is necessary.

http://java.sun.com/j2se/1.5.0/docs/api/java/util/concurrent/atomic/package-summary.html

cysun
Posts: 2935
Posted 16:56 Aug 10, 2009 |

You are right that using Java atomic types are more efficient than guarding shared data with synchronized methods, but note that all the atomic types are simple types like boolean, int, references, and so on, and making these simple types atomic in databases does not solve the database synchronization problem. For example, considering a simple table with two columns (id integer, name varchar). Making integer and varchar atomic does not means updating a row, which consists of an integer and a varchar, would be atomic. Furthermore, the Atomicity property of DB transactions means that a whole transaction, which may consist of multiple statements and updates of many rows, should be atomic - and that cannot be done easily by simply using atomic types.