title: Websphere Server threads getting hung
body: <p>We have an application where we use an H2 embedded database to store the data. We have a synchronized write method which does DB inserts. Since the H2 DB is a small Java embedded DB, we use "synchronized" on the write method to handle the transaction management in embedded DB rather than in DB.</p>
  
  <p>But during heavy load, we could see that the write thread is getting hung. We are not sure  for which resource, this thread is getting hung.</p>
  
  <p>Please look at this snippet of code:</p>
  
  <pre><code>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;
    }
  }
  </code></pre>
  
  <p>We have multiple write methods which can access this DB. From the code we could see that the code is straightforward. But we are not sure where the resource is locked.</p>
  
  <p>Another problem is in the thread dump in the (Websphere) system.out, we could see the thread stacktrace as below.</p>
  
  <pre><code>[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)
  </code></pre>
  
  <p>In the above stacktrace, I need to know the reason why I am getting "Unknown Source" in the stack trace. Those jars are available in the class path and we also have the H2.jar in the classpath. We are not sure why, if the thread gets in hung in H2, we are not able to get the thread stacktrace.</p>
  
  <p>If not, I also need to know why the thread stack trace is showing "Unknown Source".</p>
  
  <p>Appreciate your help.</p>
  
  <p>Thanks in advance.</p>