我们有一个应用程序,我们使用H2嵌入式数据库存储数据。我们有一个同步写入方法,可以插入数据库。由于H2 DB是一个小型Java嵌入式数据库,因此我们在写入方法上使用“synchronized”来处理嵌入式数据库中的事务管理,而不是在数据库中。Websphere服务器线程挂起
但是在重载时,我们可以看到写入线程正在挂起。我们不确定哪个资源,这个线程正在被挂起。
请看看这个代码片段:
public synchronized int write(IEvent event) {
String methodName = "write";
Connection conn = null;
PreparedStatement updtStmt = null;
Statement stmt = null;
ResultSet rSet = null;
int status = 0;
try {
dbConnect.checkDBSizeExceed();
conn = dbConnect.getConnection();
updtStmt = conn.prepareStatement(insertQuery);
updtStmt.setString(1, (String) event.getAttributeValue());
......
updtStmt.setString(30, (String) event.getAttributeValue());
updtStmt.setBoolean(31, false);
status = updtStmt.executeUpdate();
}catch(SQLException ex){
logger.log(methodName,logger.print(ex),Logger.ERROR);
} catch(Exception ex){
logger.log(methodName,logger.print(ex),Logger.ERROR);
} finally {
try {
if (updtStmt != null)
updtStmt.close();
if (conn != null)
conn.close();
}catch(SQLException ex) {
logger.log(methodName,logger.print(ex),Logger.ERROR);
return status;
}
return status;
}
}
我们有哪些可以访问此DB多次写入的方法。从代码中我们可以看到代码很简单。但我们不确定资源的锁定位置。
另一个问题是在(Websphere)system.out中的线程转储中,我们可以看到线程堆栈跟踪如下。
[6/15/12 3:13:38:225 EDT] 00000032 ThreadMonitor W WSVR0605W: Thread "WebContainer : 3" (00000066) has been active for 632062 milliseconds and may be hung. There is/are 2
thread(s) in total in the server that may be hung.
at com.xxxx.eaws.di.agent.handlers.AuditEmbeddedDBHandler.store(Unknown Source)
at com.xxxx.eaws.di.agent.eventlogger.2LoggerImpl.logEvent(Unknown Source)
at com.xxxx.eecs.eventlogger.EventLoggerAdapter.logAuditEvent(EventLoggerAdapter.java:682)
at com.xxxx.eecs.eventlogger.EventLoggerAdapter.logEvent(EventLoggerAdapter.java:320)
at com.xxxx.eecs.eventlogger.EventLogger.logEventInternal(EventLogger.java:330)
at com.xxxx.eecs.eventlogger.EventLogger.logEvent(EventLogger.java:283)
at com.ibm.wps.auth.impl.ImplicitLoginFilterChainImpl.login(ImplicitLoginFilterChainImpl.java:55)
at com.ibm.wps.auth.impl.AuthenticationFilterChainHandlerImpl.invokeImplicitLoginFilterChain(AuthenticationFilterChainHandlerImpl.java:393)
at com.ibm.wps.auth.impl.InitialAuthenticationHandlerImpl.checkAuthentication(InitialAuthenticationHandlerImpl.java:204)
at com.ibm.wps.state.phases.PhaseManagerImpl.callInitialAuthenticationHandler(PhaseManagerImpl.java:240)
在上面的堆栈跟踪,我需要知道为什么我在堆栈跟踪得到“未知源”的原因。这些罐子在类路径中可用,我们在类路径中也有H2.jar。我们不确定为什么,如果线程挂在H2中,我们无法获得线程堆栈跟踪。
如果不是,我也需要知道为什么线程堆栈跟踪显示“未知源”。
感谢你的帮助。
在此先感谢。
您显示的堆栈跟踪不在您所显示的write()方法中。你也可以尝试强制一个javacore来查看你的所有线程在哪里。 – dbreaux