Skip to content

Commit

Permalink
Avoid JNDI lookups which block on System properties
Browse files Browse the repository at this point in the history
  • Loading branch information
timf committed Feb 21, 2013
1 parent 9a84102 commit ec021bf
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion src/main/java/org/dasein/persist/Transaction.java
Expand Up @@ -80,6 +80,10 @@ public class Transaction {
* 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);

Expand Down Expand Up @@ -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() ) {
Expand Down

0 comments on commit ec021bf

Please sign in to comment.