From: <tr...@hy...> - 2009-04-24 21:55:35
|
Author: trader Date: 2009-04-24 14:55:31 -0700 (Fri, 24 Apr 2009) New Revision: 13056 URL: http://svn.hyperic.org/?view=rev&root=Hyperic+HQ&revision=13056 Modified: trunk/src/org/hyperic/util/jdbc/IDGeneratorFactory.java Log: Fix synchronization Modified: trunk/src/org/hyperic/util/jdbc/IDGeneratorFactory.java =================================================================== --- trunk/src/org/hyperic/util/jdbc/IDGeneratorFactory.java 2009-04-24 21:38:15 UTC (rev 13055) +++ trunk/src/org/hyperic/util/jdbc/IDGeneratorFactory.java 2009-04-24 21:55:31 UTC (rev 13056) @@ -70,26 +70,18 @@ NamingException, SequenceRetrievalException, SQLException { - if(!generatorMap.containsKey(sequenceName)) { - synchronized(generatorMap) { - createGenerator(ctx, sequenceName, dsName); + + IDGenerator result = null; + synchronized (generatorMap) { + result = (IDGenerator) generatorMap.get(sequenceName); + + if (result == null) { + result = new IDGenerator(ctx, sequenceName, + DEFAULT_INTERVAL, dsName); + generatorMap.put(sequenceName, result); } } - return (IDGenerator)generatorMap.get(sequenceName); + + return result; } - - private static synchronized void createGenerator(String ctx, String seq, - String dsName) - throws ConfigPropertyException, - NamingException, - SequenceRetrievalException, - SQLException { - if (!generatorMap.containsKey(seq)) { - IDGenerator aGenerator = new IDGenerator(ctx, - seq, - DEFAULT_INTERVAL, - dsName); - generatorMap.put(seq, aGenerator); - } - } } |