Friday, November 12, 2010

IODH

Zero Syncronization issues ! Simple ! Clean !

public class Something {
private Something() {
}

private static class LazyHolder {
private static final Something INSTANCE = new Something();
}

public static final Something getInstance() {
return LazyHolder.INSTANCE;
}
}

OR

static Singleton instance;

public static synchronized Singleton getInstance() {
if (instance == null)
instance == new Singleton();
return instance;
}

Why it is called LAZY ? : IODH utilizes lazy class initialization. The JVM won't execute a class's static initializer until you actually touch something in the class. This applies to static nested classes, too...

Read more on : wikipedia , Double-checked_locking

Wednesday, November 3, 2010

Transaction isolation levels and 3 phenomena..


dirty read
A transaction reads data written by a concurrent uncommitted transaction.
nonrepeatable read
A transaction re-reads data it has previously read and finds that data has been modified by another transaction (that committed since the initial read).
phantom read
A transaction re-executes a query returning a set of rows that satisfy a search condition and finds that the set of rows satisfying the condition has changed due to another recently-committed transaction.
Isolation Level Dirty Read Nonrepeatable Read Phantom Read
Read uncommitted Possible Possible Possible
Read committed Not possible Possible Possible
Repeatable read Not possible Not possible Possible
Serializable Not possible Not possible Not possible

see also : http://dev.mysql.com/doc/refman/5.0/en/innodb-locking-reads.html Similar things to Java's ReentrantReadWriteLock