Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/348.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 为什么冬眠一段时间后会变慢?_Java_Spring_Hibernate_Specifications - Fatal编程技术网

Java 为什么冬眠一段时间后会变慢?

Java 为什么冬眠一段时间后会变慢?,java,spring,hibernate,specifications,Java,Spring,Hibernate,Specifications,在执行相同的查询(只读)时,hibernate会减慢速度的原因是什么 日志: 从日志中可以看到,执行时间增加了十倍,可以配置Hibernate c3p0以提高效率。 连接池有利于提高性能,因为它可以防止Java应用程序在每次与数据库交互时创建连接,并将打开和关闭连接的成本降至最低 请尝试此链接以在应用程序中配置hibernate c3p0: 是不是数据库更忙了?数据库不忙了。之后,它会减速并保持这种状态(前10次执行时间约为100ms,然后每隔500ms)。请求发送的速度有多快?可能是数据库阻止

在执行相同的查询(只读)时,hibernate会减慢速度的原因是什么

日志:


从日志中可以看到,执行时间增加了十倍,可以配置Hibernate c3p0以提高效率。 连接池有利于提高性能,因为它可以防止Java应用程序在每次与数据库交互时创建连接,并将打开和关闭连接的成本降至最低

请尝试此链接以在应用程序中配置hibernate c3p0:


是不是数据库更忙了?数据库不忙了。之后,它会减速并保持这种状态(前10次执行时间约为100ms,然后每隔500ms)。请求发送的速度有多快?可能是数据库阻止了快速的后续请求。spring应用程序似乎不太可能让它慢下来。在测试运行的同时,尝试从同一IP手动查询数据库,看看它是否慢。我这样做了,执行时间大约为30毫秒,它甚至不会增加一次到30毫秒以上,可能就是这样,
   368588 nanoseconds spent acquiring 1 JDBC connections;
   0 nanoseconds spent releasing 0 JDBC connections;
   158339 nanoseconds spent preparing 3 JDBC statements;
   33855736 nanoseconds spent executing 3 JDBC statements;
   0 nanoseconds spent executing 0 JDBC batches;
   0 nanoseconds spent performing 0 L2C puts;
   0 nanoseconds spent performing 0 L2C hits;
   0 nanoseconds spent performing 0 L2C misses;
   0 nanoseconds spent executing 0 flushes (flushing a total of 0 entities and 0 collections);
   9437 nanoseconds spent executing 3 partial-flushes (flushing a total of 0 entities and 0 collections)
}
2020-03-24 09:02:54.488  INFO 12024 --- [io-8064-exec-10] i.StatisticalLoggingSessionEventListener : Session Metrics {
   44640 nanoseconds spent acquiring 1 JDBC connections;
   0 nanoseconds spent releasing 0 JDBC connections;
   134337 nanoseconds spent preparing 3 JDBC statements;
   33256438 nanoseconds spent executing 3 JDBC statements;
   0 nanoseconds spent executing 0 JDBC batches;
   0 nanoseconds spent performing 0 L2C puts;
   0 nanoseconds spent performing 0 L2C hits;
   0 nanoseconds spent performing 0 L2C misses;
   0 nanoseconds spent executing 0 flushes (flushing a total of 0 entities and 0 collections);
   9156 nanoseconds spent executing 3 partial-flushes (flushing a total of 0 entities and 0 collections)
}
2020-03-24 09:02:56.143  INFO 12024 --- [nio-8064-exec-1] i.StatisticalLoggingSessionEventListener : Session Metrics {
   47060 nanoseconds spent acquiring 1 JDBC connections;
   0 nanoseconds spent releasing 0 JDBC connections;
   123461 nanoseconds spent preparing 3 JDBC statements;
   468759882 nanoseconds spent executing 3 JDBC statements;
   0 nanoseconds spent executing 0 JDBC batches;
   0 nanoseconds spent performing 0 L2C puts;
   0 nanoseconds spent performing 0 L2C hits;
   0 nanoseconds spent performing 0 L2C misses;
   0 nanoseconds spent executing 0 flushes (flushing a total of 0 entities and 0 collections);
   9680 nanoseconds spent executing 3 partial-flushes (flushing a total of 0 entities and 0 collections)
}