1 64 65 package com.jcorporate.expresso.core.db.tests; 66 67 import com.jcorporate.expresso.core.db.DBConnection; 68 import com.jcorporate.expresso.core.db.DBConnectionPool; 69 import com.jcorporate.expresso.core.db.DBException; 70 import com.jcorporate.expresso.core.db.exception.PoolFullException; 71 import com.jcorporate.expresso.services.test.TestSystemInitializer; 72 73 79 80 public class DBConnectionPoolStressThread extends java.lang.Thread { 81 protected String errorMessage = null; 82 int numPoolFulls = 0; 83 84 85 public DBConnectionPoolStressThread() { 86 } 87 88 public DBConnectionPoolStressThread(String threadName) { 89 super(threadName); 90 } 91 92 public String getErrors() { 93 return errorMessage; 94 } 95 96 public int getNumPoolFulls() { 97 return numPoolFulls; 98 } 99 100 public void run() { 101 try { 102 DBConnectionPool myPool = DBConnectionPool.getInstance(TestSystemInitializer.getTestContext()); 103 104 for (int i = 0; i < DBConnectionPoolTest.NUM_ITERATIONS; i++) { 105 if (!this.isInterrupted()) { 106 try { 107 DBConnection oneConnection = myPool.getConnection(); 108 if (oneConnection == null) { 109 errorMessage = "Received null connection from the connection pool."; 110 } 111 synchronized (this) { 112 try { 113 sleep(new java.util.Random ().nextInt(50)); 114 } catch (InterruptedException ex) { 115 } 116 } 117 oneConnection.release(); 118 } catch (PoolFullException pfe) { 120 numPoolFulls++; 121 } 123 } else { 124 numPoolFulls++; 125 break; 126 } 127 } 128 } catch (DBException ex) { 129 ex.printStackTrace(); 130 errorMessage = ex.getMessage(); 131 return; 132 } 133 } 134 } | Popular Tags |