In order to run this example you need a PostgreSQL database.
datasources:
default:
url: jdbc:postgresql://10.211.55.10:5432/prueba
username: postgres
password: postgres
With your values.
<database-url>jdbc:postgresql://10.211.55.10:5432/prueba</database-url>
<database-user>postgres</database-user>
<database-password>postgres</database-password>
With your values.
Run the Application class.
13:38:05.001 [pool-2-thread-3] DEBUG i.m.context.DefaultBeanContext - Resolved existing bean [prueba.jdbc.TestScheduler@df35147] for type [class prueba.jdbc.TestScheduler] and qualifier [null]
13:38:05.002 [pool-2-thread-3] DEBUG i.m.t.j.DataSourceTransactionManager - Creating new transaction with name [Dao.insert]: 0,-1
13:38:05.002 [pool-2-thread-3] DEBUG i.m.t.j.DataSourceTransactionManager - Acquired Connection [ProxyConnection[PooledConnection[org.postgresql.jdbc.PgConnection@7f64f3dc]]] for JDBC transaction
13:38:05.003 [pool-2-thread-3] DEBUG org.jooq.tools.LoggerListener - Executing query : insert into "public"."test_table" ("key", "some_text") values (?, ?)
13:38:05.003 [pool-2-thread-3] DEBUG org.jooq.tools.LoggerListener - -> with bind values : insert into "public"."test_table" ("key", "some_text") values ('7396b88c-6438-4e9a-bb45-ebdc88f6dce7', 'text.')
13:38:05.004 [pool-2-thread-3] DEBUG org.jooq.tools.LoggerListener - Affected row(s) : 1
13:38:05.005 [pool-2-thread-3] DEBUG i.m.t.j.DataSourceTransactionManager - Initiating transaction commit
13:38:05.005 [pool-2-thread-3] DEBUG i.m.t.j.DataSourceTransactionManager - Committing JDBC transaction on Connection [ProxyConnection[PooledConnection[org.postgresql.jdbc.PgConnection@7f64f3dc]]]
13:38:05.006 [pool-2-thread-3] DEBUG i.m.t.j.DataSourceTransactionManager - Releasing JDBC Connection [ProxyConnection[PooledConnection[org.postgresql.jdbc.PgConnection@7f64f3dc]]] after transaction
13:38:07.006 [pool-2-thread-2] DEBUG i.m.context.DefaultBeanContext - Resolved existing bean [prueba.jdbc.TestScheduler@df35147] for type [class prueba.jdbc.TestScheduler] and qualifier [null]
13:38:07.006 [pool-2-thread-2] DEBUG i.m.t.j.DataSourceTransactionManager - Creating new transaction with name [Dao.insert]: 0,-1
13:38:07.006 [pool-2-thread-2] DEBUG i.m.t.j.DataSourceTransactionManager - Acquired Connection [ProxyConnection[PooledConnection[org.postgresql.jdbc.PgConnection@7f64f3dc]]] for JDBC transaction
13:38:07.007 [pool-2-thread-2] DEBUG org.jooq.tools.LoggerListener - Executing query : insert into "public"."test_table" ("key", "some_text") values (?, ?)
13:38:07.007 [pool-2-thread-2] DEBUG org.jooq.tools.LoggerListener - -> with bind values : insert into "public"."test_table" ("key", "some_text") values ('c772cd4d-3383-44a2-8bfb-e8e3ceff700e', 'text.')
13:38:07.009 [pool-2-thread-2] DEBUG org.jooq.tools.LoggerListener - Affected row(s) : 1
Restart the application, for some reason the problem doesn't happen all the time.
When the problem happens, you will see this in the log at the first insert attempt:
13:36:38.723 [pool-2-thread-2] DEBUG org.jooq.tools.LoggerListener - Executing query : insert into "public"."test_table" ("key", "some_text") values (?, ?)
13:36:38.724 [pool-2-thread-2] DEBUG org.jooq.tools.LoggerListener - -> with bind values : insert into "public"."test_table" ("key", "some_text") values ('be6d5215-42f9-4b9e-96b3-e1045b8c7eaf', 'text.')
13:37:08.731 [pool-2-thread-2] DEBUG io.micronaut.core.reflect.ClassUtils - Attempting to dynamically load class org.postgresql.Driver
13:37:08.731 [pool-2-thread-2] DEBUG io.micronaut.core.reflect.ClassUtils - Successfully loaded class org.postgresql.Driver
13:37:08.732 [pool-2-thread-2] DEBUG org.jooq.tools.LoggerListener - Exception
org.jooq.exception.DataAccessException: Error getting connection from data source org.apache.tomcat.jdbc.pool.DataSource@7ff2b8d2{ConnectionPool[defaultAutoCommit=false; defaultReadOnly=null; defaultTransactionIsolation=-1; defaultCatalog=null; driverClassName=org.postgresql.Driver; maxActive=1; maxIdle=1; minIdle=1; initialSize=1; maxWait=30000; testOnBorrow=false; testOnReturn=false; timeBetweenEvictionRunsMillis=5000; numTestsPerEvictionRun=0; minEvictableIdleTimeMillis=60000; testWhileIdle=false; testOnConnect=false; password=********; url=jdbc:postgresql://10.211.55.10:5432/prueba; username=postgres; validationQuery=SELECT 1; validationQueryTimeout=-1; validatorClassName=null; validationInterval=3000; accessToUnderlyingConnectionAllowed=true; removeAbandoned=false; removeAbandonedTimeout=60; logAbandoned=false; connectionProperties=null; initSQL=null; jdbcInterceptors=null; jmxEnabled=true; fairQueue=true; useEquals=true; abandonWhenPercentageFull=0; maxAge=0; useLock=false; dataSource=null; dataSourceJNDI=null; suspectTimeout=0; alternateUsernameAllowed=false; commitOnReturn=false; rollbackOnReturn=false; useDisposableConnectionFacade=true; logValidationErrors=false; propagateInterruptState=false; ignoreExceptionOnPreLoad=false; useStatementFacade=true; }
at org.jooq_3.13.2.POSTGRES.debug(Unknown Source)
at org.jooq.impl.DataSourceConnectionProvider.acquire(DataSourceConnectionProvider.java:86)
at org.jooq.impl.DefaultExecuteContext.connection(DefaultExecuteContext.java:647)
at org.jooq.impl.AbstractQuery.execute(AbstractQuery.java:334)
at org.jooq.impl.AbstractDelegatingQuery.execute(AbstractDelegatingQuery.java:119)
at prueba.jdbc.Dao.insert(Dao.java:29)
at prueba.jdbc.$DaoDefinition$Intercepted.$$access0(Unknown Source)
at prueba.jdbc.$DaoDefinition$Intercepted$$proxy0.invokeInternal(Unknown Source)
at io.micronaut.context.AbstractExecutableMethod.invoke(AbstractExecutableMethod.java:146)
at io.micronaut.aop.chain.MethodInterceptorChain.proceed(MethodInterceptorChain.java:60)
at io.micronaut.transaction.interceptor.TransactionalInterceptor.intercept(TransactionalInterceptor.java:108)
at io.micronaut.aop.chain.MethodInterceptorChain.proceed(MethodInterceptorChain.java:69)
at prueba.jdbc.$DaoDefinition$Intercepted.insert(Unknown Source)
at prueba.jdbc.TestScheduler.handle(TestScheduler.java:22)
at prueba.jdbc.TestScheduler.run(TestScheduler.java:18)
at prueba.jdbc.$TestSchedulerDefinition$$exec1.invokeInternal(Unknown Source)
at io.micronaut.context.AbstractExecutableMethod.invoke(AbstractExecutableMethod.java:146)
at io.micronaut.inject.DelegatingExecutableMethod.invoke(DelegatingExecutableMethod.java:76)
at io.micronaut.scheduling.processor.ScheduledMethodProcessor.lambda$process$5(ScheduledMethodProcessor.java:125)
at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)
at java.base/java.util.concurrent.FutureTask.runAndReset(FutureTask.java:305)
at java.base/java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:305)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1130)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:630)
at java.base/java.lang.Thread.run(Thread.java:832)
Caused by: org.apache.tomcat.jdbc.pool.PoolExhaustedException: [pool-2-thread-2] Timeout: Pool empty. Unable to fetch a connection in 30 seconds, none available[size:1; busy:1; idle:0; lastwait:30000].
at org.apache.tomcat.jdbc.pool.ConnectionPool.borrowConnection(ConnectionPool.java:717)
at org.apache.tomcat.jdbc.pool.ConnectionPool.getConnection(ConnectionPool.java:198)
at org.apache.tomcat.jdbc.pool.DataSourceProxy.getConnection(DataSourceProxy.java:132)
at org.jooq.impl.DataSourceConnectionProvider.acquire(DataSourceConnectionProvider.java:83)
... 23 common frames omitted