[jboss-cvs] JBossAS SVN: r109446 - projects/jboss-jca/branches/performance/pojos/src/main/java/org/jboss/jca/performance/pojos.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Wed Nov 24 09:23:49 EST 2010


Author: jesper.pedersen
Date: 2010-11-24 09:23:48 -0500 (Wed, 24 Nov 2010)
New Revision: 109446

Modified:
   projects/jboss-jca/branches/performance/pojos/src/main/java/org/jboss/jca/performance/pojos/DatabaseTester.java
Log:
Do JNDI lookup only once to eliminate naming noise

Modified: projects/jboss-jca/branches/performance/pojos/src/main/java/org/jboss/jca/performance/pojos/DatabaseTester.java
===================================================================
--- projects/jboss-jca/branches/performance/pojos/src/main/java/org/jboss/jca/performance/pojos/DatabaseTester.java	2010-11-24 14:22:38 UTC (rev 109445)
+++ projects/jboss-jca/branches/performance/pojos/src/main/java/org/jboss/jca/performance/pojos/DatabaseTester.java	2010-11-24 14:23:48 UTC (rev 109446)
@@ -136,6 +136,10 @@
       long start = 0;
       long end = 0;
 
+      Context context = new InitialContext();
+      UserTransaction userTransaction = (UserTransaction)context.lookup(JNDI_USER_TRANSACTION);
+      DataSource dataSource = (DataSource)context.lookup(dbJndiName);
+
       if (multiThreaded)
       {
          try
@@ -153,7 +157,7 @@
             start = System.currentTimeMillis();
             for (int counter = 0; counter < iterations; counter++)
             {
-               Test t = new Test(dbJndiName, sqls, cdl);
+               Test t = new Test(dataSource, userTransaction, sqls, cdl);
                threadPoolExecutor.submit(t);
             }
             cdl.await();
@@ -169,7 +173,7 @@
       else
       {
          start = System.currentTimeMillis();
-         Test t = new Test(dbJndiName, sqls);
+         Test t = new Test(dataSource, userTransaction, sqls);
          for (int counter = 0; counter < iterations; counter++)
          {
             t.run();
@@ -184,6 +188,8 @@
 
       log.info("Took: " + elapsed + " ms");
       log.info("Unit of work/ms: " + (iterations / (double)elapsed));
+
+      context.close();      
    }
 
    /**
@@ -191,40 +197,38 @@
     */
    private static class Test implements Runnable
    {
-      private String dbJndiName;
+      private DataSource dataSource;
+      private UserTransaction userTransaction;
       private List<String> sqls;
       private CountDownLatch cdl;
 
-      Test(String dbJndiName, List<String> sqls)
+      Test(DataSource db, UserTransaction ut, List<String> sqls)
       {
-         this(dbJndiName, sqls, null);
+         this(db, ut, sqls, null);
       }
 
-      Test(String dbJndiName, List<String> sqls, CountDownLatch cdl)
+      Test(DataSource db, UserTransaction ut, List<String> sqls, CountDownLatch cdl)
       {
-         this.dbJndiName = dbJndiName;
+         this.dataSource = db;
+         this.userTransaction = ut;
          this.sqls = sqls;
          this.cdl = cdl;
       }
 
       public void run()
       {
-         if (dbJndiName == null || dbJndiName.trim().equals(""))
-            throw new IllegalArgumentException("No datasource JNDI name defined");
+         if (dataSource == null)
+            throw new IllegalArgumentException("No datasource defined");
 
-         Context context = null;
-         UserTransaction userTransaction = null;
-         DataSource dataSource = null;
+         if (userTransaction == null)
+            throw new IllegalArgumentException("UserTransaction is null");
+
          Connection connection = null;
 
          try
          {
-            context = new InitialContext();
-
-            userTransaction = (UserTransaction)context.lookup(JNDI_USER_TRANSACTION);
             userTransaction.begin();
 
-            dataSource = (DataSource)context.lookup(dbJndiName);
             connection = dataSource.getConnection();
 
             PreparedStatement ps = null;
@@ -267,8 +271,6 @@
             }
             
             userTransaction.commit();
-
-            context.close();
          }
          catch (Throwable t)
          {



More information about the jboss-cvs-commits mailing list