java - Spot the concurrency issue -
One of our heritage has a database connection leak in one application, and I'm tracking this little gem. With debugging, I can see the same logical connection being returned for more than one thread (no good!). But I am struggling to understand why this is happening
We are using the setup ojdbc6 driver on the weblogic data source with connection pooling.
The code that creates a problem Updated fixes You singleton / P> Public stable MyDummyDaoUtil getInstance () {return example; Use the double check locking system Note: Do not forget to close the connection.
Public category MyDummyDaoUtil {// Note: This is a public area in a singleton (though a constant The area is not ...) conn public connection; Private MaidamidouUutil () {} Public Static MyMediaOutilIstance () (if (instance == blank) {instance = New MyDummyDaoUtil ();} Return Example;} Private Datacource throws the GetDataSource (Last String DSNName) Naming Explanation {return ServiceLocator.getInstance GetDataSource (dsName);} Get the public static connection throws naming upstation (last string source) {return MyDummyDaoUtil.getInstance (). GetDBConnection (source);} Private connection getDBConnection (last String source) NamingException throws / is the same logical connection generated by the data source or something else? Conn = getDataSource (Source) .getConnection (); conn.setAutoCommit (wrong); Return Canon;}}
public class MyDummyDaoUtil {Private MyDummyDaoUtil () {} Public Fixed MyDummyDaoUtil getInstance () {if (example == Faucet) {Example = New MyDummyDaoUtil ();} Return Example;} Private Datacours GetDataSource (Last String DSNName) Nomination Expression Enkta is {return ServiceLocator.getInstance (). GetDataSource (dsName); } Public static connection throws naming upstation (Connection MyDummyDaoUtil.getInstance) to get connection (final string source). GetDBConnection (source); } Private connection throws the getDBConnection (final string source) NamingException {connection conn = getDataSource (source) .getConnection (); Conn.setAutoCommit (wrong); Return canon; The wrong lazy initialization of the example
getInstance () synchronize method
public Static synchronized MyDummyDaoUtil getInstance () {if (example == zero) {example = New MyDummyDaoUtil (); } Return Example; }
public static MyDummyDaoUtil getInstance () { If (example == faucet) {synchronize (MyDummyDaoUtil.class) {if (example == blank) {example = new MyDummyDaoUtil (); }}} Return example;
Comments
Post a Comment