HikariPool-1 - Connection is not available, request timed out after 30050ms - oracle

I am using Oracle DB with spring-boot(2.6.2), upon running batch services, I am getting the following error:
*
36mo.h.engine.jdbc.spi.SqlExceptionHelper SQL Error: 0, SQLState: null
31mERROR 36mo.h.engine.jdbc.spi.SqlExceptionHelper: HikariPool-1 - Connection is not available, request timed out after 30050ms.
32mDEBUG 36mcom.zaxxer.hikari.pool.HikariPool: HikariPool-2 - Pool stats (total=10, active=0, idle=10, waiting=0)
32mDEBUG 36mcom.zaxxer.hikari.pool.: HikariPool-2 - Fill pool skipped, pool is at sufficient level.
32mDEBUG 36mcom.zaxxer.hikari.pool.HikariPool: HikariPool-1 - Pool stats (total=10, active=10, idle=0, waiting=1)
32mDEBUG 36mcom.zaxxer.hikari.pool.: HikariPool-1 - Fill pool skipped, pool is at sufficient level.
32mDEBUG 36mcom.zaxxer.hikari.pool.HikariPool: HikariPool-1 - Timeout failure stats (total=10, active=10, idle=0, waiting=0)
33m WARN 36mo.h.engine.jdbc.spi.SqlExceptionHelper: SQL Error: 0, SQLState: null
31mERROR 36mo.h.engine.jdbc.spi.SqlExceptionHelper: HikariPool-1 - Connection is not available, request timed out after 30002ms.
32mDEBUG 36mcom.zaxxer.hikari.pool.HikariPool: HikariPool-2 - Pool stats (total=10, active=0, idle=10, waiting=0)
32mDEBUG 36mcom.zaxxer.hikari.pool.: HikariPool-2 - Fill pool skipped, pool is at sufficient level.
32mDEBUG 36mcom.zaxxer.hikari.pool.HikariPool: HikariPool-1 - Pool stats (total=10, active=10, idle=0, waiting=1)
32mDEBUG 36mcom.zaxxer.hikari.pool.HikariPool: HikariPool-1 - Fill pool skipped, pool is at sufficient level.
32mDEBUG 36mcom.zaxxer.hikari.pool.HikariPool: HikariPool-1 - Timeout failure stats (total=10, active=10, idle=0, waiting=0)
33m WARN 36mo.h.engine.jdbc.spi.SqlExceptionHelper SQL Error: 0, SQLState: null
*
I see sometime the total connection becomes 0 and then it reaches 10 and then again back to 0. I went through websites for this error where they mentioned error related DataSource object. Below is the details of the properties file:
spring:
datasource:
ss:
driver-class-name: oracle.jdbc.driver.OracleDriver
hikari:
connection-timeout: 5000
maximum-pool-size: 10
idle-timeout: 60000
max-lifetime: 1800000
minimum-idle: 2
jdbc-url: ------URL---
Here is the configuration class function:
#Bean
#ConfigurationProperties(prefix="spring.datasource.ss")
public DataSource sourceDataSource() {
return DataSourceBuilder.create().build();
}
// EntityManager bean
#Bean
public LocalContainerEntityManagerFactoryBean sourceEntityManager() {
LocalContainerEntityManagerFactoryBean em
= new LocalContainerEntityManagerFactoryBean();
em.setDataSource(sourceDataSource());
........... .
I tried solving this...but didn't got concrete solution. So how to remove this error ?

Related

spring kafka: Transactions in consumer Timeout expired after 60000 milliseconds while awaiting AddOffsetsToTxn

We have a transactional producer. And there are no issue there.
For the consumer, we see the following in the logs. Question is why is a transaction being started here while we are consuming the message (and there is this resulting exception)?
2022-12-28 18:02:05.986 DEBUG [qa] 85474 --- [tainer#0-51-C-1] o.s.k.t.KafkaTransactionManager : Creating new transaction with name [null]: PROPAGATION_REQUIRED,ISOLATION_DEFAULT
2022-12-28 18:02:10.437 DEBUG [qa] 85474 --- [tainer#0-51-C-1] o.s.k.t.KafkaTransactionManager : Created Kafka transaction on producer [CloseSafeProducer [delegate=brave.kafka.clients.TracingProducer#43e18a26]]
2022-12-28 18:02:10.438 DEBUG [qa] 85474 --- [tainer#0-51-C-1] abc.abc.kafka : NORMAL uid[n/a] cid[uPRwhWZikfcYpGfIqh7TxXFnm6VmZWkf] m[[S] Consuming message] data[record = ConsumerRecord(topic =XXXXXXX)))]
2022-12-28 18:02:10.438 DEBUG [qa] 85474 --- [tainer#0-51-C-1] abc.abc.kafka : NORMAL uid[n/a] cid[uPRwhWZikfcYpGfIqh7TxXFnm6VmZWkf] m[Processed message]
2022-12-28 18:03:10.439 INFO [qa] 85474 --- [tainer#0-51-C-1] abc.abc.common.Generic : NORMAL uid[n/a] cid[uPRwhWZikfcYpGfIqh7TxXFnm6VmZWkf] m[Throwable t] data[exception = [Ljava.lang.StackTraceElement;#6d314e1d] ex[Timeout expired after 60000 milliseconds while awaiting AddOffsetsToTxn] sts[org.apache.kafka.common.errors.TimeoutException: Timeout expired after 60000 milliseconds while awaiting AddOffsetsToTxn
]
2022-12-28 18:03:10.439 DEBUG [qa] 85474 --- [tainer#0-51-C-1] abc.abc.kafka : NORMAL uid[n/a] cid[uPRwhWZikfcYpGfIqh7TxXFnm6VmZWkf] m[[E] Consuming message]
2022-12-28 18:03:10.439 DEBUG [qa] 85474 --- [tainer#0-51-C-1] o.s.k.t.KafkaTransactionManager : Initiating transaction commit
2022-12-28 18:04:10.444 ERROR [qa] 85474 --- [tainer#0-51-C-1] o.s.k.core.DefaultKafkaProducerFactory : org.apache.kafka.common.errors.TimeoutException: Timeout expired after 60000 milliseconds while awaiting EndTxn(true)
commitTransaction failed: CloseSafeProducer [delegate=brave.kafka.clients.TracingProducer#43e18a26]
2022-12-28 18:04:10.444 DEBUG [qa] 85474 --- [tainer#0-51-C-1] o.s.k.t.KafkaTransactionManager : org.apache.kafka.common.errors.TimeoutException: Timeout expired after 60000 milliseconds while awaiting EndTxn(true)
Initiating transaction rollback after commit exception
2022-12-28 18:04:10.445 WARN [qa] 85474 --- [tainer#0-51-C-1] o.s.k.core.DefaultKafkaProducerFactory : Error during some operation; producer removed from cache: CloseSafeProducer [delegate=brave.kafka.clients.TracingProducer#43e18a26]
2022-12-28 18:04:12.436 ERROR [qa] 85474 --- [tainer#0-51-C-1] o.s.k.l.KafkaMessageListenerContainer : org.apache.kafka.common.errors.TimeoutException: Timeout expired after 60000 milliseconds while awaiting EndTxn(true)
Transaction rolled back
This is the configuration:
spring:
data:
mongodb:
uri: indb-prop
auto-index-creation: false
kafka:
producer:
key-serializer: org.apache.kafka.common.serialization.StringSerializer
value-serializer: org.springframework.kafka.support.serializer.JsonSerializer
retries: 2
client-id: ${spring.application.name}-${info.cluster}-${IP_ADDRESS}PP
transaction-id-prefix: tx-${spring.kafka.producer.client-id}-
properties:
enable.idempotence: true
spring.json.add.type.headers: false
bootstrap-servers: ${kafka_bootstrap_servers_2}
# listener:
# missing-topics-fatal: true
# type: batch
# concurrency: 15
# ack-mode: manual_immediate
# poll-timeout: 1s
consumer:
key-deserializer: org.springframework.kafka.support.serializer.ErrorHandlingDeserializer
value-deserializer: org.springframework.kafka.support.serializer.ErrorHandlingDeserializer
group-id: ${spring.application.name}-${info.cluster}-111111111112
client-id: ${spring.application.name}-${info.cluster}-${IP_ADDRESS}
# client-id: ${spring.kafka.consumer.group-id}-${IP_ADDRESS}
auto-offset-reset: earliest
enable-auto-commit: false
isolation-level: read_committed
# max-poll-records: 3
fetch-max-wait: 5s
properties:
max.poll.interval.ms: 20000000
spring.json.trusted.packages: '*'
spring.deserializer.key.delegate.class: org.apache.kafka.common.serialization.StringDeserializer
spring.deserializer.value.delegate.class: org.springframework.kafka.support.serializer.JsonDeserializer
spring.json.value.default.type: net.abc.abc.EventData
bootstrap-servers: ${kafka_bootstrap_servers}
And the consumer:
#KafkaListener(
topics = "SOME_TOPIC",
autoStartup = "true")
// #Transactional(transactionManager = "mongoTransactionManager", propagation = Propagation.REQUIRED)
#Override
public void onMessage(ConsumerRecord<String, EventData> data) {
if (data == null || data.value() == null) {
return;
}
logger.debug(m -> m.event(KAFKA)
.msg("[S] Consuming message")
.with("record", data));
try {
logger.debug(m -> m.event(KAFKA)
.msg("Processed message"));
}
finally {
logger.debug(m -> m.event(KAFKA)
.msg("[E] Consuming message"));
}
The springBoot version: '2.6.6'
How many broker nodes are you using? If 1, have you overridden the broker params KAFKA_TRANSACTION_STATE_LOG_REPLICATION_FACTOR and KAFKA_TRANSACTION_STATE_LOG_MIN_ISR to 1?
Similar sounding issue here:
https://github.com/testcontainers/testcontainers-java/issues/1816
Rob.

"HikariPool-1 - Connection is not available, request timed out after 30004ms." exception occurs only on the development server

"Hikari Pool-1 - Connection is not available, request timed out after 30004ms." exception occurs only on the development server.
I spent a lot of time trying to find this problem, but I couldn't. For the first time in my life, I'm posting a question on stackoverflow.Please let me know if there is anything lacking in the question.
For your understanding, I have placed an example source code on GitHub.
I included the DDL Query used in the example below the resource folder and the log file (dev-log.out) on the actual development server.
I wrote down what I wanted to ask you at the bottom.
The requirements I am trying to implement are as follows.
Put the data from the source table into the target table.
If an exception occurs in the process of 1), the transaction is rolled back and the corresponding exception information is loaded on the log table.
To meet this requirement, I declared #Transactional to a service class (DemoService class in the example) that performs 1).
#RequiredArgsConstructor
#Service
public class DemoService {
private final DemoRepository repository;
#Transactional
#Logging
public void run() {
List<Integer> ids = repository.select(); //select from source table
for (Integer id : ids) {
repository.insert(id); //insert into target table
//An exception was made intentionally to roll back test
if (id == 1) {
throw new RuntimeException("exception~~");
}
}
}
}
And I wrote Aop using #Aspect (LoggingAspect in the example) to load exception information into the table. And I gave the REQUIRES_NEW option because the transaction loading exception information should be committed separately from the transaction used in 1).
#RequiredArgsConstructor
#Slf4j
#Component
#Aspect
public class LoggingAspect {
private final LoggingService loggingService;
#AfterThrowing(value = "#annotation(com.example.dbcpquestion.logging.Logging)", throwing = "ex")
public void doLog(JoinPoint joinPoint, Exception ex) throws Throwable {
log.error("-----------------------------------------");
int cnt = loggingService.logging();
log.error("cnt={}", cnt);
log.error("-----------------------------------------");
}
}
#RequiredArgsConstructor
#Service
public class LoggingService {
private final LoggingRepository repository;
#Transactional(propagation = Propagation.REQUIRES_NEW)
public int logging() {
return repository.save(); //insert exception info into log table
}
}
I know that if an exception occurs while performing 1) logic, at least two connections are required. (Transactions that work to move data from the Source table to the Target table that will eventually be rolled back, and transactions that load exception information into the log table)
The problem is!
The logic (1, 2) above works fine on the local PC, but when deployed to the development server, the exception "Hikari Pool-1 - Connection is not available, request timed out after 30004ms."
The strangest thing happens intermittently... (crazy)
Here's the Hikari setup log.
[2022-10-06 18:46:00.724] [DEBUG] [main] [HikariConfig ]- HikariPool-1 - configuration:
[2022-10-06 18:46:00.730] [DEBUG] [main] [HikariConfig ]- allowPoolSuspension................................false
[2022-10-06 18:46:00.730] [DEBUG] [main] [HikariConfig ]- autoCommit................................true
[2022-10-06 18:46:00.730] [DEBUG] [main] [HikariConfig ]- catalog................................none
[2022-10-06 18:46:00.730] [DEBUG] [main] [HikariConfig ]- connectionInitSql................................none
[2022-10-06 18:46:00.731] [DEBUG] [main] [HikariConfig ]- connectionTestQuery................................none
[2022-10-06 18:46:00.731] [DEBUG] [main] [HikariConfig ]- connectionTimeout................................30000
[2022-10-06 18:46:00.731] [DEBUG] [main] [HikariConfig ]- dataSource................................none
[2022-10-06 18:46:00.732] [DEBUG] [main] [HikariConfig ]- dataSourceClassName................................none
[2022-10-06 18:46:00.732] [DEBUG] [main] [HikariConfig ]- dataSourceJNDI................................none
[2022-10-06 18:46:00.734] [DEBUG] [main] [HikariConfig ]- dataSourceProperties................................{password=<masked>}
[2022-10-06 18:46:00.734] [DEBUG] [main] [HikariConfig ]- driverClassName................................"oracle.jdbc.OracleDriver"
[2022-10-06 18:46:00.734] [DEBUG] [main] [HikariConfig ]- exceptionOverrideClassName................................none
[2022-10-06 18:46:00.734] [DEBUG] [main] [HikariConfig ]- healthCheckProperties................................{}
[2022-10-06 18:46:00.734] [DEBUG] [main] [HikariConfig ]- healthCheckRegistry................................none
[2022-10-06 18:46:00.735] [DEBUG] [main] [HikariConfig ]- idleTimeout................................600000
[2022-10-06 18:46:00.735] [DEBUG] [main] [HikariConfig ]- initializationFailTimeout................................1
[2022-10-06 18:46:00.735] [DEBUG] [main] [HikariConfig ]- isolateInternalQueries................................false
[2022-10-06 18:46:00.735] [DEBUG] [main] [HikariConfig ]- jdbcUrl................................[Cleared for security reasons.]
[2022-10-06 18:46:00.736] [DEBUG] [main] [HikariConfig ]- keepaliveTime................................0
[2022-10-06 18:46:00.736] [DEBUG] [main] [HikariConfig ]- leakDetectionThreshold................................2000
[2022-10-06 18:46:00.736] [DEBUG] [main] [HikariConfig ]- maxLifetime................................1800000
[2022-10-06 18:46:00.736] [DEBUG] [main] [HikariConfig ]- maximumPoolSize................................3
[2022-10-06 18:46:00.737] [DEBUG] [main] [HikariConfig ]- metricRegistry................................none
[2022-10-06 18:46:00.737] [DEBUG] [main] [HikariConfig ]- metricsTrackerFactory................................none
[2022-10-06 18:46:00.737] [DEBUG] [main] [HikariConfig ]- minimumIdle................................3
[2022-10-06 18:46:00.737] [DEBUG] [main] [HikariConfig ]- password................................<masked>
[2022-10-06 18:46:00.737] [DEBUG] [main] [HikariConfig ]- poolName................................"HikariPool-1"
[2022-10-06 18:46:00.738] [DEBUG] [main] [HikariConfig ]- readOnly................................false
[2022-10-06 18:46:00.738] [DEBUG] [main] [HikariConfig ]- registerMbeans................................false
[2022-10-06 18:46:00.738] [DEBUG] [main] [HikariConfig ]- scheduledExecutor................................none
[2022-10-06 18:46:00.738] [DEBUG] [main] [HikariConfig ]- schema................................none
[2022-10-06 18:46:00.739] [DEBUG] [main] [HikariConfig ]- threadFactory................................internal
[2022-10-06 18:46:00.739] [DEBUG] [main] [HikariConfig ]- transactionIsolation................................default
[2022-10-06 18:46:00.739] [DEBUG] [main] [HikariConfig ]- username................................[Cleared for security reasons.]
[2022-10-06 18:46:00.739] [DEBUG] [main] [HikariConfig ]- validationTimeout................................5000
[2022-10-06 18:46:00.739] [INFO ] [main] [HikariDataSource ]- HikariPool-1 - Starting...
[2022-10-06 18:46:02.249] [DEBUG] [main] [HikariPool ]- HikariPool-1 - Added connection oracle.jdbc.driver.T4CConnection#1fc684e
[2022-10-06 18:46:02.252] [INFO ] [main] [HikariDataSource ]- HikariPool-1 - Start completed.
[2022-10-06 18:46:02.288] [INFO ] [main] [DemoService ]- [select]..................
[2022-10-06 18:46:02.361] [DEBUG] [HikariPool-1 housekeeper] [HikariPool ]- HikariPool-1 - Pool stats (total=1, active=1, idle=0, waiting=0)
[2022-10-06 18:46:02.369] [DEBUG] [HikariPool-1 connection adder] [PoolBase ]- HikariPool-1 - Failed to create/setup connection: null
[2022-10-06 18:46:02.390] [DEBUG] [HikariPool-1 connection adder] [HikariPool ]- HikariPool-1 - Cannot acquire connection from data source
java.lang.NullPointerException: null
Yaml file settings.
Logging level has been set to DEBUG.
Hikari's maximum-pool-size is set to 3. As far as I know, I can set it to 2, but...I added one more connection
I also set leak-detection-threshold to look at connection leak.
As an example, url was specified as localhost, but the URL is actually specified as an IP address, not localhost. Both local profiles and dev profiles have the same DB connection information.
spring:
datasource:
username: dbcp
password: dbcp
driver-class-name: oracle.jdbc.OracleDriver
hikari:
maximum-pool-size: 3
leak-detection-threshold: 2000
logging:
pattern:
console: "[%d{yyyy-MM-dd HH:mm:ss.SSS}] [%-5level] [%thread] [%-25logger{0}]- %msg%n"
level:
'[com.zaxxer.hikari]': trace
'[com.zaxxer.hikari.HikariConfig]': debug
---
spring:
config:
activate:
on-profile: local
datasource:
url: jdbc:oracle:thin:#localhost:1521:orcl
#As an example, url was specified as localhost, but the URL is actually specified as an IP address, not localhost. Both local profiles and dev profiles have the same DB connection information.
---
spring:
config:
activate:
on-profile: dev
datasource:
url: jdbc:oracle:thin:#localhost:1521:orcl
The entire log.(Omit part of the log because of the number of characters.)
[2022-10-06 18:46:02.361] [DEBUG] [HikariPool-1 housekeeper] [HikariPool ]- HikariPool-1 - Pool stats (total=1, active=1, idle=0, waiting=0)
[2022-10-06 18:46:02.369] [DEBUG] [HikariPool-1 connection adder] [PoolBase ]- HikariPool-1 - Failed to create/setup connection: null
[2022-10-06 18:46:02.390] [DEBUG] [HikariPool-1 connection adder] [HikariPool ]- HikariPool-1 - Cannot acquire connection from data source
java.lang.NullPointerException: null
at java.base/java.lang.StringCoding.encode(StringCoding.java:652)
at java.base/java.lang.String.getBytes(String.java:982)
at java.base/java.lang.ProcessEnvironment$Variable.valueOfQueryOnly(ProcessEnvironment.java:166)
at java.base/java.lang.ProcessEnvironment$Variable.valueOfQueryOnly(ProcessEnvironment.java:162)
at java.base/java.lang.ProcessEnvironment$StringEnvironment.get(ProcessEnvironment.java:239)
at java.base/java.lang.ProcessEnvironment$StringEnvironment.get(ProcessEnvironment.java:221)
at java.base/java.util.Collections$UnmodifiableMap.get(Collections.java:1454)
at java.base/java.lang.ProcessEnvironment.getenv(ProcessEnvironment.java:85)
at java.base/java.lang.System.getenv(System.java:1001)
at oracle.jdbc.driver.PhysicalConnection.lambda$getTnsAdminFromEnv$4(PhysicalConnection.java:10990)
at java.base/java.security.AccessController.doPrivileged(Native Method)
at oracle.jdbc.driver.PhysicalConnection.getTnsAdminFromEnv(PhysicalConnection.java:10987)
at oracle.jdbc.driver.PhysicalConnection.readConnectionProperties(PhysicalConnection.java:1427)
at oracle.jdbc.driver.PhysicalConnection.<init>(PhysicalConnection.java:941)
at oracle.jdbc.driver.PhysicalConnection.<init>(PhysicalConnection.java:926)
at oracle.jdbc.driver.T4CConnection.<init>(T4CConnection.java:542)
at oracle.jdbc.driver.T4CDriverExtension.getConnection(T4CDriverExtension.java:69)
at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:728)
at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:649)
at com.zaxxer.hikari.util.DriverDataSource.getConnection(DriverDataSource.java:138)
at com.zaxxer.hikari.pool.PoolBase.newConnection(PoolBase.java:364)
at com.zaxxer.hikari.pool.PoolBase.newPoolEntry(PoolBase.java:206)
at com.zaxxer.hikari.pool.HikariPool.createPoolEntry(HikariPool.java:476)
at com.zaxxer.hikari.pool.HikariPool.access$100(HikariPool.java:71)
at com.zaxxer.hikari.pool.HikariPool$PoolEntryCreator.call(HikariPool.java:726)
at com.zaxxer.hikari.pool.HikariPool$PoolEntryCreator.call(HikariPool.java:712)
at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
at java.base/java.lang.Thread.run(Thread.java:834)
[2022-10-06 18:46:02.660] [DEBUG] [HikariPool-1 connection adder] [HikariPool ]- HikariPool-1 - Cannot acquire connection from data source
java.lang.NullPointerException: null
at java.base/java.lang.StringCoding.encode(StringCoding.java:652)
at java.base/java.lang.String.getBytes(String.java:982)
at java.base/java.lang.ProcessEnvironment$Variable.valueOfQueryOnly(ProcessEnvironment.java:166)
at java.base/java.lang.ProcessEnvironment$Variable.valueOfQueryOnly(ProcessEnvironment.java:162)
at java.base/java.lang.ProcessEnvironment$StringEnvironment.get(ProcessEnvironment.java:239)
/////Omit part of the log because of the number of characters.
[2022-10-06 18:46:02.928] [ERROR] [main] [LoggingAspect ]- -----------------------------------------
[2022-10-06 18:46:03.055] [DEBUG] [HikariPool-1 connection adder] [HikariPool ]- HikariPool-1 - Cannot acquire connection from data source
java.lang.NullPointerException: null
at java.base/java.lang.StringCoding.encode(StringCoding.java:652)
/////Omit part of the log because of the number of characters.
[2022-10-06 18:46:03.624] [DEBUG] [HikariPool-1 connection adder] [HikariPool ]- HikariPool-1 - Cannot acquire connection from data source
java.lang.NullPointerException: null
at java.base/java.lang.StringCoding.encode(StringCoding.java:652)
/////Omit part of the log because of the number of characters.
[2022-10-06 18:46:04.278] [WARN ] [HikariPool-1 housekeeper] [ProxyLeakTask ]- Connection leak detection triggered for oracle.jdbc.driver.T4CConnection#1fc684e on thread main, stack trace follows
java.lang.Exception: Apparent connection leak detected
at com.zaxxer.hikari.HikariDataSource.getConnection(HikariDataSource.java:128)
at org.springframework.jdbc.datasource.DataSourceTransactionManager.doBegin(DataSourceTransactionManager.java:265)
/////Omit part of the log because of the number of characters.
[2022-10-06 18:46:04.475] [DEBUG] [HikariPool-1 connection adder] [HikariPool ]- HikariPool-1 - Cannot acquire connection from data source
java.lang.NullPointerException: null
at java.base/java.lang.StringCoding.encode(StringCoding.java:652)
/////Omit part of the log because of the number of characters.
[2022-10-06 18:46:05.745] [DEBUG] [HikariPool-1 connection adder] [HikariPool ]- HikariPool-1 - Cannot acquire connection from data source
java.lang.NullPointerException: null
at java.base/java.lang.StringCoding.encode(StringCoding.java:652)
[2022-10-06 18:46:32.371] [DEBUG] [HikariPool-1 housekeeper] [HikariPool ]- HikariPool-1 - Pool stats (total=1, active=1, idle=0, waiting=1)
[2022-10-06 18:46:32.371] [DEBUG] [HikariPool-1 housekeeper] [HikariPool ]- HikariPool-1 - Fill pool skipped, pool is at sufficient level.
[2022-10-06 18:46:32.931] [DEBUG] [main] [HikariPool ]- HikariPool-1 - Timeout failure stats (total=1, active=1, idle=0, waiting=0)
[2022-10-06 18:46:32.955] [INFO ] [main] [ProxyLeakTask ]- Previously reported leaked connection oracle.jdbc.driver.T4CConnection#1fc684e on thread main was returned to the pool (unleaked)
[2022-10-06 18:46:32.961] [INFO ] [main] [ConditionEvaluationReportLoggingListener]-
Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
[2022-10-06 18:46:33.010] [ERROR] [main] [SpringApplication ]- Application run failed
java.lang.IllegalStateException: Failed to execute ApplicationRunner
at org.springframework.boot.SpringApplication.callRunner(SpringApplication.java:776)
at org.springframework.boot.SpringApplication.callRunners(SpringApplication.java:763)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:314)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1317)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1306)
at com.springboot.example.ExampleApplication.main(ExampleApplication.java:19)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:49)
at org.springframework.boot.loader.Launcher.launch(Launcher.java:108)
at org.springframework.boot.loader.Launcher.launch(Launcher.java:58)
at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:88)
Caused by: org.springframework.transaction.CannotCreateTransactionException: Could not open JDBC Connection for transaction; nested exception is java.sql.SQLTransientConnectionException: HikariPool-1 - Connection is not available, request timed out after 30004ms.
at org.springframework.jdbc.datasource.DataSourceTransactionManager.doBegin(DataSourceTransactionManager.java:309)
at org.springframework.transaction.support.AbstractPlatformTransactionManager.startTransaction(AbstractPlatformTransactionManager.java:400)
at org.springframework.transaction.support.AbstractPlatformTransactionManager.handleExistingTransaction(AbstractPlatformTransactionManager.java:434)
at org.springframework.transaction.support.AbstractPlatformTransactionManager.getTransaction(AbstractPlatformTransactionManager.java:352)
at org.springframework.transaction.interceptor.TransactionAspectSupport.createTransactionIfNecessary(TransactionAspectSupport.java:595)
at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:382)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:119)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:763)
at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:708)
at com.springboot.example.logging.LoggingService$$EnhancerBySpringCGLIB$$f2e4eeed.logging(<generated>)
at com.springboot.example.logging.LoggingAspect.doLog(LoggingAspect.java:23)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethodWithGivenArgs(AbstractAspectJAdvice.java:634)
at org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethod(AbstractAspectJAdvice.java:617)
at org.springframework.aop.aspectj.AspectJAfterThrowingAdvice.invoke(AspectJAfterThrowingAdvice.java:68)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:175)
at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:763)
at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:123)
at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:388)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:119)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:763)
at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:97)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:763)
at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:708)
at com.springboot.example.DemoService$$EnhancerBySpringCGLIB$$3b65fd43.run(<generated>)
at com.springboot.example.ExampleApplication.lambda$applicationRunner$0(ExampleApplication.java:27)
at org.springframework.boot.SpringApplication.callRunner(SpringApplication.java:773)
... 13 common frames omitted
Caused by: java.sql.SQLTransientConnectionException: HikariPool-1 - Connection is not available, request timed out after 30004ms.
at com.zaxxer.hikari.pool.HikariPool.createTimeoutException(HikariPool.java:696)
at com.zaxxer.hikari.pool.HikariPool.getConnection(HikariPool.java:197)
at com.zaxxer.hikari.pool.HikariPool.getConnection(HikariPool.java:162)
at com.zaxxer.hikari.HikariDataSource.getConnection(HikariDataSource.java:128)
at org.springframework.jdbc.datasource.DataSourceTransactionManager.doBegin(DataSourceTransactionManager.java:265)
... 45 common frames omitted
[2022-10-06 18:46:33.020] [INFO ] [main] [HikariDataSource ]- HikariPool-1 - Shutdown initiated...
[2022-10-06 18:46:33.020] [DEBUG] [main] [HikariPool ]- HikariPool-1 - Before shutdown stats (total=1, active=0, idle=1, waiting=0)
[2022-10-06 18:46:33.023] [DEBUG] [HikariPool-1 connection closer] [PoolBase ]- HikariPool-1 - Closing connection oracle.jdbc.driver.T4CConnection#1fc684e: (connection evicted)
[2022-10-06 18:46:40.826] [DEBUG] [main] [HikariPool ]- HikariPool-1 - After shutdown stats (total=0, active=0, idle=0, waiting=0)
[2022-10-06 18:46:40.826] [INFO ] [main] [HikariDataSource ]- HikariPool-1 - Shutdown completed.
What I checked to solve this problem is as follows.
I checked the settings of the Oracle DB server.
'IDLE_TIME' is set much longer than Hikari maxLifeTime.
'CONNECT_TIME' is unlimit.
We excluded the setting to load all spring bean into Lazy.
The actual project uses Mybatis, but if you look at what happens when you use JdbcTemplate, as in the example...I don't think Mybatis or Lazy loading is the cause.
The local DB and the DB used by the development server are all the same.
I confirmed that there were three sessions connected from Oracle when the problem did not occur and that there was one session connected when the exception occurred. From this, I expected that the connection itself would not be obtained.
What I'm curious about is as follows.
When logging level is set to DEBUG, the message 'Hikari Pool-1 - Canot acquisition connection from data source' appears frequently. Is it related to this part? (And what does this message mean?) Is the network unstable?)
If you look at the entire log,
[2022-10-06 18:46:32.371] [DEBUG] [HikariPool-1 housekeeper] [HikariPool ]- HikariPool-1 - Pool stats (total=1, active=1, idle=0, waiting=1)
[2022-10-06 18:46:32.371] [DEBUG] [HikariPool-1 housekeeper] [HikariPool ]- HikariPool-1 - Fill pool skipped, pool is at sufficient level.
[2022-10-06 18:46:32.931] [DEBUG] [main] [HikariPool ]- HikariPool-1 - Timeout failure stats (total=1, active=1, idle=0, waiting=0)
~~~~
Caused by: org.springframework.transaction.CannotCreateTransactionException: Could not open JDBC Connection for transaction; nested exception is java.sql.SQLTransientConnectionException: HikariPool-1 - Connection is not available, request timed out after 30004ms.
This log remains. Can I say that it was 'waiting=1' and then changed to 'waiting=0' because a timeout exception occurred...?
Is it because you didn't get the connection?
Can't I run the application after the connection pool has three connections set to maximum-pool-size? As far as I know, Hikari's separate threads are out of control because they serve to get Connection.
I'd really appreciate your help.

Setting Max Idle connections with Redis in Spring Boot

I have a Simple Spring Boot 1.5.x REST API application with Redis Caching. I haven't added any custom configuratators and Spring boot automatically gets configured with Jedis. Redis properties are as follows,
spring.cache.type = redis
spring.redis.host = localhost
spring.redis.port = 6379
spring.redis.pool.max-active = 10000
spring.redis.pool.max-idle = 9000
spring.redis.pool.min-idle = 9000
Spring Boot Application Class
#SpringBootApplication
#EnableCaching
public class DemoApplication {
public static void main(String[] args) {
pringApplication.run(DemoApplication.class, args);
}
}
Usage
#RestController
public class UserController {
#Autowired
private UserService userService;
#RequestMapping(value = "/api/users/{id}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
#Cacheable(value = "UserDto", key = "#id")
public UserDto getUser(#PathVariable("id") Integer id){
User u = userService.getUser(id);
UserDto dto = new UserDto(u.getId(), u.getFirstName(), u.getLastName());
return dto;
}
}
If I load an API Endpoint with JMeter and monitor the number of connections maintained to Redis with a netstat continuously I can see the following output.
Netstat command :
while [ true ] ; do sudo netstat -anp | grep EST|grep "127.0.0.1:6379 ESTABLISHED"|wc -l; done
The Output
9000
9000
9006
9016
9031
9019
9000
9015
9005
9027
9046
9011
9005
9013
9011
9054
9010
9094
9061
9091
9036
9010
9004
9003
8935
8826
8387
7910
7122
6631
6524
6420
6300
6190
5776
5482
5475
5293
5187
5118
5081
5020
4992
4817
3996
3485
3582
6504
8964
9031
9136
9000
9025
9035
9000
9000
As you can clearly see the number of connections is getting decreased at the middle and then again rises to 9000 which does not seem like the desirable result.
Additionally I can see the following DEBUG logs.
2018-06-11 14:20:18.010 DEBUG 4151 --- [io-8080-exec-44] o.s.d.redis.core.RedisConnectionUtils : Opening RedisConnection
2018-06-11 14:20:18.012 DEBUG 4151 --- [io-8080-exec-19] o.s.d.redis.core.RedisConnectionUtils : Closing Redis Connection
2018-06-11 14:20:18.015 DEBUG 4151 --- [io-8080-exec-19] o.s.d.redis.core.RedisConnectionUtils : Opening RedisConnection
2018-06-11 14:20:18.015 DEBUG 4151 --- [io-8080-exec-34] o.s.d.redis.core.RedisConnectionUtils : Closing Redis Connection
2018-06-11 14:20:18.015 DEBUG 4151 --- [io-8080-exec-34] o.s.d.redis.core.RedisConnectionUtils : Opening RedisConnection
2018-06-11 14:20:18.015 DEBUG 4151 --- [io-8080-exec-41] o.s.d.redis.core.RedisConnectionUtils : Closing Redis Connection
2018-06-11 14:20:18.015 DEBUG 4151 --- [io-8080-exec-41] o.s.d.redis.core.RedisConnectionUtils : Opening RedisConnection
2018-06-11 14:20:18.015 DEBUG 4151 --- [io-8080-exec-49] o.s.d.redis.core.RedisConnectionUtils : Closing Redis Connection
2018-06-11 14:20:18.016 DEBUG 4151 --- [io-8080-exec-49] o.s.d.redis.core.RedisConnectionUtils : Opening RedisConnection
2018-06-11 14:20:18.016 DEBUG 4151 --- [io-8080-exec-29] o.s.d.redis.core.RedisConnectionUtils : Closing Redis Connection
2018-06-11 14:20:18.016 DEBUG 4151 --- [io-8080-exec-29] o.s.d.redis.core.RedisConnectionUtils : Opening RedisConnection
2018-06-11 14:20:18.016 DEBUG 4151 --- [nio-8080-exec-3] o.s.d.redis.core.RedisConnectionUtils : Closing Redis Connection
2018-06-11 14:20:18.016 DEBUG 4151 --- [nio-8080-exec-3] o.s.d.redis.core.RedisConnectionUtils : Opening RedisConnection
2018-06-11 14:20:18.016 DEBUG 4151 --- [io-8080-exec-51] o.s.d.redis.core.RedisConnectionUtils : Closing Redis Connection
2018-06-11 14:20:18.016 DEBUG 4151 --- [io-8080-exec-51] o.s.d.redis.core.RedisConnectionUtils : Opening RedisConnection
2018-06-11 14:20:18.017 DEBUG 4151 --- [io-8080-exec-45] o.s.d.redis.core.RedisConnectionUtils : Closing Redis Connection
2018-06-11 14:20:18.017 DEBUG 4151 --- [io-8080-exec-45] o.s.d.redis.core.RedisConnectionUtils : Opening RedisConnection
Based on the code in GitHub this happens due to continuous calling of doGetConnection and releaseConnection methods.
Is this desirable? If so what is the explanation for seeing a connection count less than 9000?
If this is not accurate what are the things I can try?

spring-boot-starter-quartz jdbc example

Starting with spring-boot 2.x.x they started offering spring-boot-starter-quartz which is great! Out of the box it does an in-memory store. I want to change it to be a clustered environment but I'm having issues with the configuration I think mostly because I need to put the qrtz_ tables in a different schema than my default data source. Does anyone have an example of using an alternate datasource? I'm currently attempting to set the properties field (as you can see below) but its like they are not being picked up by the configuration bean. Any help is appreciated.
Configuration
spring:
quartz:
job-store-type: jdbc
jdbc:
initialize-schema: never
properties:
scheduler:
instanceName : MyClusteredScheduler
instanceId : AUTO
threadPool:
class : org.quartz.simpl.SimpleThreadPool
threadCount : 25
threadPriority : 5
jobStore:
misfireThreshold : 60000
class : org.quartz.impl.jdbcjobstore.JobStoreTX
driverDelegateClass : org.quartz.impl.jdbcjobstore.StdJDBCDelegate
useProperties : false
dataSource : myDS
tablePrefix : QRTZ_
isClustered : true
clusterCheckinInterval : 20000
dataSource:
myDS:
driver : com.mysql.jdbc.Driver
URL : jdbc:mysql://127.0.0.1:3306/quartz
user : removed
password : removed
maxConnections : 5
validationQuery : select 0 from dual
Output from log
2017-11-06 13:33:02.853 INFO 7082 --- [ main] org.quartz.core.QuartzScheduler : Quartz Scheduler v.2.3.0 created.
2017-11-06 13:33:02.856 INFO 7082 --- [ main] o.s.s.quartz.LocalDataSourceJobStore : Using db table-based data access locking (synchronization).
2017-11-06 13:33:02.858 INFO 7082 --- [ main] o.s.s.quartz.LocalDataSourceJobStore : JobStoreCMT initialized.
2017-11-06 13:33:02.859 INFO 7082 --- [ main] org.quartz.core.QuartzScheduler : Scheduler meta-data: Quartz Scheduler (v2.3.0) 'quartzScheduler' with instanceId 'NON_CLUSTERED'
Scheduler class: 'org.quartz.core.QuartzScheduler' - running locally.
NOT STARTED.
Currently in standby mode.
Number of jobs executed: 0
Using thread pool 'org.quartz.simpl.SimpleThreadPool' - with 10 threads.
Using job-store 'org.springframework.scheduling.quartz.LocalDataSourceJobStore' - which supports persistence. and is not clustered.
2017-11-06 13:33:02.859 INFO 7082 --- [ main] org.quartz.impl.StdSchedulerFactory : Quartz scheduler 'quartzScheduler' initialized from an externally provided properties instance.
2017-11-06 13:33:02.860 INFO 7082 --- [ main] org.quartz.impl.StdSchedulerFactory : Quartz scheduler version: 2.3.0
2017-11-06 13:33:02.860 INFO 7082 --- [ main] org.quartz.core.QuartzScheduler : JobFactory set to: org.springframework.boot.autoconfigure.quartz.AutowireCapableBeanJobFactory#21132086
2017-11-06 13:33:03.214 INFO 7082 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Registering beans for JMX exposure on startup
2017-11-06 13:33:03.216 INFO 7082 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Bean with name 'dataSource' has been autodetected for JMX exposure
2017-11-06 13:33:03.223 INFO 7082 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Located MBean 'dataSource': registering with JMX server as MBean [com.zaxxer.hikari:name=dataSource,type=HikariDataSource]
2017-11-06 13:33:03.227 INFO 7082 --- [ main] o.s.c.support.DefaultLifecycleProcessor : Starting beans in phase 2147483647
2017-11-06 13:33:03.227 INFO 7082 --- [ main] o.s.s.quartz.SchedulerFactoryBean : Starting Quartz Scheduler now
2017-11-06 13:33:05.250 WARN 7082 --- [ main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.context.ApplicationContextException: Failed to start bean 'quartzScheduler'; nested exception is org.springframework.scheduling.SchedulingException: Could not start Quartz Scheduler; nested exception is org.quartz.SchedulerConfigException: Failure occured during job recovery. [See nested exception: org.quartz.impl.jdbcjobstore.LockException: Failure obtaining db row lock: No database selected [See nested exception: java.sql.SQLException: No database selected]]
2017-11-06 13:33:05.250 INFO 7082 --- [ main] o.s.s.quartz.SchedulerFactoryBean : Shutting down Quartz Scheduler
2017-11-06 13:33:05.251 INFO 7082 --- [ main] org.quartz.core.QuartzScheduler : Scheduler quartzScheduler_$_NON_CLUSTERED shutting down.
2017-11-06 13:33:05.251 INFO 7082 --- [ main] org.quartz.core.QuartzScheduler : Scheduler quartzScheduler_$_NON_CLUSTERED paused.
2017-11-06 13:33:05.251 INFO 7082 --- [ main] org.quartz.core.QuartzScheduler : Scheduler quartzScheduler_$_NON_CLUSTERED shutdown complete.
2017-11-06 13:33:05.252 INFO 7082 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Unregistering JMX-exposed beans on shutdown
2017-11-06 13:33:05.253 INFO 7082 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Unregistering JMX-exposed beans
2017-11-06 13:33:05.254 INFO 7082 --- [ main] j.LocalContainerEntityManagerFactoryBean : Closing JPA EntityManagerFactory for persistence unit 'default'
2017-11-06 13:33:05.255 INFO 7082 --- [ main] com.zaxxer.hikari.HikariDataSource : testdb - Shutdown initiated...
2017-11-06 13:33:05.264 INFO 7082 --- [ main] com.zaxxer.hikari.HikariDataSource : testdb - Shutdown completed.
2017-11-06 13:33:05.265 INFO 7082 --- [ main] o.apache.catalina.core.StandardService : Stopping service [Tomcat]
2017-11-06 13:33:05.283 INFO 7082 --- [ main] utoConfigurationReportLoggingInitializer :
Error starting ApplicationContext. To display the auto-configuration report re-run your application with 'debug' enabled.
2017-11-06 13:33:05.293 ERROR 7082 --- [ main] o.s.boot.SpringApplication : Application startup failed
org.springframework.context.ApplicationContextException: Failed to start bean 'quartzScheduler'; nested exception is org.springframework.scheduling.SchedulingException: Could not start Quartz Scheduler; nested exception is org.quartz.SchedulerConfigException: Failure occured during job recovery. [See nested exception: org.quartz.impl.jdbcjobstore.LockException: Failure obtaining db row lock: No database selected [See nested exception: java.sql.SQLException: No database selected]]
at org.springframework.context.support.DefaultLifecycleProcessor.doStart(DefaultLifecycleProcessor.java:186) ~[spring-context-5.0.0.RELEASE.jar:5.0.0.RELEASE]
at org.springframework.context.support.DefaultLifecycleProcessor.access$200(DefaultLifecycleProcessor.java:52) ~[spring-context-5.0.0.RELEASE.jar:5.0.0.RELEASE]
at org.springframework.context.support.DefaultLifecycleProcessor$LifecycleGroup.start(DefaultLifecycleProcessor.java:358) ~[spring-context-5.0.0.RELEASE.jar:5.0.0.RELEASE]
at org.springframework.context.support.DefaultLifecycleProcessor.startBeans(DefaultLifecycleProcessor.java:159) ~[spring-context-5.0.0.RELEASE.jar:5.0.0.RELEASE]
at org.springframework.context.support.DefaultLifecycleProcessor.onRefresh(DefaultLifecycleProcessor.java:123) ~[spring-context-5.0.0.RELEASE.jar:5.0.0.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.finishRefresh(AbstractApplicationContext.java:884) ~[spring-context-5.0.0.RELEASE.jar:5.0.0.RELEASE]
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.finishRefresh(ServletWebServerApplicationContext.java:143) ~[spring-boot-2.0.0.M5.jar:2.0.0.M5]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:552) ~[spring-context-5.0.0.RELEASE.jar:5.0.0.RELEASE]
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:122) ~[spring-boot-2.0.0.M5.jar:2.0.0.M5]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:750) [spring-boot-2.0.0.M5.jar:2.0.0.M5]
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:386) [spring-boot-2.0.0.M5.jar:2.0.0.M5]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:327) [spring-boot-2.0.0.M5.jar:2.0.0.M5]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1245) [spring-boot-2.0.0.M5.jar:2.0.0.M5]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1233) [spring-boot-2.0.0.M5.jar:2.0.0.M5]
at com.tci.reader.incident.parser.IncidentParserApplication.main(IncidentParserApplication.java:18) [classes/:na]
Caused by: org.springframework.scheduling.SchedulingException: Could not start Quartz Scheduler; nested exception is org.quartz.SchedulerConfigException: Failure occured during job recovery. [See nested exception: org.quartz.impl.jdbcjobstore.LockException: Failure obtaining db row lock: No database selected [See nested exception: java.sql.SQLException: No database selected]]
at org.springframework.scheduling.quartz.SchedulerFactoryBean.start(SchedulerFactoryBean.java:738) ~[spring-context-support-5.0.0.RELEASE.jar:5.0.0.RELEASE]
at org.springframework.context.support.DefaultLifecycleProcessor.doStart(DefaultLifecycleProcessor.java:183) ~[spring-context-5.0.0.RELEASE.jar:5.0.0.RELEASE]
... 14 common frames omitted
Caused by: org.quartz.SchedulerConfigException: Failure occured during job recovery.
at org.quartz.impl.jdbcjobstore.JobStoreSupport.schedulerStarted(JobStoreSupport.java:697) ~[quartz-2.3.0.jar:na]
at org.quartz.core.QuartzScheduler.start(QuartzScheduler.java:539) ~[quartz-2.3.0.jar:na]
at org.quartz.impl.StdScheduler.start(StdScheduler.java:142) ~[quartz-2.3.0.jar:na]
at org.springframework.scheduling.quartz.SchedulerFactoryBean.startScheduler(SchedulerFactoryBean.java:664) ~[spring-context-support-5.0.0.RELEASE.jar:5.0.0.RELEASE]
at org.springframework.scheduling.quartz.SchedulerFactoryBean.start(SchedulerFactoryBean.java:735) ~[spring-context-support-5.0.0.RELEASE.jar:5.0.0.RELEASE]
... 15 common frames omitted
Caused by: org.quartz.impl.jdbcjobstore.LockException: Failure obtaining db row lock: No database selected
at org.quartz.impl.jdbcjobstore.StdRowLockSemaphore.executeSQL(StdRowLockSemaphore.java:157) ~[quartz-2.3.0.jar:na]
at org.quartz.impl.jdbcjobstore.DBSemaphore.obtainLock(DBSemaphore.java:113) ~[quartz-2.3.0.jar:na]
at org.quartz.impl.jdbcjobstore.JobStoreSupport.executeInNonManagedTXLock(JobStoreSupport.java:3842) ~[quartz-2.3.0.jar:na]
at org.quartz.impl.jdbcjobstore.JobStoreSupport.recoverJobs(JobStoreSupport.java:839) ~[quartz-2.3.0.jar:na]
at org.quartz.impl.jdbcjobstore.JobStoreSupport.schedulerStarted(JobStoreSupport.java:695) ~[quartz-2.3.0.jar:na]
... 19 common frames omitted
Caused by: java.sql.SQLException: No database selected
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:964) ~[mysql-connector-java-5.1.44.jar:5.1.44]
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3973) ~[mysql-connector-java-5.1.44.jar:5.1.44]
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3909) ~[mysql-connector-java-5.1.44.jar:5.1.44]
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2527) ~[mysql-connector-java-5.1.44.jar:5.1.44]
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2680) ~[mysql-connector-java-5.1.44.jar:5.1.44]
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2487) ~[mysql-connector-java-5.1.44.jar:5.1.44]
at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1858) ~[mysql-connector-java-5.1.44.jar:5.1.44]
at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:1966) ~[mysql-connector-java-5.1.44.jar:5.1.44]
at com.zaxxer.hikari.pool.ProxyPreparedStatement.executeQuery(ProxyPreparedStatement.java:52) ~[HikariCP-2.7.2.jar:na]
at com.zaxxer.hikari.pool.HikariProxyPreparedStatement.executeQuery(HikariProxyPreparedStatement.java) ~[HikariCP-2.7.2.jar:na]
at org.quartz.impl.jdbcjobstore.StdRowLockSemaphore.executeSQL(StdRowLockSemaphore.java:96) ~[quartz-2.3.0.jar:na]
... 23 common frames omitted
You have to use the correct properties for the quartz properties.
Your properties are missing ...org.quartz...
For the none-yml notation, try this for the threadCount:
spring.quartz.properties.org.quartz.threadPool.threadCount=25
For the yml notation:
Add two layers under the 'properties', e.g.
spring:
quartz:
properties:
org:
quartz:
threadPool:
threadCount : 25
Application.yml file:
spring:
jpa:
hibernate:
ddl-auto: none
datasource:
url: jdbc:mysql://127.0.0.1:3306/Quartz
username: Your Username
password: Your Password
quartz:
scheduler:
instanceName: Scheduler
threadPool:
class: org.quartz.simpl.SimpleThreadPool
threadCount: 3
context:
key:
QuartzTopic: QuartzPorperties
jobStore:
driver: com.mysql.jdbc.Driver
class: org.quartz.impl.jdbcjobstore.JobStoreTX
driverDelegateClass: org.quartz.impl.jdbcjobstore.StdJDBCDelegate
misfireThreshold: 6000
tablePrefix: QRTZ_
Next create a Configuration class which reads these properties from the yml file and then creates a Scheduler Bean:
#Configuration
public class SchedulerConfig {
private final Logger logger = LoggerFactory.getLogger(this.getClass());
#Value("${quartz.scheduler.instanceName}")
private String instanceName;
#Value("${quartz.threadPool.class}")
private String threadClass;
#Value("${quartz.threadPool.threadCount}")
private String threadCount;
#Value("${quartz.context.key.QuartzTopic}")
private String quartzTopic;
#Value("${quartz.jobStore.class}")
private String jobStoreClass;
#Value("${quartz.jobStore.driverDelegateClass}")
private String driverDelegateClass;
#Value("${quartz.jobStore.misfireThreshold}")
private String misfireThreshold;
#Value("${quartz.jobStore.tablePrefix}")
private String tablePrefix;
#Value("${quartz.jobStore.driver}")
private String dataSourceDriver;
#Value("${spring.datasource.url}")
private String dataSourceUrl;
#Value("${spring.datasource.username}")
private String dataSourceUsername;
#Value("${spring.datasource.password}")
private String databasePassword;
#Bean({"Scheduler"})
public Scheduler getScheduler() {
Scheduler scheduler = null;
try {
StdSchedulerFactory factory = new StdSchedulerFactory();
Properties props = new Properties();
props.put("org.quartz.scheduler.instanceName", instanceName);
props.put("org.quartz.threadPool.class", threadClass);
props.put("org.quartz.threadPool.threadCount", threadCount);
props.put("org.quartz.context.key.QuartzTopic", quartzTopic);
props.put("org.quartz.jobStore.class", jobStoreClass);
props.put("org.quartz.jobStore.driverDelegateClass", driverDelegateClass);
props.put("quartz.jobStore.misfireThreshold", misfireThreshold);
props.put("org.quartz.jobStore.tablePrefix", tablePrefix);
props.put("org.quartz.jobStore.dataSource", "myDS");
props.put("org.quartz.dataSource.myDS.driver", dataSourceDriver);
props.put("org.quartz.dataSource.myDS.URL", dataSourceUrl);
props.put("org.quartz.dataSource.myDS.user", dataSourceUsername);
props.put("org.quartz.dataSource.myDS.password", databasePassword);
props.put("org.quartz.dataSource.myDS.maxConnections", "10");
factory.initialize(props);
scheduler = factory.getScheduler();
scheduler.start();
scheduler.resumeAll(); // This is to resume the entire scheduler when a new build is deployed
} catch (Exception e) {
logger.error("{} - SchedulerConfig class - getScheduler() - Error creating Scheduler instance: {}",
appName, e);
}
return scheduler;
}
}
Finally, use the Bean as below in any class you want:
#Autowired
private Scheduler scheduler;

Update native query is too slow

I am using Hibernate with native query to update a field in a table with 17000 rows in Oracle.
When I execute the query on Toad, it takes 0.5s to be executed and with the below code no finish ever.
Query query = em.createNativeQuery("UPDATE table SET field= LEAST(NUMERADOR/DENOMINADO, ? )");
query.setParameter(1, value);
query.executeUpdate();
This is the trace:
10-08 14:15:59 DEBUG JpaTransactionManager - Creating new transaction with name [es.package.app.repository.jpa.JPAValorMaximo.update]: PROPAGATION_REQUIRED,ISOLATION_DEFAULT; ''
10-08 14:15:59 DEBUG JpaTransactionManager - Opened new EntityManager [org.hibernate.ejb.EntityManagerImpl#405264e8] for JPA transaction
10-08 14:15:59 DEBUG AbstractTransactionImpl - begin
10-08 14:15:59 DEBUG LogicalConnectionImpl - Obtaining JDBC connection
10-08 14:15:59 DEBUG LogicalConnectionImpl - Obtained JDBC connection
10-08 14:15:59 DEBUG JdbcTransaction - initial autocommit status: true
10-08 14:15:59 DEBUG JdbcTransaction - disabling autocommit
10-08 14:15:59 DEBUG JpaTransactionManager - Exposing JPA transaction as JDBC transaction [org.springframework.orm.jpa.vendor.HibernateJpaDialect$HibernateConnectionHandle#1bbb3b9e]
10-08 14:15:59 DEBUG SQL - UPDATE table SET field= LEAST(NUMERADOR/DENOMINADO, ? )
Hibernate: UPDATE table SET field= LEAST(NUMERADOR/DENOMINADO, ? )
thanks

Resources