Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Avoid JNDI lookups which block on System properties

  • Loading branch information...
commit ec021bf650a05bade7bba5f6d623700d9352a52c 1 parent 9a84102
Tim Freeman authored

Showing 1 changed file with 17 additions and 1 deletion. Show diff stats Hide diff stats

  1. +17 1 src/main/java/org/dasein/persist/Transaction.java
18 src/main/java/org/dasein/persist/Transaction.java
@@ -80,6 +80,10 @@
80 80 * Cache of Execution objects to minimize dynamically created SQL
81 81 */
82 82 static private final Map<String,Stack<Execution>> eventCache = new ConcurrentHashMap<String, Stack<Execution>>(8, 0.9f, 1);
  83 + /**
  84 + * Cache of DataSource instances. JNDI blocks on System properties.
  85 + */
  86 + static private final Map<String,DataSource> dsCache = new ConcurrentHashMap<String, DataSource>(8, 0.9f, 1);
83 87
84 88 static private final AtomicBoolean maidLaunched = new AtomicBoolean(false);
85 89
@@ -552,8 +556,20 @@ private synchronized void open(Execution event, String dsn) throws SQLException,
552 556 if( dsn == null ) {
553 557 dsn = event.getDataSource();
554 558 }
  559 + if (dsn == null) {
  560 + throw new PersistenceException("No data source name");
  561 + }
555 562 state = "LOOKING UP";
556   - ds = (DataSource)ctx.lookup(dsn);
  563 + ds = dsCache.get(dsn);
  564 + if (ds == null) {
  565 + ds = (DataSource)ctx.lookup(dsn);
  566 + if (ds != null) {
  567 + dsCache.put(dsn, ds);
  568 + }
  569 + }
  570 + if (ds == null) {
  571 + throw new PersistenceException("Could not find data source: " + dsn);
  572 + }
557 573 conn = ds.getConnection();
558 574 openTime = System.currentTimeMillis();
559 575 if( logger.isDebugEnabled() ) {

0 comments on commit ec021bf

Please sign in to comment.
Something went wrong with that request. Please try again.