New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and
privacy statement. We’ll occasionally send you account related emails.
Already on GitHub?
Sign in
to your account
Closed
kenkoooo opened this issue
Jun 26, 2018
· 2 comments
Comments
2018/06/25 07:58:56.690 ERROR - [com.kenkoooo.atcoder.common.ScheduledExecutorServiceExtension$TryAndDieScheduledExecutorService$$anonfun$$nestedInanonfun$tryAtFixedDelay$1$1] Catching
java.sql.SQLException: Cannot get a connection, pool error Timeout waiting for idle object
at org.apache.commons.dbcp2.PoolingDataSource.getConnection(PoolingDataSource.java:142) ~[atcoder-problems-assembly-0.1.jar:0.1]
at scalikejdbc.Commons2ConnectionPool.borrow(Commons2ConnectionPool.scala:48) ~[atcoder-problems-assembly-0.1.jar:0.1]
at scalikejdbc.DB$.readOnly(DB.scala:174) ~[atcoder-problems-assembly-0.1.jar:0.1]
at com.kenkoooo.atcoder.db.SqlClient.executeAndLoadSubmission(SqlClient.scala:61) ~[atcoder-problems-assembly-0.1.jar:0.1]
at com.kenkoooo.atcoder.db.SubmissionIterator.reload(SqlClient.scala:475) ~[atcoder-problems-assembly-0.1.jar:0.1]
at com.kenkoooo.atcoder.db.SubmissionIterator.hasNext(SqlClient.scala:461) ~[atcoder-problems-assembly-0.1.jar:0.1]
at scala.collection.Iterator.foreach(Iterator.scala:929) ~[atcoder-problems-assembly-0.1.jar:0.1]
at scala.collection.Iterator.foreach$(Iterator.scala:929) ~[atcoder-problems-assembly-0.1.jar:0.1]
at com.kenkoooo.atcoder.db.SubmissionIterator.foreach(SqlClient.scala:452) ~[atcoder-problems-assembly-0.1.jar:0.1]
at scala.collection.TraversableOnce.size(TraversableOnce.scala:107) ~[atcoder-problems-assembly-0.1.jar:0.1]
at scala.collection.TraversableOnce.size$(TraversableOnce.scala:105) ~[atcoder-problems-assembly-0.1.jar:0.1]
at com.kenkoooo.atcoder.db.SubmissionIterator.size(SqlClient.scala:452) ~[atcoder-problems-assembly-0.1.jar:0.1]
at com.kenkoooo.atcoder.runner.NewerSubmissionScrapingRunner.scrapeOnePage(NewerSubmissionScrapingRunner.scala:30) ~[atcoder-problems-assembly-0.1.jar:0.1]
at com.kenkoooo.atcoder.Main$.$anonfun$main$1(Main.scala:54) ~[atcoder-problems-assembly-0.1.jar:0.1]
at scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:12) ~[atcoder-problems-assembly-0.1.jar:0.1]
at scala.util.Try$.apply(Try.scala:209) ~[atcoder-problems-assembly-0.1.jar:0.1]
at com.kenkoooo.atcoder.common.ScheduledExecutorServiceExtension$TryAndDieScheduledExecutorService$.$anonfun$tryAtFixedDelay$1(ScheduledExecutorServiceExtension.scala:30) ~[atcoder-problems-assembly-0.1.jar:0.1]
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) [?:1.8.0_171]
at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:308) [?:1.8.0_171]
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:180) [?:1.8.0_171]
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:294) [?:1.8.0_171]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [?:1.8.0_171]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [?:1.8.0_171]
at java.lang.Thread.run(Thread.java:748) [?:1.8.0_171]
Caused by: java.util.NoSuchElementException: Timeout waiting for idle object
at org.apache.commons.pool2.impl.GenericObjectPool.borrowObject(GenericObjectPool.java:449) ~[atcoder-problems-assembly-0.1.jar:0.1]
at org.apache.commons.pool2.impl.GenericObjectPool.borrowObject(GenericObjectPool.java:363) ~[atcoder-problems-assembly-0.1.jar:0.1]
at org.apache.commons.dbcp2.PoolingDataSource.getConnection(PoolingDataSource.java:134) ~[atcoder-problems-assembly-0.1.jar:0.1]
... 23 more
2018/07/06 15:24:14.359 INFO - [com.kenkoooo.atcoder.runner.NewerSubmissionScrapingRunner] 40 submissions overlapped in arc030
2018/07/06 15:24:14.870 INFO - [com.kenkoooo.atcoder.scraper.SubmissionScraper] scraping https://beta.atcoder.jp/contests/rco-contest-2018-final/submissions?page=44...
2018/07/06 15:24:14.911 INFO - [com.kenkoooo.atcoder.scraper.SubmissionScraper] scraping https://beta.atcoder.jp/contests/ijpc2012pr/submissions?page=1...
2018/07/06 15:24:16.196 INFO - [com.kenkoooo.atcoder.db.SqlClient] loading rated_point_sum
2018/07/06 15:24:16.216 INFO - [com.kenkoooo.atcoder.runner.NewerSubmissionScrapingRunner] 20 submissions overlapped in ijpc2012pr
2018/07/06 15:24:16.726 INFO - [com.kenkoooo.atcoder.scraper.SubmissionScraper] scraping https://beta.atcoder.jp/contests/jag2013summer-day3/submissions?page=1...
2018/07/06 15:24:19.406 INFO - [com.kenkoooo.atcoder.db.SqlClient] loading language_count
2018/07/06 15:24:19.408 INFO - [com.kenkoooo.atcoder.scraper.SubmissionScraper] scraping https://beta.atcoder.jp/contests/ijpc2012pr/submissions?page=2...
2018/07/06 15:24:24.453 ERROR - [com.kenkoooo.atcoder.common.ScheduledExecutorServiceExtension$TryAndDieScheduledExecutorService$$anonfun$$nestedInanonfun$tryAtFixedDelay$1$1] Catching
java.sql.SQLException: Cannot get a connection, pool error Timeout waiting for idle object
at org.apache.commons.dbcp2.PoolingDataSource.getConnection(PoolingDataSource.java:142) ~[atcoder-problems-assembly-0.1.jar:0.1]
at scalikejdbc.Commons2ConnectionPool.borrow(Commons2ConnectionPool.scala:48) ~[atcoder-problems-assembly-0.1.jar:0.1]
at scalikejdbc.DB$.readOnly(DB.scala:174) ~[atcoder-problems-assembly-0.1.jar:0.1]
at com.kenkoooo.atcoder.db.SqlClient.executeAndLoadSubmission(SqlClient.scala:61) ~[atcoder-problems-assembly-0.1.jar:0.1]
at com.kenkoooo.atcoder.db.SubmissionIterator.reload(SqlClient.scala:478) ~[atcoder-problems-assembly-0.1.jar:0.1]
at com.kenkoooo.atcoder.db.SubmissionIterator.hasNext(SqlClient.scala:464) ~[atcoder-problems-assembly-0.1.jar:0.1]
at scala.collection.Iterator.foreach(Iterator.scala:929) ~[atcoder-problems-assembly-0.1.jar:0.1]
at scala.collection.Iterator.foreach$(Iterator.scala:929) ~[atcoder-problems-assembly-0.1.jar:0.1]
at com.kenkoooo.atcoder.db.SubmissionIterator.foreach(SqlClient.scala:455) ~[atcoder-problems-assembly-0.1.jar:0.1]
at scala.collection.TraversableOnce.size(TraversableOnce.scala:107) ~[atcoder-problems-assembly-0.1.jar:0.1]
at scala.collection.TraversableOnce.size$(TraversableOnce.scala:105) ~[atcoder-problems-assembly-0.1.jar:0.1]
at com.kenkoooo.atcoder.db.SubmissionIterator.size(SqlClient.scala:455) ~[atcoder-problems-assembly-0.1.jar:0.1]
at com.kenkoooo.atcoder.runner.NewerSubmissionScrapingRunner.scrapeOnePage(NewerSubmissionScrapingRunner.scala:30) ~[atcoder-problems-assembly-0.1.jar:0.1]
at com.kenkoooo.atcoder.Main$.$anonfun$main$1(Main.scala:54) ~[atcoder-problems-assembly-0.1.jar:0.1]
at scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:12) ~[atcoder-problems-assembly-0.1.jar:0.1]
at scala.util.Try$.apply(Try.scala:209) ~[atcoder-problems-assembly-0.1.jar:0.1]
at com.kenkoooo.atcoder.common.ScheduledExecutorServiceExtension$TryAndDieScheduledExecutorService$.$anonfun$tryAtFixedDelay$1(ScheduledExecutorServiceExtension.scala:30) ~[atcoder-problems-assembly-0.1.jar:0.1]
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) [?:1.8.0_171]
at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:308) [?:1.8.0_171]
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:180) [?:1.8.0_171]
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:294) [?:1.8.0_171]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [?:1.8.0_171]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [?:1.8.0_171]
at java.lang.Thread.run(Thread.java:748) [?:1.8.0_171]
Caused by: java.util.NoSuchElementException: Timeout waiting for idle object
at org.apache.commons.pool2.impl.GenericObjectPool.borrowObject(GenericObjectPool.java:449) ~[atcoder-problems-assembly-0.1.jar:0.1]
at org.apache.commons.pool2.impl.GenericObjectPool.borrowObject(GenericObjectPool.java:363) ~[atcoder-problems-assembly-0.1.jar:0.1]
at org.apache.commons.dbcp2.PoolingDataSource.getConnection(PoolingDataSource.java:134) ~[atcoder-problems-assembly-0.1.jar:0.1]
... 23 more
2018/07/06 15:24:24.863 INFO - [com.kenkoooo.atcoder.db.SqlClient] loading predicted_rating
2018/07/06 15:24:24.864 ERROR - [com.kenkoooo.atcoder.common.ScheduledExecutorServiceExtension$TryAndDieScheduledExecutorService$$anonfun$$nestedInanonfun$tryAtFixedDelay$1$1] Catching
java.sql.SQLException: Cannot get a connection, general error
at org.apache.commons.dbcp2.PoolingDataSource.getConnection(PoolingDataSource.java:146) ~[atcoder-problems-assembly-0.1.jar:0.1]
at scalikejdbc.Commons2ConnectionPool.borrow(Commons2ConnectionPool.scala:48) ~[atcoder-problems-assembly-0.1.jar:0.1]
at scalikejdbc.DB$.readOnly(DB.scala:174) ~[atcoder-problems-assembly-0.1.jar:0.1]
at com.kenkoooo.atcoder.db.SqlClient.loadRecords(SqlClient.scala:353) ~[atcoder-problems-assembly-0.1.jar:0.1]
at com.kenkoooo.atcoder.db.SqlClient.reloadRecords(SqlClient.scala:339) ~[atcoder-problems-assembly-0.1.jar:0.1]
at com.kenkoooo.atcoder.Main$.$anonfun$main$2(Main.scala:58) ~[atcoder-problems-assembly-0.1.jar:0.1]
at scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:12) ~[atcoder-problems-assembly-0.1.jar:0.1]
at scala.util.Try$.apply(Try.scala:209) ~[atcoder-problems-assembly-0.1.jar:0.1]
at com.kenkoooo.atcoder.common.ScheduledExecutorServiceExtension$TryAndDieScheduledExecutorService$.$anonfun$tryAtFixedDelay$1(ScheduledExecutorServiceExtension.scala:30) ~[atcoder-problems-assembly-0.1.jar:0.1]
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) [?:1.8.0_171]
at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:308) [?:1.8.0_171]
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:180) [?:1.8.0_171]
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:294) [?:1.8.0_171]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [?:1.8.0_171]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [?:1.8.0_171]
at java.lang.Thread.run(Thread.java:748) [?:1.8.0_171]
Caused by: java.lang.InterruptedException
at java.util.concurrent.locks.AbstractQueuedSynchronizer.acquireInterruptibly(AbstractQueuedSynchronizer.java:1220) ~[?:1.8.0_171]
at java.util.concurrent.locks.ReentrantLock.lockInterruptibly(ReentrantLock.java:335) ~[?:1.8.0_171]
at org.apache.commons.pool2.impl.LinkedBlockingDeque.pollFirst(LinkedBlockingDeque.java:624) ~[atcoder-problems-assembly-0.1.jar:0.1]
at org.apache.commons.pool2.impl.GenericObjectPool.borrowObject(GenericObjectPool.java:444) ~[atcoder-problems-assembly-0.1.jar:0.1]
at org.apache.commons.pool2.impl.GenericObjectPool.borrowObject(GenericObjectPool.java:363) ~[atcoder-problems-assembly-0.1.jar:0.1]
at org.apache.commons.dbcp2.PoolingDataSource.getConnection(PoolingDataSource.java:134) ~[atcoder-problems-assembly-0.1.jar:0.1]
... 15 more
java.sql.SQLException: Cannot get a connection, pool error Timeout waiting for idle object
at org.apache.commons.dbcp2.PoolingDataSource.getConnection(PoolingDataSource.java:142) ~[atcoder-problems-assembly-0.1.jar:0.1]
at scalikejdbc.Commons2ConnectionPool.borrow(Commons2ConnectionPool.scala:48) ~[atcoder-problems-assembly-0.1.jar:0.1]
at scalikejdbc.DB$.readOnly(DB.scala:174) ~[atcoder-problems-assembly-0.1.jar:0.1]
at com.kenkoooo.atcoder.db.SqlClient.loadRecords(SqlClient.scala:353) ~[atcoder-problems-assembly-0.1.jar:0.1]
at com.kenkoooo.atcoder.db.SqlClient.reloadRecords(SqlClient.scala:329) ~[atcoder-problems-assembly-0.1.jar:0.1]
at com.kenkoooo.atcoder.Main$.$anonfun$main$2(Main.scala:58) ~[atcoder-problems-assembly-0.1.jar:0.1]
at scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:12) ~[atcoder-problems-assembly-0.1.jar:0.1]
at scala.util.Try$.apply(Try.scala:209) ~[atcoder-problems-assembly-0.1.jar:0.1]
at com.kenkoooo.atcoder.common.ScheduledExecutorServiceExtension$TryAndDieScheduledExecutorService$.$anonfun$tryAtFixedDelay$1(ScheduledExecutorServiceExtension.scala:30) ~[atcoder-problems-assembly-0.1.jar:0.1]
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) [?:1.8.0_171]
at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:308) [?:1.8.0_171]
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:180) [?:1.8.0_171]
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:294) [?:1.8.0_171]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [?:1.8.0_171]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [?:1.8.0_171]
at java.lang.Thread.run(Thread.java:748) [?:1.8.0_171]
Caused by: java.util.NoSuchElementException: Timeout waiting for idle object
at org.apache.commons.pool2.impl.GenericObjectPool.borrowObject(GenericObjectPool.java:449) ~[atcoder-problems-assembly-0.1.jar:0.1]
at org.apache.commons.pool2.impl.GenericObjectPool.borrowObject(GenericObjectPool.java:363) ~[atcoder-problems-assembly-0.1.jar:0.1]
at org.apache.commons.dbcp2.PoolingDataSource.getConnection(PoolingDataSource.java:134) ~[atcoder-problems-assembly-0.1.jar:0.1]
... 15 more
2018/07/10 01:53:02.774 ERROR - [com.kenkoooo.atcoder.common.ScheduledExecutorServiceExtension$TryAndDieScheduledExecutorService$$anonfun$$nestedInanonfun$tryAtFixedDelay$1$1] Catching
java.sql.SQLException: Cannot get a connection, general error
at org.apache.commons.dbcp2.PoolingDataSource.getConnection(PoolingDataSource.java:146) ~[atcoder-problems-assembly-0.1.jar:0.1]
at scalikejdbc.Commons2ConnectionPool.borrow(Commons2ConnectionPool.scala:48) ~[atcoder-problems-assembly-0.1.jar:0.1]
at scalikejdbc.DB$.readOnly(DB.scala:174) ~[atcoder-problems-assembly-0.1.jar:0.1]
at com.kenkoooo.atcoder.db.SqlClient.executeAndLoadSubmission(SqlClient.scala:61) ~[atcoder-problems-assembly-0.1.jar:0.1]
at com.kenkoooo.atcoder.db.SubmissionIterator.reload(SqlClient.scala:478) ~[atcoder-problems-assembly-0.1.jar:0.1]
at com.kenkoooo.atcoder.db.SubmissionIterator.hasNext(SqlClient.scala:464) ~[atcoder-problems-assembly-0.1.jar:0.1]
at scala.collection.Iterator.foreach(Iterator.scala:929) ~[atcoder-problems-assembly-0.1.jar:0.1]
at scala.collection.Iterator.foreach$(Iterator.scala:929) ~[atcoder-problems-assembly-0.1.jar:0.1]
at com.kenkoooo.atcoder.db.SubmissionIterator.foreach(SqlClient.scala:455) ~[atcoder-problems-assembly-0.1.jar:0.1]
at scala.collection.TraversableOnce.size(TraversableOnce.scala:107) ~[atcoder-problems-assembly-0.1.jar:0.1]
at scala.collection.TraversableOnce.size$(TraversableOnce.scala:105) ~[atcoder-problems-assembly-0.1.jar:0.1]
at com.kenkoooo.atcoder.db.SubmissionIterator.size(SqlClient.scala:455) ~[atcoder-problems-assembly-0.1.jar:0.1]
at com.kenkoooo.atcoder.runner.NewerSubmissionScrapingRunner.scrapeOnePage(NewerSubmissionScrapingRunner.scala:30) ~[atcoder-problems-assembly-0.1.jar:0.1]
at com.kenkoooo.atcoder.Main$.$anonfun$main$1(Main.scala:54) ~[atcoder-problems-assembly-0.1.jar:0.1]
at scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:12) ~[atcoder-problems-assembly-0.1.jar:0.1]
at scala.util.Try$.apply(Try.scala:209) ~[atcoder-problems-assembly-0.1.jar:0.1]
at com.kenkoooo.atcoder.common.ScheduledExecutorServiceExtension$TryAndDieScheduledExecutorService$.$anonfun$tryAtFixedDelay$1(ScheduledExecutorServiceExtension.scala:30) ~[atcoder-problems-assembly-0.1.jar:0.1]
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) [?:1.8.0_171]
at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:308) [?:1.8.0_171]
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:180) [?:1.8.0_171]
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:294) [?:1.8.0_171]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [?:1.8.0_171]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [?:1.8.0_171]
at java.lang.Thread.run(Thread.java:748) [?:1.8.0_171]
Caused by: java.lang.InterruptedException
at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.reportInterruptAfterWait(AbstractQueuedSynchronizer.java:2014) ~[?:1.8.0_171]
at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.awaitNanos(AbstractQueuedSynchronizer.java:2088) ~[?:1.8.0_171]
at org.apache.commons.pool2.impl.LinkedBlockingDeque.pollFirst(LinkedBlockingDeque.java:631) ~[atcoder-problems-assembly-0.1.jar:0.1]
at org.apache.commons.pool2.impl.GenericObjectPool.borrowObject(GenericObjectPool.java:444) ~[atcoder-problems-assembly-0.1.jar:0.1]
at org.apache.commons.pool2.impl.GenericObjectPool.borrowObject(GenericObjectPool.java:363) ~[atcoder-problems-assembly-0.1.jar:0.1]
at org.apache.commons.dbcp2.PoolingDataSource.getConnection(PoolingDataSource.java:134) ~[atcoder-problems-assembly-0.1.jar:0.1]
... 23 more
1 participant
Платные услуги для вашего проекта
- Консалтинг и техническая поддержка
Запросы в рамках коммерческой поддержки имеют гарантированное время ответа
- Разработка на заказ
Предоставляем разработку полностью нашими рабочими ресурсами или участвуем в создании вашего проекта
- Обучение
Для быстрого и всестороннего освоения особенностей платформы, чтобы повысить продуктивность вашей команды
Haulmont
мы разрабатываем современные корпоративные решения
-
Эксперты в области разработки корпоративного ПО
-
Создатели CUBA Platform
-
Компания основана в 2008
-
300+
разработчиков
-
400+
проектов
-
Клиенты в
60+
странах
I am having a webapp on production, which runs fine for 7-8 days then suddenly my website is down and logs reproduce this error:
java.sql.SQLException: Cannot get a connection, pool error Timeout waiting for idle object
And all operations to database starts failing. I have read across several other questions and blog but not able to find any definite solution. I am using connection pool, and I am really not sure where the problem is.
Is it because of my code which I have written or pool configuration? I am providing code here for one of method which gets data from database and also the pool configuration. Please have a look and let me know if I am doing something wrong.
public CartItem getCustomerCartItem(int customerId, int productId, int productOfCityId) {
Connection con = ConnectionPool.getInstance().getConnection();
PreparedStatement st = null;
ResultSet rs = null;
CartItem ci = null;
CityProduct cityProduct = productService.getCityProduct(productId, productOfCityId);
if (cityProduct == null) {
return null;
}
String query = "SELECT ci.* FROM customer_cart_item_mapping cim INNER JOIN cart_item ci ON ci.Id = cim.CartItemId WHERE "
+ "cim.CustomerId = ? AND ci.ProductOfCityId = ?";
try {
st = con.prepareCall(query);
st.setInt(1, customerId);
st.setInt(2, productOfCityId);
rs = st.executeQuery();
if (rs.first()) {
ci = new CartItem();
ci.setId(rs.getInt("Id"));
ci.setCityProduct(cityProduct);
ci.setQuantity(rs.getInt("Quantity"));
ci.setCreatedDate(rs.getDate("CreatedDate"));
ci.setUpdatedDate(rs.getDate("UpdatedDate"));
}
} catch (SQLException ex) {
Logger lgr = Logger.getLogger(CartItemDaoImpl.class.getName());
lgr.log(Level.SEVERE, ex.getMessage(), ex);
} finally {
DBUtil.close(con, st, rs);
}
return ci;
}
Below is DBUtil
class used to close connections:
public class DBUtil {
public static void close(Connection c, Statement s, ResultSet r) {
try {
if (r != null) {
r.close();
}
if (s != null) {
s.close();
}
if (c != null) {
ConnectionPool.getInstance().freeConnection(c);
}
} catch (SQLException ex) {
Logger.getLogger(DBUtil.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
Following is ConnectionPool
class
public class ConnectionPool {
private static ConnectionPool pool=null;
private static DataSource dataSource = null;
public synchronized static ConnectionPool getInstance(){
if (pool == null){
pool = new ConnectionPool();
}
return pool;
}
private ConnectionPool(){
try{
InitialContext ic = new InitialContext();
dataSource = (DataSource) ic.lookup("java:/comp/env/jdbc/prod_db");
}
catch(NamingException e){
System.out.println(e);
}
}
public Connection getConnection(){
try{
return dataSource.getConnection();
}
catch (SQLException sqle){
System.err.println(sqle);
return null;
}
}
public void freeConnection(Connection c){
try{
c.close();
}
catch (SQLException sqle){
System.err.println(sqle);
}
}
}
Below is connection pool configuration
<Context antiJARLocking="true" path="/">
<Resource auth="Container" connectionProperties="useEncoding=true;" driverClassName="com.mysql.jdbc.Driver" initialSize="2"
logAbandoned="true" maxIdle="40" maxTotal="70" maxWaitMillis="1000" minEvictableIdleTimeMillis="600000" minIdle="2" name="jdbc/winni_prime_db"
password="password" removeAbandoned="true" removeAbandonedTimeout="90" testWhileIdle="true" timeBetweenEvictionRunsMillis="90000"
type="javax.sql.DataSource" url="jdbc:mysql://localhost:3306/prod_db"
username="sqladmin" validationQuery="SELECT 1"/>
This problem has been persistent from last several months. Only solution is like to restart tomcat every night. Please take a look at this code and give me an expert opinion where I am doing wrong. I am using MySQL
Skip to content
I am trying to connect to mysql
database using apache
dbcp2
connection pooling following its tutorial from here:
https://git-wip-us.apache.org/repos/asf?p=commons-dbcp.git;a=blob;f=doc/PoolingDataSourceExample.java;h=2a12c74898930b9623223db1597b8a8052a6f1df;hb=HEAD
My Database connection class that return the connection looks something like this:
public class DbConnection {
private static interface Singleton {
final DbConnection INSTANCE = new DbConnection();
}
private final PoolingDataSource<PoolableConnection> dataSource;
private DbConnection() {
// A ConnectionFactory that the pool will use to create Connections.
DriverManagerConnectionFactory connectionFactory = new DriverManagerConnectionFactory(url, user, pass); //url,user,pass for db connnection
//implement the pooling functionality.
PoolableConnectionFactory poolableConnectionFactory = new PoolableConnectionFactory(connectionFactory, null);
GenericObjectPoolConfig config = new GenericObjectPoolConfig();
config.setMaxWaitMillis(500);
config.setMaxTotal(20);
config.setMaxIdle(5);
config.setMinIdle(5);
//PoolingDataSource expect an ObjectPool
ObjectPool<PoolableConnection> connectionPool = new GenericObjectPool<>(poolableConnectionFactory, config);
// Set the poolableConnectionFactory's pool property to the owning pool
poolableConnectionFactory.setPool(connectionPool);
this.dataSource = new PoolingDataSource<>(connectionPool);
}
public static Connection getCon() throws SQLException {
return Singleton.INSTANCE.dataSource.getConnection();
}
}
I am using apache jmeter to test the connection and return something from my mysql database. I created 100 users with Ramp-up periods(in seconds) being 2 second. I created a Http request
and when I tried to see my response in view results tree
I successfully get response for first 20 request. Later requests from (21 to 100) have blank response. I have gone through many of the issues involving:
java.sql.SQLException: Cannot get a connection, pool error Timeout
waiting for idle object
I access my code as:
try (PreparedStatement ps = DbConnection.getCon().prepareStatement("SELECT id FROM test WHERE id =?;")) {
ps.setString(1, id);
try (
ResultSet rs = ps.executeQuery()) {
return rs.next();
}
} catch (Exception ex) {
}
Solution:
You aren’t closing Connection
object, you must declare such variable in try-with-resources block :
try (Connection conn = DbConnection.getCon();
PreparedStatement ps = conn.prepareStatement("SELECT id FROM test WHERE id =?;")) {
Also you need to close ResultSet
, either call close
method ResultSet
in method or add it to try-with-resources block using a new method returning it