日志警告: 检测到线程饥饿或时钟跳跃(管家 delta = springHikariConnectionPool)

我正在使用 HikariCP 2.4.6,在 Tomcat 8启动时,我收到一条警告消息:

01-Aug-2016 11:18:01.599 INFO [RMI TCP Connection(4)-127.0.0.1] org.apache.catalina.core.ApplicationContext.log Initializing Spring FrameworkServlet 'Spring MVC Dispatcher Servlet'
[2016-08-01 11:18:01,654] Artifact blueberry:war exploded: Artifact is deployed successfully
[2016-08-01 11:18:01,655] Artifact blueberry:war exploded: Deploy took 33,985 milliseconds
Aug 01 2016 11:26:52.802 AM [DEV] (HikariPool.java:614)
WARN : com.zaxxer.hikari.pool.HikariPool - 9m13s102ms - Thread starvation or clock leap detected (housekeeper delta=springHikariConnectionPool).

我没有看到任何其他错误或问题从数据库读/写。这有什么好担心的吗?我到处找过了,没找到。

我们也使用 Hibernate 4.3.8。Final over MySQL 5和支持 Spring4.1.0的 MySQL 5.1.39连接器。释放。我们正在努力升级到 Hibernate 5,并将看到这是否会消失,但不知道这是否会有影响。

137887 次浏览

There's a good rundown of why clock leap detections might legitimately occur. To quote the external link by Brett Woolridge:

This runs on the housekeeper thread, which executes every 30 seconds. If you are on Mac OS X, the clockSource is System.currentTimeMillis(), any other platform the clockSource is System.nanoTime(). Both in theory are monotonically increasing, but various things can affect that such as NTP servers. Most OSes are designed to handle backward NTP time adjustments to preserve the illusion of the forward flow of time.

This code is saying, if time moves backwards (now < previous), or if time has "jumped forward" more than two housekeeping periods (more than 60 seconds), then something strange is likely going on.

A couple of things might be going on:

  1. You could be running in a virtual container (VMWare, AWS, etc.) that for some reason is doing a particularly poor job of maintaining the illusion of the forward flow of time.

  2. Because other things occur in the housekeeper thread -- specifically, closing idle connections -- it is possible that for some reason closing connections is blocking the housekeeper thread for more than two housekeeping periods (60 seconds).

  3. The server is so busy, with all CPUs pegged, that thread starvation is occurring, which is preventing the housekeeper thread from running for more than two housekeeping periods.

Considering these, maybe you can provide additional context.

EDIT: Note that this is based on HikariCP 2.4.1 code. Make sure you are running the most up-to-date version available.

(It also looks like the parameters were updated on the warning statement in the latest code.)

One other reason if you run the app locally and the computer went to sleep it happens. In that case, you don't need to do anything configure wise.

I was facing this issue in a spring boot MySQL work in an AWS T2 micro 1GB RAM instance . After an hours effort and nothing moving forward , observed that CPU usage was going towards 100% . Then I made the instance T2 medium having 4 GB RAM and 2 vCPUs. After that I faced no problem

I was having the same issue when I ran my spring boot application with microservices on the Linux machine. After some investigation found out that, the server has only 8GB memory. Increasing Memory(RAM) to 16GB fixed my issue.

I was facing this issue because of an infinite loop in my hashCode method of the Entity.

Two entities had OneToMany relationship and I was using lombok @Data annotation which generates equals and hashcode implementation itself by calling hashCode() method for each attribute which was causing the infinite loop.

Another reason why this is happening is due to excessive garbage collection, when garbage collection was running for a longer time within two executions of housekeeping thread, trying to free up some memory(e.g exactly when an application thread was running a 'select' query). Since the GC was blocking all application threads including the housekeeping thread, as such my suspicion is that the clock "leapt" due to that.

If this is happening at the start of your spring-boot application

org.springframework.data.repository.config.RepositoryConfigurationDelegate :
Bootstrapping Spring Data JPA repositories in DEFERRED mode.

then run your application with the following Program Arguments

--spring.data.jpa.repositories.bootstrap_mode=default