为什么过一会儿,Hibernate变慢?

执行相同查询(只读)后,休眠速度变慢的原因可能是什么?

日志:

   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)
}

从日志中可以看到,执行时间增加了十倍

hongfuxiao 回答:为什么过一会儿,Hibernate变慢?

可以配置休眠c3p0以提高效率。 连接池提高了性能,因为它防止Java应用程序每次与数据库交互时创建连接,并最大程度地减少了打开和关闭连接的成本。

尝试使用此链接在您的应用程序中配置休眠c3p0:

https://mkyong.com/hibernate/how-to-configure-the-c3p0-connection-pool-in-hibernate/

本文链接:https://www.f2er.com/2591956.html

大家都在问