Browse files

Avoid JNDI lookups which block on System properties

  • Loading branch information...
1 parent 9a84102 commit ec021bf650a05bade7bba5f6d623700d9352a52c @timf committed Feb 21, 2013
Showing with 17 additions and 1 deletion.
  1. +17 −1 src/main/java/org/dasein/persist/Transaction.java
View
18 src/main/java/org/dasein/persist/Transaction.java
@@ -80,6 +80,10 @@
* Cache of Execution objects to minimize dynamically created SQL
*/
static private final Map<String,Stack<Execution>> eventCache = new ConcurrentHashMap<String, Stack<Execution>>(8, 0.9f, 1);
+ /**
+ * Cache of DataSource instances. JNDI blocks on System properties.
+ */
+ static private final Map<String,DataSource> dsCache = new ConcurrentHashMap<String, DataSource>(8, 0.9f, 1);
static private final AtomicBoolean maidLaunched = new AtomicBoolean(false);
@@ -552,8 +556,20 @@ private synchronized void open(Execution event, String dsn) throws SQLException,
if( dsn == null ) {
dsn = event.getDataSource();
}
+ if (dsn == null) {
+ throw new PersistenceException("No data source name");
+ }
state = "LOOKING UP";
- ds = (DataSource)ctx.lookup(dsn);
+ ds = dsCache.get(dsn);
+ if (ds == null) {
+ ds = (DataSource)ctx.lookup(dsn);
+ if (ds != null) {
+ dsCache.put(dsn, ds);
+ }
+ }
+ if (ds == null) {
+ throw new PersistenceException("Could not find data source: " + dsn);
+ }
conn = ds.getConnection();
openTime = System.currentTimeMillis();
if( logger.isDebugEnabled() ) {

0 comments on commit ec021bf

Please sign in to comment.