title: Tomcat hangs in Spring Boot application
body: <p>I am working in a web application which using <strong>Spring boot,SQL server activiti,websocket and angularJS</strong>.</p>
  
  <p>Sometimes, this application UI hangs ( not always ). I suspect this is because of connection pooling. This application is using <strong>default datasource properties</strong> from Spring Boot. There is <strong>no connection pool library</strong> used until now.</p>
  
  <p><strong>Questions:</strong></p>
  
  <p>I suspect <strong>thread is waiting</strong> for DB connection, so...</p>
  
  <p>1) Increasing Maximum active connections will solve this problem?</p>
  
  <p>2) Using connection pools libraries will solve this problem?</p>
  
  <p>I attached <strong>thread dump</strong> below....</p>
  
  <pre><code>    MessageBrokerSockJS-3 prio=10 tid=0x00007f8c1c3d1800 nid=0xebd in  Object.wait() [0x00007f8c609c2000]
     java.lang.Thread.State: WAITING (on object monitor)
      at java.lang.Object.wait(Native Method)
      - waiting on &lt;0x00000007095cd788&gt; (a org.apache.commons.pool.impl.GenericObjectPool$Latch)
      at java.lang.Object.wait(Object.java:503)
      at org.apache.commons.pool.impl.GenericObjectPool.borrowObject(GenericObjectPool.java:1118)
      - locked &lt;0x00000007095cd788&gt; (a org.apache.commons.pool.impl.GenericObjectPool$Latch)
      at org.apache.commons.dbcp.PoolingDataSource.getConnection(PoolingDataSource.java:106)
      at org.apache.commons.dbcp.BasicDataSource.getConnection(BasicDataSource.java:1044)
      at org.springframework.jdbc.datasource.DataSourceTransactionManager.doBegin(DataSourceTransactionManager.java:204)
      at org.springframework.transaction.support.AbstractPlatformTransactionManager.getTransaction(AbstractPlatformTransactionManager.java:373)
      at org.springframework.transaction.support.TransactionTemplate.execute(TransactionTemplate.java:130)
      at org.activiti.spring.SpringTransactionInterceptor.execute(SpringTransactionInterceptor.java:45)
      at org.activiti.engine.impl.interceptor.LogInterceptor.execute(LogInterceptor.java:31)
      at org.activiti.engine.impl.cfg.CommandExecutorImpl.execute(CommandExecutorImpl.java:40)
      at org.activiti.engine.impl.cfg.CommandExecutorImpl.execute(CommandExecutorImpl.java:35)
      at org.activiti.engine.impl.AbstractQuery.list(AbstractQuery.java:138)
      at com.rbccm.workflow.db.dao.ActivitiHelper.getTasksByTaskLocalVar(ActivitiHelper.java:305)
      at com.rbccm.workflow.db.dao.ActivitiHelper$$FastClassBySpringCGLIB$$86c44488.invoke(&lt;generated&gt;)
      at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204)
      at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:649)
      at com.rbccm.workflow.db.dao.ActivitiHelper$$EnhancerBySpringCGLIB$$71f2d0fd.getTasksByTaskLocalVar(&lt;generated&gt;)
      at com.rbccm.workflow.manager.ActivitiManager.getTasksByTaskLocalVar(ActivitiManager.java:861)
      at com.rbccm.workflow.manager.ActivitiManager$$FastClassBySpringCGLIB$$f69deb1c.invoke(&lt;generated&gt;)
      at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204)
      at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:649)
      at com.rbccm.workflow.manager.ActivitiManager$$EnhancerBySpringCGLIB$$31946c7.getTasksByTaskLocalVar(&lt;generated&gt;)
      at com.rbccm.workflow.manager.AlfrescoManager.unlockTaskForClosedDocument(AlfrescoManager.java:37)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:606)
      at org.springframework.scheduling.support.ScheduledMethodRunnable.run(ScheduledMethodRunnable.java:65)
      at org.springframework.scheduling.support.DelegatingErrorHandlingRunnable.run(DelegatingErrorHandlingRunnable.java:54)
      at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
      at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:304)
      at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:178)
      at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293)
      at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
      at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
      at java.lang.Thread.run(Thread.java:745)
  
  "MessageBrokerSockJS-2" prio=10 tid=0x00007f8c1e484000 nid=0xebc waiting on condition [0x00007f8c60ac4000]
     java.lang.Thread.State: WAITING (parking)
      at sun.misc.Unsafe.park(Native Method)
      - parking to wait for  &lt;0x00000007041a9590&gt; (a java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject)
      at java.util.concurrent.locks.LockSupport.park(LockSupport.java:186)
      at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await(AbstractQueuedSynchronizer.java:2043)
      at java.util.concurrent.ScheduledThreadPoolExecutor$DelayedWorkQueue.take(ScheduledThreadPoolExecutor.java:1085)
      at java.util.concurrent.ScheduledThreadPoolExecutor$DelayedWorkQueue.take(ScheduledThreadPoolExecutor.java:807)
      at java.util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:1068)
      at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1130)
      at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
      at java.lang.Thread.run(Thread.java:745)
  
  "MessageBrokerSockJS-1" prio=10 tid=0x00007f8c1c9c6000 nid=0xeb6 in Object.wait() [0x00007f8c60bc4000]
     java.lang.Thread.State: WAITING (on object monitor)
      at java.lang.Object.wait(Native Method)
      - waiting on &lt;0x00000007095d02d8&gt; (a org.apache.commons.pool.impl.GenericObjectPool$Latch)
      at java.lang.Object.wait(Object.java:503)
      at org.apache.commons.pool.impl.GenericObjectPool.borrowObject(GenericObjectPool.java:1118)
      - locked &lt;0x00000007095d02d8&gt; (a org.apache.commons.pool.impl.GenericObjectPool$Latch)
      at org.apache.commons.dbcp.PoolingDataSource.getConnection(PoolingDataSource.java:106)
      at org.apache.commons.dbcp.BasicDataSource.getConnection(BasicDataSource.java:1044)
      at org.springframework.jdbc.datasource.DataSourceUtils.doGetConnection(DataSourceUtils.java:111)
      at org.springframework.jdbc.datasource.DataSourceUtils.getConnection(DataSourceUtils.java:77)
      at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:391)
      at org.springframework.jdbc.core.JdbcTemplate.update(JdbcTemplate.java:549)
      at com.rbccm.workflow.db.dao.ChaserDao.clearOldChasers(ChaserDao.java:111)
      at com.rbccm.workflow.db.dao.ChaserDao$$FastClassBySpringCGLIB$$fa074cd3.invoke(&lt;generated&gt;)
      at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204)
      at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:717)
      at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157)
      at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:136)
      at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
      at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:653)
      at com.rbccm.workflow.db.dao.ChaserDao$$EnhancerBySpringCGLIB$$48b6e5eb.clearOldChasers(&lt;generated&gt;)
      at com.rbccm.workflow.sendchaser.SendChaser.checkChasers(SendChaser.java:72)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:606)
      at org.springframework.scheduling.support.ScheduledMethodRunnable.run(ScheduledMethodRunnable.java:65)
      at org.springframework.scheduling.support.DelegatingErrorHandlingRunnable.run(DelegatingErrorHandlingRunnable.java:54)
      at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
      at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:304)
      at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:178)
      at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293)
      at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
      at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
      at java.lang.Thread.run(Thread.java:745)
  
  "container-0" prio=10 tid=0x00007f8c1c930000 nid=0xeb5 waiting on condition [0x00007f8c60cc6000]
     java.lang.Thread.State: TIMED_WAITING (sleeping)
      at java.lang.Thread.sleep(Native Method)
      at org.apache.catalina.core.StandardServer.await(StandardServer.java:407)
      at org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainer$1.run(TomcatEmbeddedServletContainer.java:146)
  
  "ContainerBackgroundProcessor[StandardEngine[Tomcat].StandardHost[localhost].StandardContext[]]" daemon prio=10 tid=0x00007f8c149fa000 nid=0xeb4 waiting on condition [0x00007f8c60dc7000]
     java.lang.Thread.State: TIMED_WAITING (sleeping)
      at java.lang.Thread.sleep(Native Method)
      at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.run(ContainerBase.java:1345)
      at java.lang.Thread.run(Thread.java:745)
  </code></pre>