Aquiring datasource connections in JBoss EAP 6
Issue
- The following code snippet is from SLSB. It has found that it takes a considerable amount of time to retrieve a database connection (150ms).
- Why this is happening? It need to speed this up considerably. How can to speed this up?
@Stateless
public class TestDAO implements TestDAOLocal{
@Resource(mappedName = "java:/TEST_DS")
private DataSource testDs;
private String insertSQL = "insert into test_table (a, b, c, d, e, f) values (?, ?, ?, ?, ?, ?)";
private static Logger logger = Logger.getLogger(TestDAO.class);
@Override
public void add(TestLog testlog) {
logger.debug("Add method entered");
Connection conn = null;
try {
//HERE IS WHERE THE SLOWDOWN IS
conn = testDs.getConnection();
logger.debug("got a connection");
PreparedStatement pstmt = conn.prepareStatement(insertSQL);
pstmt.setString(1,testlog.getA());
pstmt.setDate(2, new Date(new java.util.Date().getB()));
pstmt.setString(3, testlog.getC());
pstmt.setString(4, testlog.getD());
pstmt.setLong(5, 100);
pstmt.setString(6, testlog.getF());
long queryTimeinMillis = 0;
if (logger.isDebugEnabled()) {
queryTimeinMillis = System.currentTimeMillis();
}
logger.debug("calling insert");
pstmt.executeUpdate();
if (logger.isDebugEnabled()) {
queryTimeinMillis = (System.currentTimeMillis() - queryTimeinMillis);
logger.debug("Request Message recorded in " + queryTimeinMillis + "ms");
}
}
catch(Exception e){
try {
conn.close();
} catch (Exception se) {
//do nothing
}
logger.warn(StringUtil.getStackTraceString(e));
}
}
Environment
- Red Hat JBoss Enterprise Application Platform (EAP)
- 6.1.1
Subscriber exclusive content
A Red Hat subscription provides unlimited access to our knowledgebase of over 48,000 articles and solutions.
Welcome! Check out the Getting Started with Red Hat page for quick tours and guides for common tasks.
