{"id":504415,"date":"2026-11-23T14:27:08","date_gmt":"2026-11-23T11:27:08","guid":{"rendered":"https:\/\/savepearlharbor.com\/?p=504415"},"modified":"2026-11-23T14:27:08","modified_gmt":"2026-11-23T11:27:08","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=504415","title":{"rendered":"\u0414\u0435\u043b\u043e \u043e \u0437\u0430\u0432\u0438\u0441\u0448\u0435\u043c \u043f\u0443\u043b\u0435: @Transactional, connection leak \u0438 deadlock \u0432 Spring Boot"},"content":{"rendered":"<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p><em>\u0421\u0435\u0440\u0432\u0438\u0441 \u043f\u043e \u0432\u0441\u0435\u043c \u0432\u043d\u0435\u0448\u043d\u0438\u043c \u043f\u0440\u0438\u0437\u043d\u0430\u043a\u0430\u043c \u0436\u0438\u0432: health check \u0437\u0435\u043b\u0451\u043d\u044b\u0439, \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0440 \u043f\u043e\u0447\u0442\u0438 \u043f\u0440\u043e\u0441\u0442\u0430\u0438\u0432\u0430\u0435\u0442, \u0432 \u043b\u043e\u0433\u0430\u0445 \u0442\u0438\u0445\u043e. \u0422\u043e\u043b\u044c\u043a\u043e HTTP-\u0437\u0430\u043f\u0440\u043e\u0441\u044b \u043f\u0435\u0440\u0435\u0441\u0442\u0430\u043b\u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0442\u044c\u0441\u044f. \u041d\u0438\u0436\u0435 \u2014 \u0440\u0430\u0437\u0431\u043e\u0440 \u043d\u043e\u0447\u043d\u043e\u0433\u043e \u0438\u043d\u0446\u0438\u0434\u0435\u043d\u0442\u0430 \u0441 \u043f\u0443\u043b\u043e\u043c HikariCP, \u043d\u0435\u043e\u0436\u0438\u0434\u0430\u043d\u043d\u0430\u044f \u0437\u0430\u0441\u0430\u0434\u0430 \u0441 Open Session In View \u0438 \u0435\u0449\u0451 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0442\u0438\u043f\u043e\u0432\u044b\u0445 \u0433\u0440\u0430\u0431\u043b\u0435\u0439 \u0441 \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u044f\u043c\u0438 \u0432 Spring Boot, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u044f \u0441\u043e\u0431\u0440\u0430\u043b \u0432 \u043e\u0434\u0438\u043d \u0434\u0435\u043c\u043e-\u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0439.<\/em><\/p>\n<hr\/>\n<h3>\u0427\u0435\u0442\u0432\u0435\u0440\u0433, 23:10<\/h3>\n<p>\u041f\u043e\u0441\u043b\u0435 \u043f\u0440\u043e\u0448\u043b\u043e\u0439 \u0438\u0441\u0442\u043e\u0440\u0438\u0438 \u0441 <a href=\"https:\/\/habr.com\/ru\/articles\/1046239\/\" rel=\"noopener nofollow\">\u043c\u043e\u043b\u0447\u0430\u043b\u0438\u0432\u043e\u0439 JVM<\/a> \u043c\u043e\u043d\u0438\u0442\u043e\u0440\u0438\u043d\u0433 \u0431\u043e\u043b\u0435\u0435-\u043c\u0435\u043d\u0435\u0435 \u043f\u0440\u0438\u0432\u0435\u043b\u0438 \u0432 \u043f\u043e\u0440\u044f\u0434\u043e\u043a: Prometheus \u0441\u043e\u0431\u0438\u0440\u0430\u0435\u0442 \u043c\u0435\u0442\u0440\u0438\u043a\u0438, \u0432 Grafana \u0435\u0441\u0442\u044c \u0434\u0430\u0448\u0431\u043e\u0440\u0434\u044b, \u0430\u043b\u0435\u0440\u0442\u044b \u043d\u0435 \u0434\u0451\u0440\u0433\u0430\u044e\u0442 \u043f\u043e \u043c\u0435\u043b\u043e\u0447\u0430\u043c.<\/p>\n<p>\u0412 \u0447\u0435\u0442\u0432\u0435\u0440\u0433 \u0432 23:10 \u0432 \u0440\u0430\u0431\u043e\u0447\u0438\u0439 \u0447\u0430\u0442 \u043d\u0430\u043f\u0438\u0441\u0430\u043b \u0414\u0430\u043d\u044f, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0434\u0435\u0436\u0443\u0440\u0438\u043b \u043d\u0430 \u0442\u043e\u0439 \u043d\u0435\u0434\u0435\u043b\u0435:<\/p>\n<blockquote>\n<p>\u00ab\u0421\u0435\u0440\u0432\u0438\u0441 \u043b\u0435\u0436\u0438\u0442, \u0445\u043e\u0442\u044f k8s \u0441\u0447\u0438\u0442\u0430\u0435\u0442 \u0435\u0433\u043e \u0436\u0438\u0432\u044b\u043c. p99 \u0443\u043b\u0435\u0442\u0435\u043b \u0432 \u043f\u043e\u0442\u043e\u043b\u043e\u043a, \u0441\u0440\u0430\u0431\u043e\u0442\u0430\u043b ConnectionTimeouts. \u0417\u0430\u0448\u0451\u043b \u0432 \u043f\u043e\u0441\u0442\u0433\u0440\u0435\u0441 \u0440\u0443\u043a\u0430\u043c\u0438 \u2014 \u0431\u0430\u0437\u0430 \u043f\u043e\u0447\u0442\u0438 \u043f\u0443\u0441\u0442\u0430\u044f, \u043e\u0431\u044b\u0447\u043d\u044b\u0435 \u0441\u0435\u043b\u0435\u043a\u0442\u044b \u043e\u0442\u0434\u0430\u044e\u0442\u0441\u044f \u0437\u0430 \u043f\u0430\u0440\u0443 \u043c\u0441\u00bb.<\/p>\n<\/blockquote>\n<p>\u0421\u0442\u0435\u043a \u043d\u0430 \u0441\u0442\u0435\u043d\u0434\u0435: Spring Boot 3.2.1, Hibernate 6.4.1.Final, HikariCP 5.0.1, PostgreSQL 16.15, JDK 17.0.21 (\u0437\u0430\u0431\u0435\u0433\u0430\u044f \u0432\u043f\u0435\u0440\u0451\u0434 \u2014 \u0433\u043b\u0430\u0432\u043d\u044b\u0439 \u0441\u044e\u0440\u043f\u0440\u0438\u0437 \u0441 \u0434\u0435\u0444\u043e\u043b\u0442\u043d\u044b\u043c <code>open-in-view: true<\/code> \u043d\u0438\u043a\u0443\u0434\u0430 \u043d\u0435 \u0434\u0435\u043b\u0441\u044f \u0438 \u0432 \u0431\u043e\u043b\u0435\u0435 \u0441\u0432\u0435\u0436\u0438\u0445 \u0432\u0435\u0440\u0441\u0438\u044f\u0445 Spring Boot).<\/p>\n<p>\u041f\u0435\u0440\u0432\u044b\u0435 \u043c\u0438\u043d\u0443\u0442 \u0434\u0432\u0430\u0434\u0446\u0430\u0442\u044c \u044f \u043f\u043e \u0441\u0442\u0430\u0440\u043e\u0439 \u043f\u0440\u0438\u0432\u044b\u0447\u043a\u0435 \u0438\u0441\u043a\u0430\u043b \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0443 \u0432\u0435\u0437\u0434\u0435, \u043a\u0440\u043e\u043c\u0435 \u043e\u0447\u0435\u0432\u0438\u0434\u043d\u043e\u0433\u043e. \u0421\u043d\u0430\u0447\u0430\u043b\u0430 \u0433\u0440\u0435\u0448\u0438\u043b \u043d\u0430 \u0432\u0435\u0447\u0435\u0440\u043d\u0438\u0439 \u0440\u0435\u043b\u0438\u0437 \u0438 \u043f\u043e\u043b\u0435\u0437 \u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u043f\u0430\u0443\u0437\u044b GC \u2014 \u0442\u0430\u043c \u0440\u043e\u0432\u043d\u043e. \u041f\u043e\u0442\u043e\u043c \u043e\u0442\u043a\u0440\u044b\u043b pg_stat_statements \u0432 \u043d\u0430\u0434\u0435\u0436\u0434\u0435 \u043f\u043e\u0439\u043c\u0430\u0442\u044c \u0441\u0432\u0435\u0436\u0438\u0439 SELECT \u0431\u0435\u0437 \u0438\u043d\u0434\u0435\u043a\u0441\u0430 \u2014 CPU \u0443 \u0431\u0430\u0437\u044b \u043e\u043a\u043e\u043b\u043e 10%, \u043c\u0435\u0434\u043b\u0435\u043d\u043d\u044b\u0445 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u043d\u0435\u0442. \u041f\u0440\u043e\u0432\u0435\u0440\u0438\u043b \u0441\u0435\u0442\u044c \u0434\u043e \u0431\u0430\u0437\u044b \u0438 \u0443\u0436\u0435 \u0441\u043e\u0431\u0438\u0440\u0430\u043b\u0441\u044f \u043e\u0431\u0432\u0438\u043d\u0438\u0442\u044c \u0432\u043e \u0432\u0441\u0451\u043c k8s, \u043d\u043e \u0432\u0441\u0451-\u0442\u0430\u043a\u0438 \u043e\u0442\u043a\u0440\u044b\u043b \u043f\u0430\u043d\u0435\u043b\u044c HikariCP \u0432 Grafana.<\/p>\n<p>\u0412 \u043f\u0440\u043e\u0434\u0435 \u043f\u0443\u043b \u043d\u0430\u0441\u0442\u0440\u043e\u0435\u043d \u043d\u0430 15 \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0439. \u0412 \u0434\u0435\u043c\u043e-\u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0438 \u043a \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u044f \u0443\u0440\u0435\u0437\u0430\u043b \u0435\u0433\u043e \u0434\u043e 5 \u0441 <code>connection-timeout: 5000<\/code>, \u0447\u0442\u043e\u0431\u044b \u043d\u0435 \u0433\u043e\u0440\u043e\u0434\u0438\u0442\u044c \u043d\u0430\u0433\u0440\u0443\u0437\u043e\u0447\u043d\u044b\u0439 \u0433\u0435\u043d\u0435\u0440\u0430\u0442\u043e\u0440 \u0438 \u043b\u043e\u043c\u0430\u0442\u044c \u0432\u0441\u0451 \u043f\u0430\u0440\u043e\u0439 <code>curl<\/code>. \u041a\u043e\u0433\u0434\u0430 \u0432\u0441\u0435 \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f \u0437\u0430\u043d\u044f\u0442\u044b, \u043d\u043e\u0432\u044b\u0435 \u043f\u043e\u0442\u043e\u043a\u0438 \u0432\u0441\u0442\u0430\u044e\u0442 \u0432 \u043e\u0447\u0435\u0440\u0435\u0434\u044c, \u0436\u0434\u0443\u0442 \u0442\u0430\u0439\u043c\u0430\u0443\u0442 \u0438 \u043f\u0430\u0434\u0430\u044e\u0442 \u0441 <code>SQLTransientConnectionException<\/code>.<\/p>\n<hr\/>\n<h3>\u041e\u0441\u043c\u043e\u0442\u0440: \u043c\u0435\u0442\u0440\u0438\u043a\u0438, jstack \u0438 pg_stat_activity<\/h3>\n<p>\u0412 Grafana \u043e\u0442\u043a\u0440\u044b\u0432\u0430\u0435\u043c \u043f\u0430\u043d\u0435\u043b\u044c \u043f\u0443\u043b\u0430 \u2014 \u0435\u0449\u0451 \u0441 \u043f\u0440\u043e\u0448\u043b\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0438 \u043e\u043d\u0430 \u0443 \u043d\u0430\u0441 \u0442\u0430\u043a \u0438 \u043d\u0430\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f Bar \u2018U Hikari\u2019, \u043f\u043e \u0430\u043d\u0430\u043b\u043e\u0433\u0438\u0438 \u0441 \u0431\u0430\u0440\u043e\u043c \u043d\u0430 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0441\u0442\u043e\u043b\u0438\u043a\u043e\u0432, \u0433\u0434\u0435 \u0431\u0430\u0440\u043c\u0435\u043d \u0441\u0442\u043e\u0438\u0442 \u0441 \u0441\u0435\u043a\u0443\u043d\u0434\u043e\u043c\u0435\u0440\u043e\u043c. \u0421\u043c\u043e\u0442\u0440\u0438\u043c \u043d\u0430 \u0447\u0435\u0442\u044b\u0440\u0435 \u0431\u0430\u0437\u043e\u0432\u044b\u0435 \u043c\u0435\u0442\u0440\u0438\u043a\u0438:<\/p>\n<pre><code>hikaricp_connections_activehikaricp_connections_idlehikaricp_connections_pendinghikaricp_connections_timeout_total<\/code><div class=\"code-explainer\"><a href=\"https:\/\/sourcecraft.dev\/\" class=\"tm-button code-explainer__link\" style=\"visibility: hidden;\"><span class=\"sc-logo-wrapper\"><\/span><\/a><\/div><\/pre>\n<p>\u0412 \u043d\u043e\u0440\u043c\u0430\u043b\u044c\u043d\u043e\u0439 \u0440\u0430\u0431\u043e\u0442\u0435 <code>pending<\/code> \u043f\u0440\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u0432\u0441\u0435\u0433\u0434\u0430 \u0440\u0430\u0432\u0435\u043d \u043d\u0443\u043b\u044e (\u043a\u043e\u0440\u043e\u0442\u043a\u0438\u0435 \u0432\u0441\u043f\u043b\u0435\u0441\u043a\u0438 \u043d\u0430 \u043c\u0438\u043b\u043b\u0438\u0441\u0435\u043a\u0443\u043d\u0434\u044b \u043f\u043e\u0434 \u043d\u0430\u0433\u0440\u0443\u0437\u043a\u043e\u0439 \u043d\u043e\u0440\u043c\u0430\u043b\u044c\u043d\u044b, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0432 \u0430\u043b\u0435\u0440\u0442\u0435 \u0441\u0442\u043e\u0438\u0442 <code>for: 1m<\/code>). \u0423 \u043d\u0430\u0441 <code>active<\/code> \u0443\u043f\u0451\u0440\u0441\u044f \u0432 \u043f\u043e\u0442\u043e\u043b\u043e\u043a \u043f\u0443\u043b\u0430, <code>idle<\/code> \u0443\u043f\u0430\u043b \u0432 \u043d\u043e\u043b\u044c, <code>pending<\/code> \u0434\u0435\u0440\u0436\u0430\u043b\u0441\u044f \u0432 \u0440\u0430\u0439\u043e\u043d\u0435 12, \u0430 <code>timeout_total<\/code> \u0440\u043e\u0441. \u0415\u0449\u0451 \u0434\u0432\u0430 \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u044e\u0442, \u0434\u043e\u043b\u0433\u043e \u043b\u0438 \u043f\u043e\u0442\u043e\u043a\u0438 \u0436\u0434\u0443\u0442 \u0432 \u043e\u0447\u0435\u0440\u0435\u0434\u0438 \u0438 \u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0434\u0435\u0440\u0436\u0430\u0442 \u0441\u0430\u043c\u043e \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0435:<\/p>\n<pre><code># \u0412\u0440\u0435\u043c\u044f \u043e\u0436\u0438\u0434\u0430\u043d\u0438\u044f \u0432 \u043e\u0447\u0435\u0440\u0435\u0434\u0438 (acquire)rate(hikaricp_connections_acquire_seconds_sum[1m])\/ rate(hikaricp_connections_acquire_seconds_count[1m])# \u0412\u0440\u0435\u043c\u044f \u0443\u0434\u0435\u0440\u0436\u0430\u043d\u0438\u044f \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f (usage)rate(hikaricp_connections_usage_seconds_sum[1m])\/ rate(hikaricp_connections_usage_seconds_count[1m])<\/code><div class=\"code-explainer\"><a href=\"https:\/\/sourcecraft.dev\/\" class=\"tm-button code-explainer__link\" style=\"visibility: hidden;\"><span class=\"sc-logo-wrapper icon-only\"><\/span><\/a><\/div><\/pre>\n<figure class=\"\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/extt\/d0\/8a\/03\/d08a03164f7ca7db68bfef35a820be3b.png\" alt=\"\u0414\u0430\u0448\u0431\u043e\u0440\u0434 \u043f\u0443\u043b\u0430 \u043d\u0430 \u0434\u0435\u043c\u043e-\u0441\u0442\u0435\u043d\u0434\u0435 \u043f\u043e\u0434 \u043d\u0430\u0433\u0440\u0443\u0437\u043a\u043e\u0439: \u0432\u0441\u0435 5 \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0439 \u0437\u0430\u043d\u044f\u0442\u044b, 5 \u043f\u043e\u0442\u043e\u043a\u043e\u0432 \u0436\u0434\u0443\u0442 \u0432 \u043e\u0447\u0435\u0440\u0435\u0434\u0438, usage \u0443\u0448\u0451\u043b \u0437\u0430 4 \u0441\u0435\u043a\u0443\u043d\u0434\u044b \u0438 \u043f\u043e\u0448\u043b\u0438 \u0442\u0430\u0439\u043c\u0430\u0443\u0442\u044b\" sizes=\"(max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/r\/w780\/extt\/d0\/8a\/03\/d08a03164f7ca7db68bfef35a820be3b.png 780w,&#10;       https:\/\/habrastorage.org\/r\/w1560\/extt\/d0\/8a\/03\/d08a03164f7ca7db68bfef35a820be3b.png 781w\" loading=\"lazy\" decode=\"async\"\/><\/p>\n<div><figcaption>\u0414\u0430\u0448\u0431\u043e\u0440\u0434 \u043f\u0443\u043b\u0430 \u043d\u0430 \u0434\u0435\u043c\u043e-\u0441\u0442\u0435\u043d\u0434\u0435 \u043f\u043e\u0434 \u043d\u0430\u0433\u0440\u0443\u0437\u043a\u043e\u0439: \u0432\u0441\u0435 5 \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0439 \u0437\u0430\u043d\u044f\u0442\u044b, 5 \u043f\u043e\u0442\u043e\u043a\u043e\u0432 \u0436\u0434\u0443\u0442 \u0432 \u043e\u0447\u0435\u0440\u0435\u0434\u0438, usage \u0443\u0448\u0451\u043b \u0437\u0430 4 \u0441\u0435\u043a\u0443\u043d\u0434\u044b \u0438 \u043f\u043e\u0448\u043b\u0438 \u0442\u0430\u0439\u043c\u0430\u0443\u0442\u044b<\/figcaption><\/div>\n<\/figure>\n<p>\u041e\u0431\u044b\u0447\u043d\u043e <code>usage<\/code> \u0443 \u043d\u0430\u0441 \u0431\u044b\u043b \u0432 \u0440\u0430\u0439\u043e\u043d\u0435 4\u20136 \u043c\u0441. \u0422\u043e\u0439 \u043d\u043e\u0447\u044c\u044e \u043e\u043d \u0441\u043a\u0430\u043a\u0430\u043b \u043e\u0442 1.2 \u0434\u043e 4.8 \u0441\u0435\u043a\u0443\u043d\u0434\u044b \u2014 \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f \u0431\u0440\u0430\u043b\u0438 \u0438 \u043d\u0435 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u043b\u0438.<\/p>\n<p>\u041f\u043e\u043b\u0435\u0437\u043b\u0438 \u0441\u043d\u0438\u043c\u0430\u0442\u044c thread dump. \u0412 \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u044b\u0445 \u043e\u0431\u0440\u0430\u0437\u0430\u0445 \u0432\u0440\u043e\u0434\u0435 <code>eclipse-temurin:17-jre-alpine<\/code> \u0443\u0442\u0438\u043b\u0438\u0442\u044b <code>jstack<\/code> \u0432\u043d\u0443\u0442\u0440\u0438 \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440\u0430 \u043d\u0435\u0442. \u0421\u0430\u043c\u044b\u0439 \u0431\u044b\u0441\u0442\u0440\u044b\u0439 \u0441\u043f\u043e\u0441\u043e\u0431 \u0431\u0435\u0437 JDK-\u0443\u0442\u0438\u043b\u0438\u0442 \u2014 \u043f\u043e\u0441\u043b\u0430\u0442\u044c \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0443 <code>kill -3 1<\/code>, \u0442\u043e\u0433\u0434\u0430 JVM \u0441\u0431\u0440\u043e\u0441\u0438\u0442 \u0434\u0430\u043c\u043f \u043f\u0440\u044f\u043c\u043e \u0432 <code>docker logs<\/code> \u0438\u043b\u0438 <code>kubectl logs<\/code>. \u0415\u0441\u043b\u0438 \u043d\u0443\u0436\u043d\u043e \u0441\u043e\u0445\u0440\u0430\u043d\u0438\u0442\u044c \u0435\u0433\u043e \u0432 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0439 \u0444\u0430\u0439\u043b, \u0432 k8s \u0432\u044b\u0440\u0443\u0447\u0430\u0435\u0442 <code>kubectl debug<\/code>, \u0430 \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u043e \u043d\u0430 docker compose \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0438\u0442\u044c JDK-\u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440 \u043a \u0442\u043e\u043c\u0443 \u0436\u0435 PID-\u043d\u0435\u0439\u043c\u0441\u043f\u0435\u0439\u0441\u0443:<\/p>\n<pre><code class=\"bash\">docker run --rm --pid=container:todo-tx-app --user 1001:1001 \\  eclipse-temurin:17-jdk jstack 1 &gt; threads.txt<\/code><div class=\"code-explainer\"><a href=\"https:\/\/sourcecraft.dev\/\" class=\"tm-button code-explainer__link\" style=\"visibility: hidden;\"><span class=\"sc-logo-wrapper icon-only\"><\/span><\/a><\/div><\/pre>\n<p>\u0412 \u0434\u0430\u043c\u043f\u0435 \u0441\u0440\u0430\u0437\u0443 \u0432\u0438\u0434\u043d\u044b \u043e\u0431\u0435 \u0441\u0442\u043e\u0440\u043e\u043d\u044b \u043a\u0430\u0440\u0442\u0438\u043d\u044b. \u041e\u0436\u0438\u0434\u0430\u044e\u0449\u0438\u0435 \u043f\u043e\u0442\u043e\u043a\u0438 Tomcat \u0432\u0438\u0441\u044f\u0442 \u0432 <code>TIMED_WAITING (parking)<\/code> \u043d\u0430 <code>ConcurrentBag.borrow<\/code>:<\/p>\n<pre><code>\"http-nio-8080-exec-2\" #37 daemon prio=5 os_prio=0 cpu=6.48ms elapsed=40.14s tid=0x00007f069f2716c0 nid=0x42 waiting on condition  [0x00007f069ea3e000]   java.lang.Thread.State: TIMED_WAITING (parking)at jdk.internal.misc.Unsafe.park(java.base@17.0.21\/Native Method)- parking to wait for  &lt;0x00000000e92bb3c0&gt; (a java.util.concurrent.SynchronousQueue$TransferQueue)at java.util.concurrent.locks.LockSupport.parkNanos(java.base@17.0.21\/Unknown Source)at java.util.concurrent.SynchronousQueue$TransferQueue.transfer(java.base@17.0.21\/Unknown Source)at java.util.concurrent.SynchronousQueue.poll(java.base@17.0.21\/Unknown Source)at com.zaxxer.hikari.util.ConcurrentBag.borrow(ConcurrentBag.java:151)at com.zaxxer.hikari.pool.HikariPool.getConnection(HikariPool.java:164)at com.zaxxer.hikari.pool.HikariPool.getConnection(HikariPool.java:146)at com.zaxxer.hikari.HikariDataSource.getConnection(HikariDataSource.java:128)<\/code><div class=\"code-explainer\"><a href=\"https:\/\/sourcecraft.dev\/\" class=\"tm-button code-explainer__link\" style=\"visibility: hidden;\"><span class=\"sc-logo-wrapper icon-only\"><\/span><\/a><\/div><\/pre>\n<p>\u0410 \u043f\u044f\u0442\u044c \u043f\u043e\u0442\u043e\u043a\u043e\u0432-\u0432\u0438\u043d\u043e\u0432\u043d\u0438\u043a\u043e\u0432 (<code>exec-1<\/code>, <code>exec-7<\/code>\u2026<code>exec-10<\/code>) \u0432 \u044d\u0442\u043e\u0442 \u0436\u0435 \u043c\u043e\u043c\u0435\u043d\u0442 \u0434\u0435\u0440\u0436\u0430\u0442 \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f \u0438 \u0432\u0438\u0441\u044f\u0442 \u0432 \u043e\u0436\u0438\u0434\u0430\u043d\u0438\u0438 \u043e\u0442\u0432\u0435\u0442\u0430 \u043e\u0442 \u0432\u043d\u0435\u0448\u043d\u0435\u0433\u043e \u0441\u0435\u0440\u0432\u0438\u0441\u0430 (\u0432 \u0434\u0435\u043c\u043e \u044d\u0442\u043e \u0438\u043c\u0438\u0442\u0438\u0440\u0443\u0435\u0442 <code>SlowExternalClient.notifyExternalSystem:30<\/code>, \u0432 \u043f\u0440\u043e\u0434\u0435 \u2014 \u0447\u0442\u0435\u043d\u0438\u0435 \u0438\u0437 HTTP-\u0441\u043e\u043a\u0435\u0442\u0430).<\/p>\n<p>\u041f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u044c\u043d\u043e \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u043b\u0438 <code>pg_stat_activity<\/code>:<\/p>\n<pre><code class=\"sql\">SELECT pid, state, wait_event_type,       now() - xact_start AS tx_age,       left(query, 50) AS queryFROM pg_stat_activityWHERE datname = 'todo'ORDER BY xact_start;<\/code><div class=\"code-explainer\"><a href=\"https:\/\/sourcecraft.dev\/\" class=\"tm-button code-explainer__link\" style=\"visibility: hidden;\"><span class=\"sc-logo-wrapper icon-only\"><\/span><\/a><\/div><\/pre>\n<figure class=\"\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/webt\/2c\/9f\/3f\/2c9f3f169bb5adb7a8622505d6751d72.png\" alt=\"\u0412\u044b\u0432\u043e\u0434 pg_stat_activity \u0432\u043e \u0432\u0440\u0435\u043c\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f slow-tx: \u0432\u0441\u0435 \u043f\u044f\u0442\u044c \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0439 \u0432\u0438\u0441\u044f\u0442 \u0432 idle in transaction \u0438 \u0436\u0434\u0443\u0442 \u043a\u043b\u0438\u0435\u043d\u0442\u0430\" sizes=\"(max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/r\/w780\/webt\/2c\/9f\/3f\/2c9f3f169bb5adb7a8622505d6751d72.png 780w,&#10;       https:\/\/habrastorage.org\/r\/w1560\/webt\/2c\/9f\/3f\/2c9f3f169bb5adb7a8622505d6751d72.png 781w\" loading=\"lazy\" decode=\"async\"\/><\/p>\n<div><figcaption>\u0412\u044b\u0432\u043e\u0434 pg_stat_activity \u0432\u043e \u0432\u0440\u0435\u043c\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f slow-tx: \u0432\u0441\u0435 \u043f\u044f\u0442\u044c \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0439 \u0432\u0438\u0441\u044f\u0442 \u0432 idle in transaction \u0438 \u0436\u0434\u0443\u0442 \u043a\u043b\u0438\u0435\u043d\u0442\u0430<\/figcaption><\/div>\n<\/figure>\n<p>\u0422\u0430\u043c \u0432\u0438\u0441\u0435\u043b\u0430 \u043f\u0430\u0447\u043a\u0430 \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0439 \u0432 <code>state = 'idle in transaction'<\/code> \u0441 \u0432\u043e\u0437\u0440\u0430\u0441\u0442\u043e\u043c \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u0438 \u0432 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0441\u0435\u043a\u0443\u043d\u0434. \u041f\u0440\u0438\u0447\u0438\u043d\u0430 \u043d\u0430\u0448\u043b\u0430\u0441\u044c \u0431\u044b\u0441\u0442\u0440\u043e: \u0441\u043e\u0441\u0435\u0434\u043d\u0438\u0439 \u0441\u0435\u0440\u0432\u0438\u0441 \u0443\u0432\u0435\u0434\u043e\u043c\u043b\u0435\u043d\u0438\u0439 \u043d\u0430\u0447\u0430\u043b \u0442\u043e\u0440\u043c\u043e\u0437\u0438\u0442\u044c, \u0430 \u0435\u0433\u043e HTTP-\u0432\u044b\u0437\u043e\u0432 \u0443 \u043d\u0430\u0441 \u0441\u0438\u0434\u0435\u043b \u043f\u0440\u044f\u043c\u043e \u0432\u043d\u0443\u0442\u0440\u0438 <code>@Transactional<\/code>.<\/p>\n<p>\u0427\u0442\u043e\u0431\u044b \u043d\u0435 \u043f\u0435\u0440\u0435\u043f\u0438\u0441\u044b\u0432\u0430\u0442\u044c \u043a\u043e\u0434 \u0432 \u0447\u0430\u0441 \u043d\u043e\u0447\u0438, \u043e\u043a\u043e\u043b\u043e 00:40 \u043c\u044b \u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e \u043f\u043e\u0434\u043d\u044f\u043b\u0438 \u043f\u0443\u043b \u0434\u043e 30 \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0439 \u0438 \u043f\u043e\u0441\u0442\u0430\u0432\u0438\u043b\u0438 \u0436\u0451\u0441\u0442\u043a\u0438\u0439 read-timeout \u043d\u0430 \u043a\u043b\u0438\u0435\u043d\u0442\u0435 \u0443\u0432\u0435\u0434\u043e\u043c\u043b\u0435\u043d\u0438\u0439. \u0420\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u0435 \u043f\u0443\u043b\u0430 \u043f\u043e\u043c\u043e\u0433\u043b\u043e \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u043e\u0442\u043e\u043c\u0443, \u0447\u0442\u043e \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f \u0432 <code>idle in transaction<\/code> \u043f\u043e\u0447\u0442\u0438 \u043d\u0435 \u0433\u0440\u0443\u0437\u044f\u0442 CPU \u0431\u0430\u0437\u044b (\u043a\u043b\u0430\u0441\u0441\u0438\u0447\u0435\u0441\u043a\u0430\u044f \u0444\u043e\u0440\u043c\u0443\u043b\u0430 HikariCP \u0440\u0430\u0441\u0441\u0447\u0438\u0442\u0430\u043d\u0430 \u043d\u0430 \u0430\u043a\u0442\u0438\u0432\u043d\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u044e\u0449\u0438\u0435 \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f). \u041e\u0447\u0435\u0440\u0435\u0434\u044c \u0440\u0430\u0441\u0441\u043e\u0441\u0430\u043b\u0430\u0441\u044c, \u0441\u043f\u0430\u0442\u044c \u0440\u0430\u0437\u043e\u0448\u043b\u0438\u0441\u044c \u0432 \u043d\u0430\u0447\u0430\u043b\u0435 \u0432\u0442\u043e\u0440\u043e\u0433\u043e.<\/p>\n<hr\/>\n<h3>\u0427\u0442\u043e \u0441\u043b\u043e\u043c\u0430\u043b\u043e \u043f\u0440\u043e\u0434: \u0432\u043d\u0435\u0448\u043d\u0438\u0439 HTTP \u0432\u043d\u0443\u0442\u0440\u0438 @Transactional<\/h3>\n<p>\u041a\u043e\u0434, \u0438\u0437-\u0437\u0430 \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u0432\u0441\u0451 \u043b\u0435\u0433\u043b\u043e, \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u043b \u0431\u0435\u0437\u043e\u0431\u0438\u0434\u043d\u043e:<\/p>\n<pre><code class=\"java\">@Transactionalpublic Task createAndNotifySlow(String title) {    Task saved = taskRepository.save(new Task(title));   \/\/ ~5 \u043c\u0441    externalClient.notifyExternalSystem(saved);          \/\/ 5 \u0441\u0435\u043a\u0443\u043d\u0434    return saved;}<\/code><div class=\"code-explainer\"><a href=\"https:\/\/sourcecraft.dev\/\" class=\"tm-button code-explainer__link\" style=\"visibility: hidden;\"><span class=\"sc-logo-wrapper icon-only\"><\/span><\/a><\/div><\/pre>\n<p><code>@Transactional<\/code> \u0434\u0435\u0440\u0436\u0438\u0442 JDBC-\u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0435 \u0434\u043e \u0432\u044b\u0445\u043e\u0434\u0430 \u0438\u0437 \u043c\u0435\u0442\u043e\u0434\u0430. \u0411\u0430\u0437\u0430 \u043e\u0442\u0440\u0430\u0431\u043e\u0442\u0430\u043b\u0430 \u0437\u0430 5 \u043c\u0441, \u043d\u043e \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u0435 5 \u0441\u0435\u043a\u0443\u043d\u0434 \u043a\u043e\u043d\u043d\u0435\u043a\u0442 \u0432\u0438\u0441\u0435\u043b \u0432 <code>idle in transaction<\/code>, \u043f\u043e\u043a\u0430 \u043c\u044b \u0436\u0434\u0430\u043b\u0438 \u043e\u0442\u0432\u0435\u0442\u0430 \u043f\u043e HTTP.<\/p>\n<p>\u0412 \u0434\u0435\u043c\u043e-\u043f\u0440\u043e\u0435\u043a\u0442\u0435 \u043f\u0440\u0438 \u043f\u0443\u043b\u0435 \u043d\u0430 5 \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0439 \u0437\u0430\u043f\u0443\u0441\u043a 7 \u043f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u044c\u043d\u044b\u0445 <code>POST \/api\/crime\/slow-tx<\/code> \u0441\u0440\u0430\u0437\u0443 \u0437\u0430\u0431\u0438\u0432\u0430\u0435\u0442 \u043f\u0443\u043b (<code>active: 5, idle: 0, waiting: 2<\/code>): \u043f\u044f\u0442\u044c \u043f\u043e\u0442\u043e\u043a\u043e\u0432 \u0443\u0445\u043e\u0434\u044f\u0442 \u0432\u043e \u0432\u043d\u0435\u0448\u043d\u0438\u0439 \u0432\u044b\u0437\u043e\u0432, \u0430 6-\u0439 \u0438 7-\u0439 \u0432\u0441\u0442\u0430\u044e\u0442 \u0432 \u043e\u0447\u0435\u0440\u0435\u0434\u044c. \u041f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u0432 \u0441\u0442\u0435\u043d\u0434\u0435 \u0437\u0430\u0434\u0435\u0440\u0436\u043a\u0430 \u0432\u043d\u0435\u0448\u043d\u0435\u0433\u043e \u0432\u044b\u0437\u043e\u0432\u0430 (5000 \u043c\u0441) \u0441\u043e\u0432\u043f\u0430\u0434\u0430\u0435\u0442 \u0441 <code>connection-timeout<\/code>, \u043f\u0440\u0438 \u0437\u0430\u043f\u0443\u0441\u043a\u0435 \u0447\u0435\u0440\u0435\u0437 <code>for ... &amp;<\/code> 6-\u0439 \u0438 7-\u0439 \u043e\u0431\u044b\u0447\u043d\u043e \u0443\u0441\u043f\u0435\u0432\u0430\u044e\u0442 \u0441\u0445\u0432\u0430\u0442\u0438\u0442\u044c \u043e\u0441\u0432\u043e\u0431\u043e\u0434\u0438\u0432\u0448\u0438\u0439\u0441\u044f \u043a\u043e\u043d\u043d\u0435\u043a\u0442 (\u043e\u0442\u0432\u0435\u0447\u0430\u044f \u0437\u0430 ~10 \u0441\u0435\u043a\u0443\u043d\u0434) \u0442\u043e\u043b\u044c\u043a\u043e \u0437\u0430 \u0441\u0447\u0451\u0442 \u0442\u043e\u0433\u043e, \u0447\u0442\u043e \u043f\u0440\u0438\u0448\u043b\u0438 \u043d\u0430 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043c\u0438\u043b\u043b\u0438\u0441\u0435\u043a\u0443\u043d\u0434 \u043f\u043e\u0437\u0436\u0435 \u043f\u0435\u0440\u0432\u044b\u0445 \u043f\u044f\u0442\u0438. \u041f\u0440\u0438 \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e\u043c \u0437\u0430\u043f\u0443\u0441\u043a\u0435 (\u0447\u0435\u0440\u0435\u0437 <code>hey<\/code> \u0438\u043b\u0438 <code>xargs -P<\/code>), \u0447\u0443\u0442\u044c \u0431\u043e\u043b\u044c\u0448\u0435\u0439 \u0437\u0430\u0434\u0435\u0440\u0436\u043a\u0435 \u0438\u043b\u0438 \u0431\u043e\u043b\u044c\u0448\u0435\u043c \u0447\u0438\u0441\u043b\u0435 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 (\u043d\u0430 \u0441\u0442\u0435\u043d\u0434\u0435 \u0445\u0432\u0430\u0442\u0430\u0435\u0442 15 \u0448\u0442\u0443\u043a) \u0432 \u043e\u0442\u0432\u0435\u0442 \u0441\u0440\u0430\u0437\u0443 \u043b\u0435\u0442\u044f\u0442 \u043f\u044f\u0442\u0438\u0441\u043e\u0442\u044b\u0435.<\/p>\n<p>\u0413\u0440\u0430\u043d\u0438\u0446\u0443 \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u0438 \u043d\u0443\u0436\u043d\u043e \u0441\u0436\u0438\u043c\u0430\u0442\u044c \u0441\u0442\u0440\u043e\u0433\u043e \u0434\u043e \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u0411\u0414, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 \u0447\u0435\u0440\u0435\u0437 <code>TransactionTemplate<\/code>:<\/p>\n<pre><code class=\"java\">public Task createAndNotifyFixed(String title) {    Task saved = transactionTemplate.execute(status -&gt;            taskRepository.save(new Task(title)));    externalClient.notifyExternalSystem(saved);    return saved;}<\/code><div class=\"code-explainer\"><a href=\"https:\/\/sourcecraft.dev\/\" class=\"tm-button code-explainer__link\" style=\"visibility: hidden;\"><span class=\"sc-logo-wrapper icon-only\"><\/span><\/a><\/div><\/pre>\n<p>\u0410\u043b\u044c\u0442\u0435\u0440\u043d\u0430\u0442\u0438\u0432\u0430 \u2014 \u0432\u044b\u043d\u043e\u0441\u0438\u0442\u044c \u0432\u043d\u0435\u0448\u043d\u0438\u0435 \u0432\u044b\u0437\u043e\u0432\u044b \u0432 <code>@TransactionalEventListener(AFTER_COMMIT)<\/code> <strong>\u0432 \u043f\u0430\u0440\u0435 \u0441 <\/strong><code><strong>@Async<\/strong><\/code>. \u0411\u0435\u0437 <code>@Async<\/code> \u043b\u0438\u0441\u0442\u0435\u043d\u0435\u0440 \u043e\u0442\u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0432 \u0442\u043e\u043c \u0436\u0435 \u043f\u043e\u0442\u043e\u043a\u0435 \u0440\u0430\u043d\u044c\u0448\u0435, \u0447\u0435\u043c \u043c\u0435\u043d\u0435\u0434\u0436\u0435\u0440 \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u0439 \u0432\u0435\u0440\u043d\u0451\u0442 \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0435 \u0432 \u043f\u0443\u043b, \u0438 \u0442\u0435 \u0436\u0435 \u043f\u044f\u0442\u044c \u0441\u0435\u043a\u0443\u043d\u0434 HTTP \u0441\u043d\u043e\u0432\u0430 \u0431\u0443\u0434\u0443\u0442 \u043e\u043f\u043b\u0430\u0447\u0435\u043d\u044b \u043a\u043e\u043d\u043d\u0435\u043a\u0442\u043e\u043c. \u041f\u0440\u0430\u0432\u0434\u0430, \u043e\u0431\u0430 \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u0430 \u043f\u043e\u0442\u0435\u0440\u044f\u044e\u0442 \u0443\u0432\u0435\u0434\u043e\u043c\u043b\u0435\u043d\u0438\u0435, \u0435\u0441\u043b\u0438 \u043f\u043e\u0434 \u0443\u043f\u0430\u0434\u0451\u0442 \u043c\u0435\u0436\u0434\u0443 \u043a\u043e\u043c\u043c\u0438\u0442\u043e\u043c \u0438 HTTP-\u0432\u044b\u0437\u043e\u0432\u043e\u043c \u2014 \u0435\u0441\u043b\u0438 \u043d\u0443\u0436\u043d\u0430 \u0433\u0430\u0440\u0430\u043d\u0442\u0438\u044f \u0434\u043e\u0441\u0442\u0430\u0432\u043a\u0438, \u0437\u0434\u0435\u0441\u044c \u0443\u0436\u0435 \u043d\u0443\u0436\u0435\u043d \u043f\u0430\u0442\u0442\u0435\u0440\u043d Transactional Outbox.<\/p>\n<p>\u041d\u0430 \u043f\u0438\u0448\u0443\u0449\u0438\u0435 \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u0438 \u043f\u043e\u043b\u0435\u0437\u043d\u043e \u0432\u0435\u0448\u0430\u0442\u044c <code>@Transactional(timeout = 5)<\/code>. \u041d\u043e \u0432\u0430\u0436\u043d\u043e \u043f\u043e\u043c\u043d\u0438\u0442\u044c: \u043d\u0438 Spring, \u043d\u0438 Hibernate \u043d\u0435 \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u044e\u0442 \u044d\u0442\u043e\u0442 \u0434\u0435\u0434\u043b\u0430\u0439\u043d \u043d\u0430 \u0441\u0430\u043c\u043e\u043c <code>commit()<\/code>. \u041e\u0441\u0442\u0430\u0432\u0448\u0435\u0435\u0441\u044f \u0432\u0440\u0435\u043c\u044f \u0441\u0432\u0435\u0440\u044f\u0435\u0442\u0441\u044f \u043f\u0440\u0438 \u043f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u043a\u0435 \u043e\u0447\u0435\u0440\u0435\u0434\u043d\u043e\u0433\u043e SQL-\u0437\u0430\u043f\u0440\u043e\u0441\u0430 (\u0432 \u0442\u043e\u043c \u0447\u0438\u0441\u043b\u0435 \u043f\u0440\u0438 <code>flush<\/code> \u043f\u0435\u0440\u0435\u0434 \u043a\u043e\u043c\u043c\u0438\u0442\u043e\u043c). \u041f\u043e\u0442\u043e\u043a, \u0437\u0430\u0432\u0438\u0441\u0448\u0438\u0439 \u043d\u0430 \u0447\u0442\u0435\u043d\u0438\u0438 \u0438\u0437 HTTP-\u0441\u043e\u043a\u0435\u0442\u0430 \u043f\u043e\u0441\u043b\u0435 \u0443\u0436\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u043d\u043e\u0433\u043e <code>INSERT<\/code>, \u0442\u0430\u043a\u043e\u0439 \u0442\u0430\u0439\u043c\u0430\u0443\u0442 \u043d\u0435 \u043f\u0440\u0435\u0440\u0432\u0451\u0442 \u2014 \u043e\u0442 \u043c\u0435\u0434\u043b\u0435\u043d\u043d\u044b\u0445 \u0441\u043e\u0441\u0435\u0434\u0435\u0439 \u0437\u0430\u0449\u0438\u0449\u0430\u044e\u0442 connect\/read \u0442\u0430\u0439\u043c\u0430\u0443\u0442\u044b \u0441\u0430\u043c\u043e\u0433\u043e HTTP-\u043a\u043b\u0438\u0435\u043d\u0442\u0430.<\/p>\n<hr\/>\n<h3>\u041f\u043e\u043d\u0435\u0434\u0435\u043b\u044c\u043d\u0438\u043a, 10:15: \u043f\u043e\u0447\u0435\u043c\u0443 TransactionTemplate \u043d\u0435 \u043e\u0442\u0434\u0430\u043b \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0435<\/h3>\n<p>\u0412 \u043f\u044f\u0442\u043d\u0438\u0446\u0443 \u0434\u043d\u0451\u043c \u043c\u044b \u0432\u044b\u043a\u0430\u0442\u0438\u043b\u0438 \u0444\u0438\u043a\u0441 \u0441 <code>TransactionTemplate<\/code> \u0438 \u0432\u0435\u0440\u043d\u0443\u043b\u0438 \u043f\u0443\u043b \u043e\u0431\u0440\u0430\u0442\u043d\u043e \u043a 15 \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f\u043c. \u0412\u044b\u0445\u043e\u0434\u043d\u044b\u0435 \u043f\u0440\u043e\u0448\u043b\u0438 \u0442\u0438\u0445\u043e.<\/p>\n<p>\u0412 \u043f\u043e\u043d\u0435\u0434\u0435\u043b\u044c\u043d\u0438\u043a \u0432 10:15, \u043a\u043e\u0433\u0434\u0430 \u043f\u0440\u0438\u0448\u0451\u043b \u0443\u0442\u0440\u0435\u043d\u043d\u0438\u0439 \u0442\u0440\u0430\u0444\u0438\u043a, \u0441\u0435\u0440\u0432\u0438\u0441 \u0443\u0432\u0435\u0434\u043e\u043c\u043b\u0435\u043d\u0438\u0439 \u0441\u043d\u043e\u0432\u0430 \u043f\u043e\u0434\u0442\u043e\u0440\u043c\u043e\u0437\u0438\u043b \u043d\u0430 \u043f\u0430\u0440\u0443 \u0441\u0435\u043a\u0443\u043d\u0434 \u2014 \u0438 \u043d\u0430 \u0433\u0440\u0430\u0444\u0438\u043a\u0435 <code>hikaricp_connections_active<\/code> \u0442\u0443\u0442 \u0436\u0435 \u043f\u043e\u0434\u0441\u043a\u043e\u0447\u0438\u043b \u043a \u043f\u043e\u0442\u043e\u043b\u043a\u0443, \u0430 <code>pending<\/code> \u043f\u043e\u043f\u043e\u043b\u0437 \u0432\u0432\u0435\u0440\u0445.<\/p>\n<p>\u0421\u043d\u043e\u0432\u0430 \u043e\u0442\u043a\u0440\u044b\u043b\u0438 <code>pg_stat_activity<\/code> \u2014 \u0438 \u0443\u0432\u0438\u0434\u0435\u043b\u0438 \u0441\u0442\u0440\u0430\u043d\u043d\u0443\u044e \u043a\u0430\u0440\u0442\u0438\u043d\u0443. \u0412 \u0447\u0435\u0442\u0432\u0435\u0440\u0433 \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f \u0432\u0438\u0441\u0435\u043b\u0438 \u0432 <code>idle in transaction<\/code>, \u0430 \u0442\u0435\u043f\u0435\u0440\u044c \u043e\u043d\u0438 \u0431\u044b\u043b\u0438 \u043f\u0440\u043e\u0441\u0442\u043e \u0432 <code>idle<\/code>. \u0422\u043e \u0435\u0441\u0442\u044c \u0441 \u0442\u043e\u0447\u043a\u0438 \u0437\u0440\u0435\u043d\u0438\u044f PostgreSQL \u043d\u0438\u043a\u0430\u043a\u043e\u0439 \u043e\u0442\u043a\u0440\u044b\u0442\u043e\u0439 \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u0438 \u043d\u0435\u0442, \u043d\u043e HikariCP \u043f\u0440\u0438 \u044d\u0442\u043e\u043c \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0430\u0435\u0442 \u0441\u0447\u0438\u0442\u0430\u0442\u044c \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f <code>active<\/code> \u0438 \u043d\u0438\u043a\u043e\u043c\u0443 \u0438\u0445 \u043d\u0435 \u043e\u0442\u0434\u0430\u0451\u0442. \u041a\u0441\u0442\u0430\u0442\u0438, \u043f\u043e\u043f\u0443\u043b\u044f\u0440\u043d\u0430\u044f \u0441\u0442\u0440\u0430\u0445\u043e\u0432\u043a\u0430 \u043d\u0430 \u0441\u0442\u043e\u0440\u043e\u043d\u0435 \u0431\u0430\u0437\u044b \u2014 <code>idle_in_transaction_session_timeout<\/code> \u2014 \u0447\u0435\u0442\u0432\u0435\u0440\u0433\u043e\u0432\u044b\u0439 \u0441\u0446\u0435\u043d\u0430\u0440\u0438\u0439 \u0431\u044b \u043f\u0440\u0438\u0431\u0438\u043b\u0430, \u0430 \u0432\u043e\u0442 \u043e\u0442 \u043f\u043e\u043d\u0435\u0434\u0435\u043b\u044c\u043d\u0438\u0447\u043d\u043e\u0433\u043e \u043d\u0435 \u0441\u043f\u0430\u0441\u043b\u0430 \u0431\u044b \u043d\u0438\u043a\u0430\u043a.<\/p>\n<p>\u00ab\u0421\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0435 \u0437\u0430\u043d\u044f\u0442\u043e, \u0430 \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u0438 \u043d\u0435\u0442\u00bb \u2014 \u043a\u043b\u0430\u0441\u0441\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u043f\u043e\u0447\u0435\u0440\u043a Open Session In View. \u041a\u043e\u0433\u0434\u0430 \u0443\u0432\u0438\u0434\u0435\u043b\u0438 \u0432 <code>pg_stat_activity<\/code> \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f \u0432 \u0441\u0442\u0430\u0442\u0443\u0441\u0435 idle \u043f\u0440\u0438 \u0437\u0430\u043d\u044f\u0442\u043e\u043c \u043f\u0443\u043b\u0435, \u043f\u0430\u0437\u043b \u0441\u043b\u043e\u0436\u0438\u043b\u0441\u044f. \u041e\u0442\u043a\u0440\u044b\u043b\u0438 \u043b\u043e\u0433 \u0441\u0442\u0430\u0440\u0442\u0430 \u2014 \u0438 \u0432\u043e\u0442 \u043e\u043d\u0430, \u0441\u0442\u0440\u043e\u0447\u043a\u0430, \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u043a\u0430\u0436\u0434\u044b\u0439 Spring-\u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a \u0432\u0438\u0434\u0435\u043b \u0442\u044b\u0441\u044f\u0447\u0443 \u0440\u0430\u0437, \u043d\u0438 \u0440\u0430\u0437\u0443 \u043d\u0435 \u0434\u043e\u0447\u0438\u0442\u0430\u043b \u0434\u043e \u043a\u043e\u043d\u0446\u0430 \u0438 \u0432\u0441\u0435\u0433\u0434\u0430 \u043e\u0442\u043a\u043b\u0430\u0434\u044b\u0432\u0430\u043b \u043d\u0430 \u00ab\u043f\u043e\u0442\u043e\u043c \u043a\u0430\u043a-\u043d\u0438\u0431\u0443\u0434\u044c \u0440\u0430\u0437\u0431\u0435\u0440\u0443\u0441\u044c\u00bb:<\/p>\n<pre><code>2026-11-19T00:09:30.705Z  WARN 1 --- [todo-transactions-demo] [           main] JpaBaseConfiguration$JpaWebConfiguration : spring.jpa.open-in-view is enabled by default. Therefore, database queries may be performed during view rendering. Explicitly configure spring.jpa.open-in-view to disable this warning<\/code><div class=\"code-explainer\"><a href=\"https:\/\/sourcecraft.dev\/\" class=\"tm-button code-explainer__link\" style=\"visibility: hidden;\"><span class=\"sc-logo-wrapper icon-only\"><\/span><\/a><\/div><\/pre>\n<p>\u0412 Spring Boot OSIV \u0432\u043a\u043b\u044e\u0447\u0451\u043d \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e: <code>EntityManager<\/code> \u043e\u0442\u043a\u0440\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0432 \u043d\u0430\u0447\u0430\u043b\u0435 HTTP-\u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u0438 \u0437\u0430\u043a\u0440\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u043e\u0441\u043b\u0435 \u0440\u0435\u043d\u0434\u0435\u0440\u0438\u043d\u0433\u0430 \u043e\u0442\u0432\u0435\u0442\u0430. \u041f\u0440\u0438 \u044d\u0442\u043e\u043c <code>HibernateJpaVendorAdapter<\/code> \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e \u0441\u0442\u0430\u0432\u0438\u0442 Hibernate \u0440\u0435\u0436\u0438\u043c <code>DELAYED_ACQUISITION_AND_HOLD<\/code> \u2014 JDBC-\u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0435 \u0431\u0435\u0440\u0451\u0442\u0441\u044f \u0438\u0437 \u043f\u0443\u043b\u0430 \u0443\u0436\u0435 \u043d\u0430 \u0441\u0442\u0430\u0440\u0442\u0435 \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u0438 (\u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e Hibernate \u0432\u044b\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 <code>setAutoCommit(false)<\/code>, \u0435\u0441\u043b\u0438 \u043d\u0435 \u0432\u043a\u043b\u044e\u0447\u0451\u043d <code>provider_disables_autocommit<\/code>) \u0438 <strong>\u0434\u0435\u0440\u0436\u0438\u0442\u0441\u044f \u0434\u043e \u0437\u0430\u043a\u0440\u044b\u0442\u0438\u044f <\/strong><code><strong>Session<\/strong><\/code><strong>, \u0430 \u043d\u0435 \u0434\u043e \u043a\u043e\u043c\u043c\u0438\u0442\u0430 \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u0438<\/strong>.<\/p>\n<p>\u041f\u043e\u043b\u0443\u0447\u0438\u043b\u043e\u0441\u044c, \u0447\u0442\u043e \u043d\u0430\u0448 <code>TransactionTemplate<\/code> \u043a\u043e\u043c\u043c\u0438\u0442\u0438\u043b \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u044e \u0437\u0430 5 \u043c\u0441, \u043d\u043e \u0438\u0437-\u0437\u0430 \u043e\u0442\u043a\u0440\u044b\u0442\u043e\u0433\u043e <code>EntityManager<\/code> \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0435 \u043e\u0431\u0440\u0430\u0442\u043d\u043e \u0432 \u043f\u0443\u043b \u043d\u0435 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u043b\u043e\u0441\u044c \u0438 \u0432\u0441\u0435 5 \u0441\u0435\u043a\u0443\u043d\u0434 \u0432\u043d\u0435\u0448\u043d\u0435\u0433\u043e HTTP-\u0432\u044b\u0437\u043e\u0432\u0430 \u043f\u043e-\u043f\u0440\u0435\u0436\u043d\u0435\u043c\u0443 \u0432\u0438\u0441\u0435\u043b\u043e \u0437\u0430\u043d\u044f\u0442\u044b\u043c.<\/p>\n<p>\u042d\u0442\u043e \u043b\u0435\u0433\u043a\u043e \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c \u043d\u0430 \u0434\u0435\u043c\u043e-\u0441\u0442\u0435\u043d\u0434\u0435, \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0432 5 \u043f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u044c\u043d\u044b\u0445 <code>POST \/api\/crime\/slow-tx-fixed<\/code> \u0438 \u0441\u043d\u044f\u0432 <code>\/api\/crime\/pool<\/code> \u043d\u0430 1-\u0439 \u0438 3-\u0439 \u0441\u0435\u043a\u0443\u043d\u0434\u0435 (\u0432 \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0438 \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e \u0441\u0442\u043e\u0438\u0442 <code>open-in-view: false<\/code>, \u0434\u043b\u044f \u043f\u0435\u0440\u0432\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0438 \u043d\u0443\u0436\u043d\u043e \u043f\u043e\u0434\u043d\u044f\u0442\u044c \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440 \u0441 <code>SPRING_JPA_OPEN_IN_VIEW=true<\/code>):<\/p>\n<div>\n<div class=\"table\">\n<table>\n<tbody>\n<tr>\n<th>\n<p align=\"left\">\u041a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u044f<\/p>\n<\/th>\n<th>\n<p align=\"left\">\u0414\u043e<\/p>\n<\/th>\n<th>\n<p align=\"left\">+1 \u0441<\/p>\n<\/th>\n<th>\n<p align=\"left\">+3 \u0441<\/p>\n<\/th>\n<th>\n<p align=\"left\">\u041f\u043e\u0441\u043b\u0435<\/p>\n<\/th>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\"><code>open-in-view: true<\/code><\/p>\n<\/td>\n<td>\n<p align=\"left\"><code>active: 0, idle: 2<\/code><\/p>\n<\/td>\n<td>\n<p align=\"left\"><code>active: 5, idle: 0<\/code><\/p>\n<\/td>\n<td>\n<p align=\"left\"><code>active: 5, idle: 0<\/code><\/p>\n<\/td>\n<td>\n<p align=\"left\"><code>active: 0, idle: 5<\/code><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\"><code>open-in-view: false<\/code><\/p>\n<\/td>\n<td>\n<p align=\"left\"><code>active: 0, idle: 2<\/code><\/p>\n<\/td>\n<td>\n<p align=\"left\"><code>active: 0, idle: 5<\/code><\/p>\n<\/td>\n<td>\n<p align=\"left\"><code>active: 0, idle: 5<\/code><\/p>\n<\/td>\n<td>\n<p align=\"left\"><code>active: 0, idle: 5<\/code><\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<p>\u041f\u043e\u0441\u043b\u0435 \u043e\u0442\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f <code>spring.jpa.open-in-view: false<\/code> \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f \u0441\u0442\u0430\u043b\u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0442\u044c\u0441\u044f \u0432 \u043f\u0443\u043b \u0441\u0440\u0430\u0437\u0443 \u043f\u043e\u0441\u043b\u0435 \u043a\u043e\u043c\u043c\u0438\u0442\u0430:<\/p>\n<figure class=\"\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/webt\/96\/d7\/5f\/96d75f2648406fb10cebf04dfde3acf9.png\" alt=\"\u0422\u043e\u0442 \u0436\u0435 slow-tx-fixed \u043d\u0430 \u0434\u0435\u043c\u043e-\u0441\u0442\u0435\u043d\u0434\u0435 \u043f\u043e\u0441\u043b\u0435 \u043e\u0442\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f OSIV: \u0432\u043d\u0435\u0448\u043d\u0438\u0439 \u0441\u0435\u0440\u0432\u0438\u0441 \u043f\u043e-\u043f\u0440\u0435\u0436\u043d\u0435\u043c\u0443 \u043e\u0442\u0432\u0435\u0447\u0430\u0435\u0442 5 \u0441\u0435\u043a\u0443\u043d\u0434 (\u0433\u0440\u0430\u0444\u0438\u043a HTTP Latency \u0441\u043f\u0440\u0430\u0432\u0430 \u0432\u043d\u0438\u0437\u0443), \u043d\u043e \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f \u0431\u043e\u043b\u044c\u0448\u0435 \u043d\u0435 \u0434\u0435\u0440\u0436\u0430\u0442\u0441\u044f \u2014 usage \u0443\u043f\u0430\u043b \u0434\u043e 2\u20133 \u043c\u0441, \u043e\u0447\u0435\u0440\u0435\u0434\u044c \u0438 \u0442\u0430\u0439\u043c\u0430\u0443\u0442\u044b \u0432 \u043d\u0443\u043b\u0435\" sizes=\"(max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/r\/w780\/webt\/96\/d7\/5f\/96d75f2648406fb10cebf04dfde3acf9.png 780w,&#10;       https:\/\/habrastorage.org\/r\/w1560\/webt\/96\/d7\/5f\/96d75f2648406fb10cebf04dfde3acf9.png 781w\" loading=\"lazy\" decode=\"async\"\/><\/p>\n<div><figcaption>\u0422\u043e\u0442 \u0436\u0435 slow-tx-fixed \u043d\u0430 \u0434\u0435\u043c\u043e-\u0441\u0442\u0435\u043d\u0434\u0435 \u043f\u043e\u0441\u043b\u0435 \u043e\u0442\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f OSIV: \u0432\u043d\u0435\u0448\u043d\u0438\u0439 \u0441\u0435\u0440\u0432\u0438\u0441 \u043f\u043e-\u043f\u0440\u0435\u0436\u043d\u0435\u043c\u0443 \u043e\u0442\u0432\u0435\u0447\u0430\u0435\u0442 5 \u0441\u0435\u043a\u0443\u043d\u0434 (\u0433\u0440\u0430\u0444\u0438\u043a HTTP Latency \u0441\u043f\u0440\u0430\u0432\u0430 \u0432\u043d\u0438\u0437\u0443), \u043d\u043e \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f \u0431\u043e\u043b\u044c\u0448\u0435 \u043d\u0435 \u0434\u0435\u0440\u0436\u0430\u0442\u0441\u044f \u2014 usage \u0443\u043f\u0430\u043b \u0434\u043e 2\u20133 \u043c\u0441, \u043e\u0447\u0435\u0440\u0435\u0434\u044c \u0438 \u0442\u0430\u0439\u043c\u0430\u0443\u0442\u044b \u0432 \u043d\u0443\u043b\u0435<\/figcaption><\/div>\n<\/figure>\n<p>\u041f\u0440\u0430\u0432\u0434\u0430, \u043f\u043e\u0441\u043b\u0435 \u0432\u044b\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f OSIV \u0441\u0440\u0430\u0437\u0443 \u0441\u043b\u043e\u043c\u0430\u043b\u0441\u044f \u043e\u0434\u0438\u043d \u0438\u0437 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043e\u0442\u0434\u0430\u0432\u0430\u043b \u043d\u0430\u0440\u0443\u0436\u0443 JPA-\u0441\u0443\u0449\u043d\u043e\u0441\u0442\u044c \u0441 <code>LAZY<\/code>-\u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u0435\u0439 <code>comments<\/code>. \u041f\u043e\u043a\u0430 OSIV \u0440\u0430\u0431\u043e\u0442\u0430\u043b, Jackson \u043c\u043e\u043b\u0447\u0430 \u0434\u0435\u043b\u0430\u043b \u043b\u0438\u0448\u043d\u044e\u044e \u043b\u0435\u043d\u0438\u0432\u0443\u044e \u0434\u043e\u0433\u0440\u0443\u0437\u043a\u0443 \u0432 \u0431\u0430\u0437\u0443 \u043f\u0440\u0438 \u0441\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0437\u0430\u0434\u0430\u0447\u0438 (\u0430 \u043d\u0430 \u0441\u043f\u0438\u0441\u043e\u0447\u043d\u043e\u043c \u044d\u043d\u0434\u043f\u043e\u0438\u043d\u0442\u0435 \u044d\u0442\u043e \u043f\u0440\u0435\u0432\u0440\u0430\u0449\u0430\u043b\u043e\u0441\u044c \u0432 N+1). \u0411\u0435\u0437 OSIV \u044d\u043d\u0434\u043f\u043e\u0438\u043d\u0442 <code>\/api\/crime\/osiv\/1<\/code> \u0443\u043f\u0430\u043b \u0441 500, \u0430 \u0432 \u043b\u043e\u0433 \u043f\u0440\u0438\u0448\u043b\u0430 \u043e\u0434\u043d\u0430 \u0441\u0442\u0440\u043e\u043a\u0430 \u043e\u0442 <code>DefaultHandlerExceptionResolver<\/code>:<\/p>\n<pre><code>2026-11-19T00:08:17.829Z  WARN 1 --- [todo-transactions-demo] [nio-8080-exec-1] .w.s.m.s.DefaultHandlerExceptionResolver : Resolved [org.springframework.http.converter.HttpMessageNotWritableException: Could not write JSON: failed to lazily initialize a collection of role: com.example.todo.model.Task.comments: could not initialize proxy - no Session]<\/code><div class=\"code-explainer\"><a href=\"https:\/\/sourcecraft.dev\/\" class=\"tm-button code-explainer__link\" style=\"visibility: hidden;\"><span class=\"sc-logo-wrapper icon-only\"><\/span><\/a><\/div><\/pre>\n<p>\u041f\u043e\u043b\u043d\u044b\u0439 \u0441\u0442\u0435\u043a\u0442\u0440\u0435\u0439\u0441 \u0432 \u043b\u043e\u0433 \u043d\u0435 \u043f\u0438\u0448\u0435\u0442\u0441\u044f, \u043d\u043e \u0432\u0438\u0434\u0435\u043d \u0432 \u043f\u043e\u043b\u0435 <code>trace<\/code> \u043e\u0442\u0432\u0435\u0442\u0430 \u043f\u0440\u0438 <code>server.error.include-stacktrace=always<\/code>:<\/p>\n<pre><code>Caused by: org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role: com.example.todo.model.Task.comments: could not initialize proxy - no Sessionat org.hibernate.collection.spi.AbstractPersistentCollection.throwLazyInitializationException(AbstractPersistentCollection.java:634)at org.hibernate.collection.spi.AbstractPersistentCollection.withTemporarySessionIfNeeded(AbstractPersistentCollection.java:217)at org.hibernate.collection.spi.AbstractPersistentCollection.readSize(AbstractPersistentCollection.java:148)at org.hibernate.collection.spi.PersistentBag.size(PersistentBag.java:355)<\/code><div class=\"code-explainer\"><a href=\"https:\/\/sourcecraft.dev\/\" class=\"tm-button code-explainer__link\" style=\"visibility: hidden;\"><span class=\"sc-logo-wrapper icon-only\"><\/span><\/a><\/div><\/pre>\n<p>\u041f\u043e\u0447\u0438\u043d\u0438\u043b\u0438 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u043e: \u043f\u043e\u0434\u0433\u0440\u0443\u0437\u0438\u043b\u0438 \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u0438 \u0442\u0435\u043c \u0436\u0435 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u043c \u0447\u0435\u0440\u0435\u0437 <code>fetch join<\/code> \u0432\u043d\u0443\u0442\u0440\u0438 \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u0438 (\u0432 \u0434\u0435\u043c\u043e \u2014 <code>\/api\/crime\/osiv-fixed\/{id}<\/code>), \u0430 \u0432 \u043f\u0440\u043e\u0434\u0435 \u043f\u0435\u0440\u0435\u0432\u0435\u043b\u0438 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440 \u043d\u0430 DTO \u0432\u043c\u0435\u0441\u0442\u043e \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0438. \u0417\u0430\u043e\u0434\u043d\u043e \u0432 Hibernate 6 \u0438\u0437 \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u0441\u0442\u043e\u0438\u0442 \u0443\u0431\u0440\u0430\u0442\u044c \u043f\u0440\u0438\u0432\u044b\u0447\u043d\u044b\u0439 \u043f\u043e \u043f\u044f\u0442\u043e\u0439 \u0432\u0435\u0440\u0441\u0438\u0438 <code>distinct<\/code> \u2014 \u0434\u0443\u0431\u043b\u0438 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0435\u0439 \u0442\u0435\u043f\u0435\u0440\u044c \u0444\u0438\u043b\u044c\u0442\u0440\u0443\u044e\u0442\u0441\u044f \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438, \u0430 \u044f\u0432\u043d\u044b\u0439 <code>distinct<\/code> \u043f\u0440\u043e\u0441\u0442\u043e \u0443\u043b\u0435\u0442\u0430\u0435\u0442 \u043b\u0438\u0448\u043d\u0435\u0439 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0435\u0439 \u0432 SQL:<\/p>\n<pre><code class=\"java\">@Query(\"select t from Task t left join fetch t.comments where t.id = :id\")Optional&lt;Task&gt; findWithCommentsById(@Param(\"id\") Long id);<\/code><div class=\"code-explainer\"><a href=\"https:\/\/sourcecraft.dev\/\" class=\"tm-button code-explainer__link\" style=\"visibility: hidden;\"><span class=\"sc-logo-wrapper icon-only\"><\/span><\/a><\/div><\/pre>\n<p>\u0412 \u043d\u043e\u0432\u044b\u0445 \u043f\u0440\u043e\u0435\u043a\u0442\u0430\u0445 <code>open-in-view: false<\/code> \u043b\u0443\u0447\u0448\u0435 \u043f\u0440\u043e\u043f\u0438\u0441\u044b\u0432\u0430\u0442\u044c \u0441\u0440\u0430\u0437\u0443. \u0412 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0449\u0435\u043c \u2014 \u0441\u043d\u0430\u0447\u0430\u043b\u0430 \u043f\u0440\u043e\u0433\u043e\u043d\u044f\u0442\u044c \u0438\u043d\u0442\u0435\u0433\u0440\u0430\u0446\u0438\u043e\u043d\u043d\u044b\u0435 \u0442\u0435\u0441\u0442\u044b \u043f\u043e \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u0430\u043c, \u0438\u043d\u0430\u0447\u0435 <code>LazyInitializationException<\/code> \u043f\u0440\u0438\u0435\u0434\u0435\u0442 \u0438\u0437 \u043f\u0440\u043e\u0434\u0430.<\/p>\n<hr\/>\n<h3>\u0427\u0442\u043e \u0435\u0449\u0451 \u043a\u043b\u0430\u0434\u0451\u0442 \u043f\u0443\u043b \u0438 \u0441\u043e\u0441\u0435\u0434\u043d\u0438\u0435 \u0433\u0440\u0430\u0431\u043b\u0438 \u0441 \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u044f\u043c\u0438<\/h3>\n<p>\u0420\u0430\u0437 \u0443\u0436 \u043f\u0440\u0438\u0448\u043b\u043e\u0441\u044c \u043f\u043b\u043e\u0442\u043d\u043e \u043f\u043e\u043a\u043e\u043f\u0430\u0442\u044c\u0441\u044f \u0432 HikariCP \u0438 \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u044f\u0445, \u044f \u0434\u043e\u043a\u0438\u043d\u0443\u043b \u0432 \u0442\u043e\u0442 \u0436\u0435 \u0434\u0435\u043c\u043e-\u043f\u0440\u043e\u0435\u043a\u0442 \u0435\u0449\u0451 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0442\u0438\u043f\u043e\u0432\u044b\u0445 \u043f\u0440\u043e\u0431\u043b\u0435\u043c, \u043d\u0430 \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0440\u0435\u0433\u0443\u043b\u044f\u0440\u043d\u043e \u043d\u0430\u0442\u044b\u043a\u0430\u044e\u0442\u0441\u044f \u0432 Spring Boot \u0441\u0435\u0440\u0432\u0438\u0441\u0430\u0445.<\/p>\n<h4>\u0417\u0430\u0431\u044b\u0442\u044b\u0439 close() \u0432 \u0440\u0443\u0447\u043d\u043e\u043c JDBC<\/h4>\n<p>\u0412 JPA \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f \u0437\u0430\u043a\u0440\u044b\u0432\u0430\u0435\u0442 \u0441\u0430\u043c Spring Data, \u043d\u043e \u043f\u043e\u0447\u0442\u0438 \u0432 \u043a\u0430\u0436\u0434\u043e\u043c \u043f\u0440\u043e\u0435\u043a\u0442\u0435 \u0441\u0442\u0430\u0440\u0448\u0435 \u0433\u043e\u0434\u0430 \u0432 \u0443\u0433\u043b\u0443 \u0436\u0438\u0432\u0451\u0442 \u00ab\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0439\u00bb \u043e\u0442\u0447\u0451\u0442 \u043d\u0430 \u0433\u043e\u043b\u043e\u043c JDBC, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043d\u0430\u043f\u0438\u0441\u0430\u043b\u0438 \u0437\u0430 \u0447\u0430\u0441 \u0434\u043e \u0440\u0435\u043b\u0438\u0437\u0430 \u0438 \u0441 \u0442\u0435\u0445 \u043f\u043e\u0440 \u0431\u043e\u044f\u043b\u0438\u0441\u044c \u0442\u0440\u043e\u0433\u0430\u0442\u044c:<\/p>\n<pre><code class=\"java\">public long generateReportWithLeak() throws SQLException {    Connection connection = dataSource.getConnection();    Statement statement = connection.createStatement();    ResultSet resultSet = statement.executeQuery(\"select count(*) from tasks\");    resultSet.next();    return resultSet.getLong(1);}<\/code><div class=\"code-explainer\"><a href=\"https:\/\/sourcecraft.dev\/\" class=\"tm-button code-explainer__link\" style=\"visibility: hidden;\"><span class=\"sc-logo-wrapper icon-only\"><\/span><\/a><\/div><\/pre>\n<p>\u041c\u0435\u0442\u043e\u0434 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0432\u0435\u0440\u043d\u044b\u0439 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442, \u0442\u0435\u0441\u0442\u044b \u043f\u0440\u043e\u0445\u043e\u0434\u044f\u0442, \u0430 \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0435 \u043d\u0430\u0432\u0441\u0435\u0433\u0434\u0430 \u043e\u0441\u0442\u0430\u0451\u0442\u0441\u044f \u0430\u043a\u0442\u0438\u0432\u043d\u044b\u043c. \u0412 \u0434\u0435\u043c\u043e \u043f\u044f\u0442\u044c \u0432\u044b\u0437\u043e\u0432\u043e\u0432 <code>POST \/api\/crime\/leak<\/code> \u043f\u043e\u043b\u043d\u043e\u0441\u0442\u044c\u044e \u0443\u0431\u0438\u0432\u0430\u044e\u0442 \u043f\u0443\u043b: \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 <code>GET \/api\/tasks<\/code> \u0436\u0434\u0451\u0442 5 \u0441\u0435\u043a\u0443\u043d\u0434 \u0438 \u043f\u0430\u0434\u0430\u0435\u0442 \u0441 500:<\/p>\n<pre><code>java.sql.SQLTransientConnectionException: TodoHikariPool - Connection is not available, request timed out after 5008ms.<\/code><div class=\"code-explainer\"><a href=\"https:\/\/sourcecraft.dev\/\" class=\"tm-button code-explainer__link\" style=\"visibility: hidden;\"><span class=\"sc-logo-wrapper icon-only\"><\/span><\/a><\/div><\/pre>\n<p>\u041b\u043e\u0432\u0438\u0442\u044c \u0442\u0430\u043a\u0438\u0435 \u0443\u0442\u0435\u0447\u043a\u0438 \u043f\u0440\u043e\u0449\u0435 \u0432\u0441\u0435\u0433\u043e \u0432\u0441\u0442\u0440\u043e\u0435\u043d\u043d\u044b\u043c \u0434\u0435\u0442\u0435\u043a\u0442\u043e\u0440\u043e\u043c HikariCP (<code>leak-detection-threshold: 10000<\/code> \u0432 \u0434\u0435\u043c\u043e; \u0432 \u043f\u0440\u043e\u0434\u0435 \u043e\u0431\u044b\u0447\u043d\u043e \u0441\u0442\u0430\u0432\u044f\u0442 30000\u201360000 \u043c\u0441, \u0447\u0442\u043e\u0431\u044b \u043d\u0435 \u043b\u043e\u0432\u0438\u0442\u044c \u043b\u043e\u0436\u043d\u044b\u0435 \u0441\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u043d\u0438\u044f \u043d\u0430 \u0434\u043e\u043b\u0433\u0438\u0445 \u0437\u0430\u043f\u0440\u043e\u0441\u0430\u0445):<\/p>\n<pre><code>2026-11-19T00:07:40.786Z  WARN 1 --- [todo-transactions-demo] [ool housekeeper] com.zaxxer.hikari.pool.ProxyLeakTask     : Connection leak detection triggered for org.postgresql.jdbc.PgConnection@5a8fbdc7 on thread http-nio-8080-exec-10, stack trace followsjava.lang.Exception: Apparent connection leak detectedat com.zaxxer.hikari.HikariDataSource.getConnection(HikariDataSource.java:128) ~[HikariCP-5.0.1.jar!\/:na]at com.example.todo.crime.LeakyReportService.generateReportWithLeak(LeakyReportService.java:43) ~[!\/:na]at com.example.todo.controller.CrimeController.leak(CrimeController.java:75) ~[!\/:na]<\/code><div class=\"code-explainer\"><a href=\"https:\/\/sourcecraft.dev\/\" class=\"tm-button code-explainer__link\" style=\"visibility: hidden;\"><span class=\"sc-logo-wrapper icon-only\"><\/span><\/a><\/div><\/pre>\n<p>\u0421\u0442\u0435\u043a\u0442\u0440\u0435\u0439\u0441 \u0441\u0440\u0430\u0437\u0443 \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442 \u043d\u0430 \u0444\u0430\u0439\u043b \u0438 \u0441\u0442\u0440\u043e\u043a\u0443. \u041b\u0435\u0447\u0438\u0442\u0441\u044f \u043e\u0431\u044b\u0447\u043d\u044b\u043c <code>try-with-resources<\/code>:<\/p>\n<pre><code class=\"java\">public long generateReportProperly() throws SQLException {    try (Connection connection = dataSource.getConnection();         Statement statement = connection.createStatement();         ResultSet resultSet = statement.executeQuery(\"select count(*) from tasks\")) {        resultSet.next();        return resultSet.getLong(1);    }}<\/code><div class=\"code-explainer\"><a href=\"https:\/\/sourcecraft.dev\/\" class=\"tm-button code-explainer__link\" style=\"visibility: hidden;\"><span class=\"sc-logo-wrapper icon-only\"><\/span><\/a><\/div><\/pre>\n<h4>Self-invocation \u0438 \u0434\u0435\u0434\u043b\u043e\u043a \u043f\u0443\u043b\u0430 \u043d\u0430 REQUIRES_NEW<\/h4>\n<p>\u0421\u0430\u043c \u043f\u043e \u0441\u0435\u0431\u0435 self-invocation \u043f\u0443\u043b \u043d\u0435 \u0432\u0435\u0448\u0430\u0435\u0442, \u043d\u043e \u044d\u0442\u043e \u0447\u0430\u0441\u0442\u0430\u044f \u043f\u043e\u0434\u0432\u043e\u0434\u043a\u0430 \u043a \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0439 \u043e\u0448\u0438\u0431\u043a\u0435. \u0415\u0441\u043b\u0438 \u0432\u044b\u0437\u0432\u0430\u0442\u044c <code>@Transactional<\/code>-\u043c\u0435\u0442\u043e\u0434 \u0447\u0435\u0440\u0435\u0437 <code>this<\/code>:<\/p>\n<pre><code class=\"java\">@Servicepublic class BatchProcessingService {    public void processBatch() {        this.saveWithTransaction();    }    @Transactional    public void saveWithTransaction() {        taskRepository.save(new Task(\"...\"));    }}<\/code><div class=\"code-explainer\"><a href=\"https:\/\/sourcecraft.dev\/\" class=\"tm-button code-explainer__link\" style=\"visibility: hidden;\"><span class=\"sc-logo-wrapper icon-only\"><\/span><\/a><\/div><\/pre>\n<p>\u0412 \u0434\u0435\u043c\u043e <code>GET \/api\/crime\/self-invocation<\/code> \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 <code>transactionActive: false<\/code>: <code>@Transactional<\/code> \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0447\u0435\u0440\u0435\u0437 \u043f\u0440\u043e\u043a\u0441\u0438-\u043e\u0431\u0451\u0440\u0442\u043a\u0443, \u0438 \u0432\u043d\u0443\u0442\u0440\u0435\u043d\u043d\u0438\u0439 \u0432\u044b\u0437\u043e\u0432 \u0447\u0435\u0440\u0435\u0437 <code>this<\/code> (\u043a\u0430\u043a \u0438 \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u044f \u043d\u0430 <code>private<\/code>-\u043c\u0435\u0442\u043e\u0434\u0435) \u0438\u0434\u0451\u0442 \u043c\u0438\u043c\u043e \u043d\u0435\u0451. \u0412\u044b\u043d\u043e\u0441 \u043c\u0435\u0442\u043e\u0434\u0430 \u0432 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0439 \u0431\u0438\u043d (<code>\/api\/crime\/self-invocation-fixed<\/code>) \u0440\u0435\u0448\u0430\u0435\u0442 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0443.<\/p>\n<p>\u041d\u043e \u0435\u0441\u043b\u0438 \u0432\u043d\u0443\u0442\u0440\u0438 \u043e\u0434\u043d\u043e\u0439 \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u0438 \u0432\u044b\u0437\u0432\u0430\u0442\u044c \u0447\u0435\u0440\u0435\u0437 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0439 \u0431\u0438\u043d \u043c\u0435\u0442\u043e\u0434 \u0441 <code>Propagation.REQUIRES_NEW<\/code> \u2014 \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0447\u0442\u043e\u0431\u044b \u0430\u0443\u0434\u0438\u0442 \u0441\u043e\u0445\u0440\u0430\u043d\u0438\u043b\u0441\u044f \u0434\u0430\u0436\u0435 \u043f\u0440\u0438 \u043e\u0442\u043a\u0430\u0442\u0435 \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0439 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438, \u2014 \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0439\u043c\u0430\u0442\u044c \u043a\u0443\u0434\u0430 \u0431\u043e\u043b\u0435\u0435 \u043d\u0435\u043f\u0440\u0438\u044f\u0442\u043d\u044b\u0439 \u0431\u0430\u0433:<\/p>\n<pre><code class=\"java\">@Servicepublic class TaskProcessingService {    @Transactional    public void process(Long taskId) {        \/\/ \u043e\u0441\u043d\u043e\u0432\u043d\u0430\u044f \u0440\u0430\u0431\u043e\u0442\u0430 \u0441 \u0411\u0414        auditTrail.record(\"processed \" + taskId);    }}@Servicepublic class AuditTrailService {    @Transactional(propagation = Propagation.REQUIRES_NEW)    public void record(String event) {        auditRepository.save(new AuditRecord(event));    }}<\/code><div class=\"code-explainer\"><a href=\"https:\/\/sourcecraft.dev\/\" class=\"tm-button code-explainer__link\" style=\"visibility: hidden;\"><span class=\"sc-logo-wrapper icon-only\"><\/span><\/a><\/div><\/pre>\n<p><code>REQUIRES_NEW<\/code> \u043f\u0440\u0438\u043e\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u0442 \u0432\u043d\u0435\u0448\u043d\u044e\u044e \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u044e (\u043d\u0435 \u043e\u0442\u0434\u0430\u0432\u0430\u044f \u0435\u0451 \u043a\u043e\u043d\u043d\u0435\u043a\u0442 \u0432 \u043f\u0443\u043b, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u0435\u0439 \u0435\u0449\u0451 \u043a\u043e\u043c\u043c\u0438\u0442\u0438\u0442\u044c\u0441\u044f) \u0438 \u043f\u0440\u043e\u0441\u0438\u0442 \u0443 HikariCP <strong>\u0432\u0442\u043e\u0440\u043e\u0435<\/strong> \u0444\u0438\u0437\u0438\u0447\u0435\u0441\u043a\u043e\u0435 \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0435.<\/p>\n<p>\u041f\u0443\u043b \u2014 5 \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0439, \u043f\u0440\u0438\u0445\u043e\u0434\u044f\u0442 5 \u043f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u044c\u043d\u044b\u0445 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432. \u041a\u0430\u0436\u0434\u044b\u0439 \u0437\u0430\u043d\u0438\u043c\u0430\u0435\u0442 \u043f\u0435\u0440\u0432\u044b\u0439 \u043a\u043e\u043d\u043d\u0435\u043a\u0442 \u0438 \u043f\u0440\u043e\u0441\u0438\u0442 \u0432\u0442\u043e\u0440\u043e\u0439 \u0434\u043b\u044f \u0430\u0443\u0434\u0438\u0442\u0430. \u0421\u0432\u043e\u0431\u043e\u0434\u043d\u044b\u0445 \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0439 \u043d\u043e\u043b\u044c: \u043d\u0438\u043a\u0442\u043e \u043d\u0435 \u043c\u043e\u0436\u0435\u0442 \u0437\u0430\u0432\u0435\u0440\u0448\u0438\u0442\u044c \u0432\u043d\u0435\u0448\u043d\u044e\u044e \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u044e, \u043f\u043e\u043a\u0430 \u043d\u0435 \u043e\u0442\u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0432\u043d\u0443\u0442\u0440\u0435\u043d\u043d\u044f\u044f, \u0430 \u0432\u043d\u0443\u0442\u0440\u0435\u043d\u043d\u044f\u044f \u043d\u0435 \u043d\u0430\u0447\u043d\u0451\u0442\u0441\u044f, \u043f\u043e\u043a\u0430 \u043a\u0442\u043e-\u043d\u0438\u0431\u0443\u0434\u044c \u043d\u0435 \u043e\u0441\u0432\u043e\u0431\u043e\u0434\u0438\u0442 \u043a\u043e\u043d\u043d\u0435\u043a\u0442. PostgreSQL \u044d\u0442\u043e\u0442 \u0434\u0435\u0434\u043b\u043e\u043a \u043d\u0435 \u0432\u0438\u0434\u0438\u0442 \u2014 \u043e\u0436\u0438\u0434\u0430\u043d\u0438\u0435 \u0438\u0434\u0451\u0442 \u0432\u043d\u0443\u0442\u0440\u0438 JVM. \u0412 <code>pg_stat_activity<\/code> \u0432 \u044d\u0442\u043e\u0442 \u043c\u043e\u043c\u0435\u043d\u0442 \u043f\u044f\u0442\u044c \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0439 \u0432 <code>idle in transaction<\/code> \u0441 <code>wait_event_type = Client<\/code> (<code>wait_event = ClientRead<\/code>), \u0430 \u043e\u0436\u0438\u0434\u0430\u044e\u0449\u0438\u0445 \u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u043e\u043a \u0432 <code>pg_locks<\/code> \u043d\u043e\u043b\u044c. \u0420\u0430\u0437\u043e\u0440\u0432\u0430\u0442\u044c \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u044e \u043c\u043e\u0436\u0435\u0442 \u0442\u043e\u043b\u044c\u043a\u043e <code>connection-timeout<\/code>.<\/p>\n<p>\u041d\u0430 \u0441\u0442\u0435\u043d\u0434\u0435 \u0432\u044b\u0437\u043e\u0432 <code>POST \/api\/crime\/requires-new?robbers=5<\/code> \u0432 \u043c\u043e\u043c\u0435\u043d\u0442\u0435 \u0434\u0430\u0451\u0442 <code>active: 5, idle: 0, waiting: 5<\/code>, \u0430 \u0447\u0435\u0440\u0435\u0437 5 \u0441\u0435\u043a\u0443\u043d\u0434 \u0432 \u043b\u043e\u0433 \u043f\u0430\u0434\u0430\u044e\u0442 \u0442\u0430\u0439\u043c\u0430\u0443\u0442\u044b \u043e\u0442 \u0440\u0430\u0431\u043e\u0447\u0438\u0445 \u043f\u043e\u0442\u043e\u043a\u043e\u0432 <code>pool-2-thread-N<\/code>:<\/p>\n<pre><code>2026-11-19T00:07:56.265Z ERROR 1 --- [todo-transactions-demo] [pool-2-thread-2] o.h.engine.jdbc.spi.SqlExceptionHelper   : TodoHikariPool - Connection is not available, request timed out after 5000ms.2026-11-19T00:07:56.265Z ERROR 1 --- [todo-transactions-demo] [pool-2-thread-5] o.h.engine.jdbc.spi.SqlExceptionHelper   : TodoHikariPool - Connection is not available, request timed out after 5000ms.2026-11-19T00:07:56.265Z ERROR 1 --- [todo-transactions-demo] [pool-2-thread-4] o.h.engine.jdbc.spi.SqlExceptionHelper   : TodoHikariPool - Connection is not available, request timed out after 5001ms.2026-11-19T00:07:56.265Z ERROR 1 --- [todo-transactions-demo] [pool-2-thread-1] o.h.engine.jdbc.spi.SqlExceptionHelper   : TodoHikariPool - Connection is not available, request timed out after 5002ms.<\/code><div class=\"code-explainer\"><a href=\"https:\/\/sourcecraft.dev\/\" class=\"tm-button code-explainer__link\" style=\"visibility: hidden;\"><span class=\"sc-logo-wrapper icon-only\"><\/span><\/a><\/div><\/pre>\n<p>\u0412 \u044d\u0442\u043e\u043c \u043f\u0440\u043e\u0433\u043e\u043d\u0435 \u0443\u043f\u0430\u043b\u0438 4 \u0443\u0447\u0430\u0441\u0442\u043d\u0438\u043a\u0430, \u0430 \u0442\u0440\u0435\u0442\u0438\u0439 (<code>tx-3<\/code> \u0432 JSON-\u043e\u0442\u0432\u0435\u0442\u0435 \u044d\u043d\u0434\u043f\u043e\u0438\u043d\u0442\u0430) \u0432\u044b\u0436\u0438\u043b. \u041a\u0430\u043a \u0442\u043e\u043b\u044c\u043a\u043e \u0443 \u043f\u0435\u0440\u0432\u043e\u0433\u043e \u043f\u043e\u0442\u043e\u043a\u0430 \u0438\u0441\u0442\u0435\u043a\u0430\u044e\u0442 5000 \u043c\u0441, \u0435\u0433\u043e \u0432\u043d\u0435\u0448\u043d\u044f\u044f \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u044f \u043e\u0442\u043a\u0430\u0442\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0438 \u043e\u0442\u0434\u0430\u0451\u0442 \u043a\u043e\u043d\u043d\u0435\u043a\u0442, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0443\u0441\u043f\u0435\u0432\u0430\u0435\u0442 \u043f\u043e\u0434\u0445\u0432\u0430\u0442\u0438\u0442\u044c \u0441\u043e\u0441\u0435\u0434\u043d\u0438\u0439 \u043f\u043e\u0442\u043e\u043a \u0441 \u0435\u0449\u0451 \u043d\u0435 \u0438\u0441\u0442\u0451\u043a\u0448\u0438\u043c \u0442\u0430\u0439\u043c\u0430\u0443\u0442\u043e\u043c. \u0412\u044b\u0436\u0438\u0432\u0448\u0438\u0439 \u0431\u044b\u0441\u0442\u0440\u043e \u0437\u0430\u043a\u0440\u044b\u0432\u0430\u0435\u0442 \u043e\u0431\u0435 \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u0438 \u0438 \u043e\u0441\u0432\u043e\u0431\u043e\u0436\u0434\u0430\u0435\u0442 \u0443\u0436\u0435 \u0434\u0432\u0430 \u043a\u043e\u043d\u043d\u0435\u043a\u0442\u0430 \u2014 \u0437\u0430\u043f\u0438\u0441\u044c \u0430\u0443\u0434\u0438\u0442\u0430 \u043f\u043e\u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0432 \u0431\u0430\u0437\u0435 \u0432 \u0442\u0443 \u0436\u0435 \u043c\u0438\u043b\u043b\u0438\u0441\u0435\u043a\u0443\u043d\u0434\u0443 \u043f\u043e\u0441\u043b\u0435 \u0442\u0430\u0439\u043c\u0430\u0443\u0442\u0430 \u0441\u043e\u0441\u0435\u0434\u0435\u0439. \u0421\u043a\u043e\u043b\u044c\u043a\u043e \u043f\u043e\u0442\u043e\u043a\u043e\u0432 \u043f\u043e\u0433\u0438\u0431\u043d\u0435\u0442, \u0440\u0435\u0448\u0430\u0435\u0442 \u0433\u043e\u043d\u043a\u0430 \u043d\u0430 \u0434\u043e\u043b\u0438 \u043c\u0438\u043b\u043b\u0438\u0441\u0435\u043a\u0443\u043d\u0434\u044b: \u0432 \u0441\u0435\u0440\u0438\u0438 \u0438\u0437 20 \u0432\u044b\u0437\u043e\u0432\u043e\u0432 \u043f\u043e\u0434\u0440\u044f\u0434 \u0432\u0441\u0435 \u043f\u044f\u0442\u0435\u0440\u043e \u0443\u043f\u0430\u043b\u0438 4 \u0440\u0430\u0437\u0430, \u0447\u0435\u0442\u0432\u0435\u0440\u043e \u2014 4 \u0440\u0430\u0437\u0430, \u0442\u0440\u043e\u0435 \u2014 10 \u0440\u0430\u0437, \u0434\u0432\u043e\u0435 \u2014 2 \u0440\u0430\u0437\u0430. \u0412 \u043f\u0440\u043e\u0434\u0435 \u043e\u0442 \u044d\u0442\u043e\u0433\u043e \u043d\u0435 \u043b\u0435\u0433\u0447\u0435: \u0437\u0430\u043f\u0440\u043e\u0441\u044b \u0432\u0441\u0451 \u0440\u0430\u0432\u043d\u043e \u0432\u0438\u0441\u044f\u0442 \u043f\u043e 5 \u0441\u0435\u043a\u0443\u043d\u0434, \u0438 \u0431\u043e\u043b\u044c\u0448\u0438\u043d\u0441\u0442\u0432\u043e \u043f\u0430\u0434\u0430\u0435\u0442.<\/p>\n<p>\u0427\u0442\u043e\u0431\u044b \u043d\u0435 \u043f\u043b\u043e\u0434\u0438\u0442\u044c \u0432\u043b\u043e\u0436\u0435\u043d\u043d\u043e\u0441\u0442\u044c, \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u0438 \u043b\u0443\u0447\u0448\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u0447\u0435\u0440\u0435\u0437 <code>TransactionTemplate<\/code> (\u0432 \u0434\u0435\u043c\u043e <code>\/api\/crime\/requires-new-fixed<\/code> \u043e\u0442\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0435\u0442 \u0437\u0430 ~20 \u043c\u0441 \u0431\u0435\u0437 \u0435\u0434\u0438\u043d\u043e\u0433\u043e \u0442\u0430\u0439\u043c\u0430\u0443\u0442\u0430):<\/p>\n<pre><code class=\"java\">public void process(Long taskId) {    transactionTemplate.executeWithoutResult(status -&gt; {        \/\/ \u043e\u0441\u043d\u043e\u0432\u043d\u0430\u044f \u0440\u0430\u0431\u043e\u0442\u0430 \u0441 \u0411\u0414    });    auditTrail.record(\"processed \" + taskId);}<\/code><div class=\"code-explainer\"><a href=\"https:\/\/sourcecraft.dev\/\" class=\"tm-button code-explainer__link\" style=\"visibility: hidden;\"><span class=\"sc-logo-wrapper icon-only\"><\/span><\/a><\/div><\/pre>\n<p>\u0415\u0441\u043b\u0438 \u0430\u0443\u0434\u0438\u0442 \u043d\u0443\u0436\u0435\u043d \u0438\u043c\u0435\u043d\u043d\u043e \u043f\u0440\u0438 \u043e\u0442\u043a\u0430\u0442\u0435 \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0439 \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u0438, \u043f\u0438\u0448\u0438\u0442\u0435 \u0435\u0433\u043e \u0432 \u0431\u043b\u043e\u043a\u0435 <code>catch<\/code> \u2014 \u043a\u043e\u0433\u0434\u0430 \u043f\u0435\u0440\u0432\u0430\u044f \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u044f \u0443\u0436\u0435 \u0437\u0430\u0432\u0435\u0440\u0448\u0438\u043b\u0430\u0441\u044c \u0438 \u043e\u0442\u0434\u0430\u043b\u0430 \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0435. \u0410 \u0435\u0441\u043b\u0438 \u043e\u0442 \u0432\u043b\u043e\u0436\u0435\u043d\u043d\u043e\u0441\u0442\u0438 \u043d\u0435 \u0443\u0439\u0442\u0438, \u0443 HikariCP \u0435\u0441\u0442\u044c \u0444\u043e\u0440\u043c\u0443\u043b\u0430 \u0437\u0430\u0449\u0438\u0442\u044b \u043e\u0442 \u0441\u0430\u043c\u043e\u0443\u0434\u0443\u0448\u0435\u043d\u0438\u044f \u043f\u0443\u043b\u0430: <code>pool size = Tn \u00d7 (Cm \u2212 1) + 1<\/code>, \u0433\u0434\u0435 <code>Tn<\/code> \u2014 \u0447\u0438\u0441\u043b\u043e \u043f\u043e\u0442\u043e\u043a\u043e\u0432, <code>Cm<\/code> \u2014 \u043c\u0430\u043a\u0441\u0438\u043c\u0443\u043c \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0439 \u043d\u0430 \u043f\u043e\u0442\u043e\u043a (\u043d\u0430 \u0434\u0435\u043c\u043e \u0441 <code>robbers=5<\/code> \u0438 <code>Cm = 2<\/code> \u043f\u0443\u043b \u043d\u0430 6 \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0439 \u043f\u0440\u043e\u0445\u043e\u0434\u0438\u0442 10 \u0438\u0437 10 \u043f\u0440\u043e\u0433\u043e\u043d\u043e\u0432 \u0431\u0435\u0437 \u0442\u0430\u0439\u043c\u0430\u0443\u0442\u043e\u0432). \u041d\u043e \u0432 \u0440\u0435\u0430\u043b\u044c\u043d\u043e\u043c \u043f\u0440\u043e\u0434\u0435 <code>Tn<\/code> \u2014 \u044d\u0442\u043e \u043f\u043e\u0442\u043e\u043a\u0438 Tomcat (\u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e 200), \u0438 \u0440\u0430\u0437\u0434\u0443\u0432\u0430\u0442\u044c \u043f\u0443\u043b \u0434\u043e 201 \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f \u043d\u0435\u043b\u044c\u0437\u044f: \u044d\u0442\u0430 \u0444\u043e\u0440\u043c\u0443\u043b\u0430 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0442\u043e\u043b\u044c\u043a\u043e \u0435\u0441\u043b\u0438 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0438\u0442\u044c \u043a\u043e\u043d\u043a\u0443\u0440\u0435\u043d\u0442\u043d\u043e\u0441\u0442\u044c \u0432\u043b\u043e\u0436\u0435\u043d\u043d\u043e\u0433\u043e \u0443\u0447\u0430\u0441\u0442\u043a\u0430 (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0441\u0435\u043c\u0430\u0444\u043e\u0440\u043e\u043c) \u0438\u043b\u0438 \u0432\u044b\u043d\u0435\u0441\u0442\u0438 \u0430\u0443\u0434\u0438\u0442 \u0432 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0439 \u043f\u0443\u043b.<\/p>\n<h4>\u0412\u0441\u0442\u0440\u0435\u0447\u043d\u044b\u0435 \u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u043a\u0438 (40P01)<\/h4>\n<p>\u0415\u0434\u0438\u043d\u0438\u0447\u043d\u044b\u0435 <code>PSQLException: ERROR: deadlock detected<\/code> (<code>40P01<\/code>) \u0441\u0430\u043c\u0438 \u043f\u043e \u0441\u0435\u0431\u0435 \u043f\u0443\u043b \u043d\u0435 \u0432\u0435\u0448\u0430\u044e\u0442: \u043a\u043e\u0433\u0434\u0430 \u0434\u0432\u0435 \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u0438 \u0431\u0435\u0440\u0443\u0442 <code>@Lock(PESSIMISTIC_WRITE)<\/code> \u043d\u0430 \u043e\u0434\u043d\u0438 \u0438 \u0442\u0435 \u0436\u0435 \u0434\u0432\u0435 \u0441\u0442\u0440\u043e\u043a\u0438 \u0432 \u0440\u0430\u0437\u043d\u043e\u043c \u043f\u043e\u0440\u044f\u0434\u043a\u0435, Postgres \u0447\u0435\u0440\u0435\u0437 <code>deadlock_timeout<\/code> (1 \u0441\u0435\u043a\u0443\u043d\u0434\u0430) \u043f\u0440\u0438\u0431\u0438\u0432\u0430\u0435\u0442 \u043e\u0434\u043d\u0443 \u0438\u0437 \u043d\u0438\u0445. \u041d\u043e \u043d\u0430 \u043a\u0430\u0436\u0434\u044b\u0439 \u0442\u0430\u043a\u043e\u0439 \u0438\u043d\u0446\u0438\u0434\u0435\u043d\u0442 \u0434\u0432\u0430 \u043a\u043e\u043d\u043d\u0435\u043a\u0442\u0430 \u0432\u044b\u043f\u0430\u0434\u0430\u044e\u0442 \u0438\u0437 \u0440\u0430\u0431\u043e\u0442\u044b \u043d\u0430 \u0441\u0435\u043a\u0443\u043d\u0434\u0443, \u043f\u043b\u044e\u0441 \u043e\u0442\u043a\u0430\u0442 \u0438 \u0440\u0435\u0442\u0440\u0430\u0439. \u041b\u0435\u0447\u0438\u0442\u0441\u044f \u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u043a\u043e\u0439 <code>id<\/code> \u043f\u0435\u0440\u0435\u0434 \u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u043a\u043e\u0439 (<code>Math.min(idA, idB)<\/code> \u2192 <code>Math.max(idA, idB)<\/code>), \u0447\u0442\u043e\u0431\u044b \u0432\u0441\u0435 \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u0438 \u0431\u0440\u0430\u043b\u0438 \u0441\u0442\u0440\u043e\u043a\u0438 \u0432 \u043e\u0434\u043d\u043e\u043c \u043f\u043e\u0440\u044f\u0434\u043a\u0435; \u0432 \u0434\u0435\u043c\u043e \u043e\u0431\u0430 \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u0430 \u043b\u0435\u0436\u0430\u0442 \u043d\u0430 <code>\/api\/crime\/deadlock<\/code> \u0438 <code>\/api\/crime\/deadlock-fixed<\/code>.<\/p>\n<hr\/>\n<h3>\u0427\u0435\u043a\u043b\u0438\u0441\u0442 \u0438 \u0430\u043b\u0435\u0440\u0442\u044b<\/h3>\n<p>\u041a\u043e\u0440\u043e\u0442\u043a\u0430\u044f \u043f\u0430\u043c\u044f\u0442\u043a\u0430, \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u043c\u044b \u043e\u0441\u0442\u0430\u0432\u0438\u043b\u0438 \u0432 \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0438:<\/p>\n<ul>\n<li>\n<p><strong>\u0413\u0440\u0430\u043d\u0438\u0446\u044b \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u0439:<\/strong> \u0432\u043d\u0443\u0442\u0440\u0438 <code>@Transactional<\/code> \u0442\u043e\u043b\u044c\u043a\u043e \u0440\u0430\u0431\u043e\u0442\u0430 \u0441 \u0411\u0414. \u0412\u043d\u0435\u0448\u043d\u0438\u0439 HTTP, Kafka, \u0444\u0430\u0439\u043b\u044b \u2014 \u0441\u043d\u0430\u0440\u0443\u0436\u0438 (\u0447\u0435\u0440\u0435\u0437 <code>TransactionTemplate<\/code>, <code>@TransactionalEventListener(AFTER_COMMIT)<\/code> + <code>@Async<\/code> \u0438\u043b\u0438 Transactional Outbox, \u0435\u0441\u043b\u0438 \u043d\u0435\u043b\u044c\u0437\u044f \u0442\u0435\u0440\u044f\u0442\u044c \u0441\u043e\u0431\u044b\u0442\u0438\u044f). \u041d\u0430 \u043f\u0438\u0448\u0443\u0449\u0438\u0445 \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u044f\u0445 \u2014 <code>timeout<\/code>, \u043d\u0430 \u0447\u0438\u0442\u0430\u044e\u0449\u0438\u0445 \u2014 <code>readOnly = true<\/code>.<\/p>\n<\/li>\n<li>\n<p><strong>\u041f\u0440\u043e\u043a\u0441\u0438 \u0438 \u0432\u043b\u043e\u0436\u0435\u043d\u043d\u043e\u0441\u0442\u044c:<\/strong> \u043d\u0435 \u0432\u044b\u0437\u044b\u0432\u0430\u0442\u044c <code>@Transactional<\/code> \u0447\u0435\u0440\u0435\u0437 <code>this<\/code> \u0438 \u043d\u0435 \u0432\u0435\u0448\u0430\u0442\u044c \u043d\u0430 <code>private<\/code>. <code>REQUIRES_NEW<\/code> \u0432\u043d\u0443\u0442\u0440\u0438 \u043e\u0442\u043a\u0440\u044b\u0442\u043e\u0439 \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u0438 \u2014 \u044d\u0442\u043e \u0432\u0442\u043e\u0440\u043e\u0439 \u043a\u043e\u043d\u043d\u0435\u043a\u0442 \u043d\u0430 \u043f\u043e\u0442\u043e\u043a: \u043b\u0443\u0447\u0448\u0435 \u0440\u0430\u0437\u0432\u043e\u0440\u0430\u0447\u0438\u0432\u0430\u0442\u044c \u0432 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c, \u0430 \u0435\u0441\u043b\u0438 \u0432\u043b\u043e\u0436\u0435\u043d\u043d\u043e\u0441\u0442\u044c \u043d\u0435\u0438\u0437\u0431\u0435\u0436\u043d\u0430 \u2014 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0438\u0432\u0430\u0442\u044c \u043a\u043e\u043d\u043a\u0443\u0440\u0435\u043d\u0442\u043d\u043e\u0441\u0442\u044c \u0443\u0447\u0430\u0441\u0442\u043a\u0430 \u0438 \u0441\u0447\u0438\u0442\u0430\u0442\u044c \u043f\u0443\u043b \u043f\u043e <code>Tn \u00d7 (Cm \u2212 1) + 1<\/code>.<\/p>\n<\/li>\n<li>\n<p><strong>\u041f\u0443\u043b \u0438 \u0411\u0414:<\/strong> <code>leak-detection-threshold<\/code> \u0432\u043a\u043b\u044e\u0447\u0451\u043d \u0432\u0441\u0435\u0433\u0434\u0430 (30\u201360 \u0441\u0435\u043a\u0443\u043d\u0434 \u0432 \u043f\u0440\u043e\u0434\u0435), <code>connection-timeout<\/code> \u043c\u0435\u043d\u044c\u0448\u0435 \u0442\u0430\u0439\u043c\u0430\u0443\u0442\u0430 \u043a\u043b\u0438\u0435\u043d\u0442\u0430, \u043d\u0430 \u0441\u0442\u043e\u0440\u043e\u043d\u0435 Postgres \u2014 <code>idle_in_transaction_session_timeout<\/code>. \u0420\u0430\u0437\u043c\u0435\u0440 \u043f\u0443\u043b\u0430 \u0441\u0447\u0438\u0442\u0430\u0442\u044c \u043e\u0442 \u0444\u043e\u0440\u043c\u0443\u043b\u044b HikariCP <code>cores * 2 + effective_spindle_count<\/code>, \u0433\u0434\u0435 <code>cores<\/code> \u2014 \u044f\u0434\u0440\u0430 \u0441\u0435\u0440\u0432\u0435\u0440\u0430 \u0411\u0414 (\u0430 \u043d\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f), \u0438 \u044d\u0442\u043e\u0442 \u0431\u044e\u0434\u0436\u0435\u0442 \u0434\u0435\u043b\u0438\u0442\u0441\u044f \u043c\u0435\u0436\u0434\u0443 \u0432\u0441\u0435\u043c\u0438 \u0440\u0435\u043f\u043b\u0438\u043a\u0430\u043c\u0438 \u0441\u0435\u0440\u0432\u0438\u0441\u0430.<\/p>\n<\/li>\n<li>\n<p><strong>\u0411\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u043a\u0438:<\/strong> \u0431\u0440\u0430\u0442\u044c \u0441\u0442\u0440\u043e\u043a\u0438 \u0432 \u043e\u0434\u043d\u043e\u043c \u043f\u043e\u0440\u044f\u0434\u043a\u0435 (\u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u043a\u0430 \u043f\u043e <code>id<\/code>), \u0434\u0435\u0440\u0436\u0430\u0442\u044c \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u0438 \u0441 <code>SELECT FOR UPDATE<\/code> \u043a\u043e\u0440\u043e\u0442\u043a\u0438\u043c\u0438.<\/p>\n<\/li>\n<li>\n<p><strong>OSIV:<\/strong> <code>spring.jpa.open-in-view: false<\/code>, \u043d\u0430\u0440\u0443\u0436\u0443 \u043e\u0442\u0434\u0430\u0432\u0430\u0442\u044c DTO, \u043d\u0443\u0436\u043d\u044b\u0435 \u0441\u0432\u044f\u0437\u0438 \u0433\u0440\u0443\u0437\u0438\u0442\u044c \u0447\u0435\u0440\u0435\u0437 <code>fetch join<\/code> \u0438\u043b\u0438 <code>@EntityGraph<\/code>.<\/p>\n<\/li>\n<\/ul>\n<p>\u0410\u043b\u0435\u0440\u0442\u044b Prometheus \u0438\u0437 \u0434\u0435\u043c\u043e-\u043f\u0440\u043e\u0435\u043a\u0442\u0430 (\u0434\u043b\u044f <code>LongConnectionUsage<\/code> \u0432 \u043f\u0440\u043e\u0434\u0435 \u043f\u043e\u043b\u0435\u0437\u043d\u043e \u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u043d\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u043d\u0430 \u0441\u0440\u0435\u0434\u043d\u0435\u0435, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0441\u0433\u043b\u0430\u0436\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u043f\u0440\u0438 \u0447\u0430\u0441\u0442\u0438\u0447\u043d\u043e\u0439 \u0434\u0435\u0433\u0440\u0430\u0434\u0430\u0446\u0438\u0438, \u043d\u043e \u0438 \u043d\u0430 <code>hikaricp_connections_usage_seconds_max<\/code> \u0432\u043c\u0435\u0441\u0442\u0435 \u0441\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u0435\u043c <code>acquire<\/code>):<\/p>\n<pre><code class=\"yaml\">- alert: ConnectionPoolPending  expr: hikaricp_connections_pending{pool=\"TodoHikariPool\"} &gt; 0  for: 1m  labels:    severity: warning- alert: ConnectionTimeouts  expr: increase(hikaricp_connections_timeout_total{pool=\"TodoHikariPool\"}[5m]) &gt; 0  for: 1m  labels:    severity: critical- alert: LongConnectionUsage  expr: |    rate(hikaricp_connections_usage_seconds_sum{pool=\"TodoHikariPool\"}[5m])    \/ rate(hikaricp_connections_usage_seconds_count{pool=\"TodoHikariPool\"}[5m]) &gt; 1  for: 5m  labels:    severity: warning<\/code><div class=\"code-explainer\"><a href=\"https:\/\/sourcecraft.dev\/\" class=\"tm-button code-explainer__link\" style=\"visibility: hidden;\"><span class=\"sc-logo-wrapper icon-only\"><\/span><\/a><\/div><\/pre>\n<hr\/>\n<h3>\u0418\u0442\u043e\u0433<\/h3>\n<p>\u041f\u043e\u0441\u043b\u0435 \u043e\u0442\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f OSIV \u0433\u0440\u0430\u0444\u0438\u043a\u0438 \u0443\u0441\u043f\u043e\u043a\u043e\u0438\u043b\u0438\u0441\u044c: usage \u0432\u0435\u0440\u043d\u0443\u043b\u0441\u044f \u0441 \u043f\u0438\u043a\u043e\u0432\u044b\u0445 1.2\u20134.8 \u0441 \u043e\u0431\u0440\u0430\u0442\u043d\u043e \u043a \u043f\u0440\u0438\u0432\u044b\u0447\u043d\u044b\u043c 4\u20136 \u043c\u0441, <code>pending<\/code> \u0432 \u043d\u0443\u043b\u0435. \u041a\u043e\u0433\u0434\u0430 \u0441\u0435\u0440\u0432\u0438\u0441 \u0443\u0432\u0435\u0434\u043e\u043c\u043b\u0435\u043d\u0438\u0439 \u0441\u043d\u043e\u0432\u0430 \u0442\u043e\u0440\u043c\u043e\u0437\u0438\u0442, \u043e\u043d \u0432\u0441\u0451 \u0435\u0449\u0451 \u0441\u043f\u043e\u0441\u043e\u0431\u0435\u043d \u0437\u0430\u043d\u044f\u0442\u044c \u043f\u043e\u0442\u043e\u043a\u0438 Tomcat \u043d\u0430 \u0431\u043e\u043b\u044c\u0448\u043e\u043c RPS (\u0434\u0430\u043b\u044c\u0448\u0435 \u044d\u0442\u043e \u0443\u0436\u0435 \u0432\u043e\u043f\u0440\u043e\u0441 <code>bulkhead<\/code> \u0438 \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e\u0441\u0442\u0438), \u043d\u043e \u043f\u0443\u043b \u0411\u0414 \u0431\u043e\u043b\u044c\u0448\u0435 \u043d\u0435 \u043b\u043e\u0436\u0438\u0442\u0441\u044f \u0441\u043b\u0435\u0434\u043e\u043c. \u041f\u0443\u043b \u0440\u0435\u0434\u043a\u043e \u0431\u044b\u0432\u0430\u0435\u0442 \u00ab\u0441\u043b\u0438\u0448\u043a\u043e\u043c \u043c\u0430\u043b\u0435\u043d\u044c\u043a\u0438\u043c\u00bb \u2014 \u043e\u0431\u044b\u0447\u043d\u043e \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0439 \u0445\u0432\u0430\u0442\u0430\u0435\u0442 \u0440\u043e\u0432\u043d\u043e \u0434\u043e \u0442\u0435\u0445 \u043f\u043e\u0440, \u043f\u043e\u043a\u0430 \u0438\u0445 \u043d\u043e\u0440\u043c\u0430\u043b\u044c\u043d\u043e \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u044e\u0442. \u0421 \u0434\u0435\u043d\u044c\u0433\u0430\u043c\u0438, \u0432\u043f\u0440\u043e\u0447\u0435\u043c, \u0442\u0430 \u0436\u0435 \u0438\u0441\u0442\u043e\u0440\u0438\u044f, \u0442\u043e\u043b\u044c\u043a\u043e \u0442\u0430\u043c <code>try-with-resources<\/code> \u043d\u0435 \u043f\u043e\u0434\u0432\u0435\u0437\u043b\u0438.<\/p>\n<p>\u0415\u0441\u043b\u0438 \u0445\u043e\u0442\u0438\u0442\u0435 \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c \u0441\u0432\u043e\u0439 \u0441\u0435\u0440\u0432\u0438\u0441 \u0437\u0430 \u0434\u0435\u0441\u044f\u0442\u044c \u043c\u0438\u043d\u0443\u0442, \u043d\u0430\u0447\u043d\u0438\u0442\u0435 \u0441 \u0442\u0440\u0451\u0445 \u0432\u0435\u0449\u0435\u0439: \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u0442\u0435 <code>hikaricp_connections_pending<\/code> \u0432 Grafana, \u043f\u0440\u043e\u0432\u0435\u0440\u044c\u0442\u0435 \u043b\u043e\u0433 \u0441\u0442\u0430\u0440\u0442\u0430 \u043d\u0430 \u043f\u0440\u0435\u0434\u0443\u043f\u0440\u0435\u0436\u0434\u0435\u043d\u0438\u0435 \u043f\u0440\u043e <code>open-in-view<\/code> \u0438 \u0433\u0440\u0435\u043f\u043d\u0438\u0442\u0435 \u043f\u0440\u043e\u0435\u043a\u0442 \u043d\u0430 <code>getConnection()<\/code>.<\/p>\n<hr\/>\n<h3>\u0421\u0441\u044b\u043b\u043a\u0438 \u0438 \u0434\u0435\u043c\u043e<\/h3>\n<ul>\n<li>\n<p><a href=\"https:\/\/github.com\/brettwooldridge\/HikariCP\/wiki\/About-Pool-Sizing\" rel=\"noopener nofollow\">HikariCP: About Pool Sizing<\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"https:\/\/docs.spring.io\/spring-framework\/reference\/data-access\/transaction.html\" rel=\"noopener nofollow\">Spring: Transaction Management<\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"https:\/\/www.postgresql.org\/docs\/current\/explicit-locking.html\" rel=\"noopener nofollow\">PostgreSQL: Explicit Locking<\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"https:\/\/vladmihalcea.com\/the-open-session-in-view-anti-pattern\/\" rel=\"noopener nofollow\">Vlad Mihalcea: The Open Session In View Anti-Pattern<\/a><\/p>\n<\/li>\n<li>\n<p>\u041f\u0440\u043e\u0448\u043b\u0430\u044f \u0447\u0430\u0441\u0442\u044c: <a href=\"https:\/\/habr.com\/ru\/articles\/1046239\/\" rel=\"noopener nofollow\">\u0414\u0435\u043b\u043e \u043e \u043c\u043e\u043b\u0447\u0430\u043b\u0438\u0432\u043e\u0439 JVM<\/a><\/p>\n<\/li>\n<li>\n<p>\u0414\u0435\u043c\u043e-\u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0439: <a href=\"https:\/\/github.com\/PrikGeorge\/todo-transactions-demo\" rel=\"noopener nofollow\">PrikGeorge\/todo-transactions-demo<\/a> \u2014 \u043f\u043e\u0434\u043d\u0438\u043c\u0430\u0435\u0442\u0441\u044f \u0447\u0435\u0440\u0435\u0437 <code>docker compose up<\/code>, \u0432\u0441\u0435 \u044d\u043d\u0434\u043f\u043e\u0438\u043d\u0442\u044b <code>\/api\/crime\/*<\/code>, \u0438\u0445 \u0438\u0441\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u043d\u044b\u0435 \u0432\u0435\u0440\u0441\u0438\u0438, \u0434\u0430\u0448\u0431\u043e\u0440\u0434 Grafana \u0438 \u043f\u0440\u0430\u0432\u0438\u043b\u0430 Prometheus \u0432\u043d\u0443\u0442\u0440\u0438.<\/p>\n<\/li>\n<\/ul>\n<p>\u0415\u0441\u043b\u0438 \u0440\u0430\u0437\u0431\u043e\u0440 \u043f\u0440\u0438\u0433\u043e\u0434\u0438\u043b\u0441\u044f \u2014 \u0441\u0442\u0430\u0432\u044c\u0442\u0435 \u043f\u043b\u044e\u0441 \u0438 \u0437\u0430\u0433\u043b\u044f\u0434\u044b\u0432\u0430\u0439\u0442\u0435 \u0432 <a href=\"https:\/\/t.me\/JavaZavrOfficial\" rel=\"noopener nofollow\">\u0442\u0435\u043b\u0435\u0433\u0440\u0430\u043c-\u043a\u0430\u043d\u0430\u043b<\/a>.<\/p>\n<\/div>\n<p>\u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/articles\/1111240\/\">https:\/\/habr.com\/ru\/articles\/1111240\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u0421\u0435\u0440\u0432\u0438\u0441 \u043f\u043e \u0432\u0441\u0435\u043c \u0432\u043d\u0435\u0448\u043d\u0438\u043c \u043f\u0440\u0438\u0437\u043d\u0430\u043a\u0430\u043c \u0436\u0438\u0432: health check \u0437\u0435\u043b\u0451\u043d\u044b\u0439, \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0440 \u043f\u043e\u0447\u0442\u0438 \u043f\u0440\u043e\u0441\u0442\u0430\u0438\u0432\u0430\u0435\u0442, \u0432 \u043b\u043e\u0433\u0430\u0445 \u0442\u0438\u0445\u043e. \u0422\u043e\u043b\u044c\u043a\u043e HTTP-\u0437\u0430\u043f\u0440\u043e\u0441\u044b \u043f\u0435\u0440\u0435\u0441\u0442\u0430\u043b\u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0442\u044c\u0441\u044f. \u041d\u0438\u0436\u0435 \u2014 \u0440\u0430\u0437\u0431\u043e\u0440 \u043d\u043e\u0447\u043d\u043e\u0433\u043e \u0438\u043d\u0446\u0438\u0434\u0435\u043d\u0442\u0430 \u0441 \u043f\u0443\u043b\u043e\u043c HikariCP, \u043d\u0435\u043e\u0436\u0438\u0434\u0430\u043d\u043d\u0430\u044f \u0437\u0430\u0441\u0430\u0434\u0430 \u0441 Open Session In View \u0438 \u0435\u0449\u0451 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0442\u0438\u043f\u043e\u0432\u044b\u0445 \u0433\u0440\u0430\u0431\u043b\u0435\u0439 \u0441 \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u044f\u043c\u0438 \u0432 Spring Boot, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u044f \u0441\u043e\u0431\u0440\u0430\u043b \u0432 \u043e\u0434\u0438\u043d \u0434\u0435\u043c\u043e-\u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0439.\u0427\u0435\u0442\u0432\u0435\u0440\u0433, 23:10\u041f\u043e\u0441\u043b\u0435 \u043f\u0440\u043e\u0448\u043b\u043e\u0439 \u0438\u0441\u0442\u043e\u0440\u0438\u0438 \u0441 \u043c\u043e\u043b\u0447\u0430\u043b\u0438\u0432\u043e\u0439 JVM \u043c\u043e\u043d\u0438\u0442\u043e\u0440\u0438\u043d\u0433 \u0431\u043e\u043b\u0435\u0435-\u043c\u0435\u043d\u0435\u0435 \u043f\u0440\u0438\u0432\u0435\u043b\u0438 \u0432 \u043f\u043e\u0440\u044f\u0434\u043e\u043a: Prometheus \u0441\u043e\u0431\u0438\u0440\u0430\u0435\u0442 \u043c\u0435\u0442\u0440\u0438\u043a\u0438, \u0432 Grafana \u0435\u0441\u0442\u044c \u0434\u0430\u0448\u0431\u043e\u0440\u0434\u044b, \u0430\u043b\u0435\u0440\u0442\u044b \u043d\u0435 \u0434\u0451\u0440\u0433\u0430\u044e\u0442 \u043f\u043e \u043c\u0435\u043b\u043e\u0447\u0430\u043c.\u0412 \u0447\u0435\u0442\u0432\u0435\u0440\u0433 \u0432 23:10 \u0432 \u0440\u0430\u0431\u043e\u0447\u0438\u0439 \u0447\u0430\u0442 \u043d\u0430\u043f\u0438\u0441\u0430\u043b \u0414\u0430\u043d\u044f, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0434\u0435\u0436\u0443\u0440\u0438\u043b \u043d\u0430 \u0442\u043e\u0439 \u043d\u0435\u0434\u0435\u043b\u0435:\u00ab\u0421\u0435\u0440\u0432\u0438\u0441 \u043b\u0435\u0436\u0438\u0442, \u0445\u043e\u0442\u044f k8s \u0441\u0447\u0438\u0442\u0430\u0435\u0442 \u0435\u0433\u043e \u0436\u0438\u0432\u044b\u043c. p99 \u0443\u043b\u0435\u0442\u0435\u043b \u0432 \u043f\u043e\u0442\u043e\u043b\u043e\u043a, \u0441\u0440\u0430\u0431\u043e\u0442\u0430\u043b ConnectionTimeouts. \u0417\u0430\u0448\u0451\u043b \u0432 \u043f\u043e\u0441\u0442\u0433\u0440\u0435\u0441 \u0440\u0443\u043a\u0430\u043c\u0438 \u2014 \u0431\u0430\u0437\u0430 \u043f\u043e\u0447\u0442\u0438 \u043f\u0443\u0441\u0442\u0430\u044f, \u043e\u0431\u044b\u0447\u043d\u044b\u0435 \u0441\u0435\u043b\u0435\u043a\u0442\u044b \u043e\u0442\u0434\u0430\u044e\u0442\u0441\u044f \u0437\u0430 \u043f\u0430\u0440\u0443 \u043c\u0441\u00bb.\u0421\u0442\u0435\u043a \u043d\u0430 \u0441\u0442\u0435\u043d\u0434\u0435: Spring Boot 3.2.1, Hibernate 6.4.1.Final, HikariCP 5.0.1, PostgreSQL 16.15, JDK 17.0.21 (\u0437\u0430\u0431\u0435\u0433\u0430\u044f \u0432\u043f\u0435\u0440\u0451\u0434 \u2014 \u0433\u043b\u0430\u0432\u043d\u044b\u0439 \u0441\u044e\u0440\u043f\u0440\u0438\u0437 \u0441 \u0434\u0435\u0444\u043e\u043b\u0442\u043d\u044b\u043c open-in-view: true \u043d\u0438\u043a\u0443\u0434\u0430 \u043d\u0435 \u0434\u0435\u043b\u0441\u044f \u0438 \u0432 \u0431\u043e\u043b\u0435\u0435 \u0441\u0432\u0435\u0436\u0438\u0445 \u0432\u0435\u0440\u0441\u0438\u044f\u0445 Spring Boot).\u041f\u0435\u0440\u0432\u044b\u0435 \u043c\u0438\u043d\u0443\u0442 \u0434\u0432\u0430\u0434\u0446\u0430\u0442\u044c \u044f \u043f\u043e \u0441\u0442\u0430\u0440\u043e\u0439 \u043f\u0440\u0438\u0432\u044b\u0447\u043a\u0435 \u0438\u0441\u043a\u0430\u043b \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0443 \u0432\u0435\u0437\u0434\u0435, \u043a\u0440\u043e\u043c\u0435 \u043e\u0447\u0435\u0432\u0438\u0434\u043d\u043e\u0433\u043e. \u0421\u043d\u0430\u0447\u0430\u043b\u0430 \u0433\u0440\u0435\u0448\u0438\u043b \u043d\u0430 \u0432\u0435\u0447\u0435\u0440\u043d\u0438\u0439 \u0440\u0435\u043b\u0438\u0437 \u0438 \u043f\u043e\u043b\u0435\u0437 \u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u043f\u0430\u0443\u0437\u044b GC \u2014 \u0442\u0430\u043c \u0440\u043e\u0432\u043d\u043e. \u041f\u043e\u0442\u043e\u043c \u043e\u0442\u043a\u0440\u044b\u043b pg_stat_statements \u0432 \u043d\u0430\u0434\u0435\u0436\u0434\u0435 \u043f\u043e\u0439\u043c\u0430\u0442\u044c \u0441\u0432\u0435\u0436\u0438\u0439 SELECT \u0431\u0435\u0437 \u0438\u043d\u0434\u0435\u043a\u0441\u0430 \u2014 CPU \u0443 \u0431\u0430\u0437\u044b \u043e\u043a\u043e\u043b\u043e 10%, \u043c\u0435\u0434\u043b\u0435\u043d\u043d\u044b\u0445 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u043d\u0435\u0442. \u041f\u0440\u043e\u0432\u0435\u0440\u0438\u043b \u0441\u0435\u0442\u044c \u0434\u043e \u0431\u0430\u0437\u044b \u0438 \u0443\u0436\u0435 \u0441\u043e\u0431\u0438\u0440\u0430\u043b\u0441\u044f \u043e\u0431\u0432\u0438\u043d\u0438\u0442\u044c \u0432\u043e \u0432\u0441\u0451\u043c k8s, \u043d\u043e \u0432\u0441\u0451-\u0442\u0430\u043a\u0438 \u043e\u0442\u043a\u0440\u044b\u043b \u043f\u0430\u043d\u0435\u043b\u044c HikariCP \u0432 Grafana.\u0412 \u043f\u0440\u043e\u0434\u0435 \u043f\u0443\u043b \u043d\u0430\u0441\u0442\u0440\u043e\u0435\u043d \u043d\u0430 15 \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0439. \u0412 \u0434\u0435\u043c\u043e-\u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0438 \u043a \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u044f \u0443\u0440\u0435\u0437\u0430\u043b \u0435\u0433\u043e \u0434\u043e 5 \u0441 connection-timeout: 5000, \u0447\u0442\u043e\u0431\u044b \u043d\u0435 \u0433\u043e\u0440\u043e\u0434\u0438\u0442\u044c \u043d\u0430\u0433\u0440\u0443\u0437\u043e\u0447\u043d\u044b\u0439 \u0433\u0435\u043d\u0435\u0440\u0430\u0442\u043e\u0440 \u0438 \u043b\u043e\u043c\u0430\u0442\u044c \u0432\u0441\u0451 \u043f\u0430\u0440\u043e\u0439 curl. \u041a\u043e\u0433\u0434\u0430 \u0432\u0441\u0435 \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f \u0437\u0430\u043d\u044f\u0442\u044b, \u043d\u043e\u0432\u044b\u0435 \u043f\u043e\u0442\u043e\u043a\u0438 \u0432\u0441\u0442\u0430\u044e\u0442 \u0432 \u043e\u0447\u0435\u0440\u0435\u0434\u044c, \u0436\u0434\u0443\u0442 \u0442\u0430\u0439\u043c\u0430\u0443\u0442 \u0438 \u043f\u0430\u0434\u0430\u044e\u0442 \u0441 SQLTransientConnectionException.\u041e\u0441\u043c\u043e\u0442\u0440: \u043c\u0435\u0442\u0440\u0438\u043a\u0438, jstack \u0438 pg_stat_activity\u0412 Grafana \u043e\u0442\u043a\u0440\u044b\u0432\u0430\u0435\u043c \u043f\u0430\u043d\u0435\u043b\u044c \u043f\u0443\u043b\u0430 \u2014 \u0435\u0449\u0451 \u0441 \u043f\u0440\u043e\u0448\u043b\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0438 \u043e\u043d\u0430 \u0443 \u043d\u0430\u0441 \u0442\u0430\u043a \u0438 \u043d\u0430\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f Bar \u2018U Hikari\u2019, \u043f\u043e \u0430\u043d\u0430\u043b\u043e\u0433\u0438\u0438 \u0441 \u0431\u0430\u0440\u043e\u043c \u043d\u0430 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0441\u0442\u043e\u043b\u0438\u043a\u043e\u0432, \u0433\u0434\u0435 \u0431\u0430\u0440\u043c\u0435\u043d \u0441\u0442\u043e\u0438\u0442 \u0441 \u0441\u0435\u043a\u0443\u043d\u0434\u043e\u043c\u0435\u0440\u043e\u043c. \u0421\u043c\u043e\u0442\u0440\u0438\u043c \u043d\u0430 \u0447\u0435\u0442\u044b\u0440\u0435 \u0431\u0430\u0437\u043e\u0432\u044b\u0435 \u043c\u0435\u0442\u0440\u0438\u043a\u0438:hikaricp_connections_activehikaricp_connections_idlehikaricp_connections_pendinghikaricp_connections_timeout_total\u0412 \u043d\u043e\u0440\u043c\u0430\u043b\u044c\u043d\u043e\u0439 \u0440\u0430\u0431\u043e\u0442\u0435 pending \u043f\u0440\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u0432\u0441\u0435\u0433\u0434\u0430 \u0440\u0430\u0432\u0435\u043d \u043d\u0443\u043b\u044e (\u043a\u043e\u0440\u043e\u0442\u043a\u0438\u0435 \u0432\u0441\u043f\u043b\u0435\u0441\u043a\u0438 \u043d\u0430 \u043c\u0438\u043b\u043b\u0438\u0441\u0435\u043a\u0443\u043d\u0434\u044b \u043f\u043e\u0434 \u043d\u0430\u0433\u0440\u0443\u0437\u043a\u043e\u0439 \u043d\u043e\u0440\u043c\u0430\u043b\u044c\u043d\u044b, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0432 \u0430\u043b\u0435\u0440\u0442\u0435 \u0441\u0442\u043e\u0438\u0442 for: 1m). \u0423 \u043d\u0430\u0441 active \u0443\u043f\u0451\u0440\u0441\u044f \u0432 \u043f\u043e\u0442\u043e\u043b\u043e\u043a \u043f\u0443\u043b\u0430, idle \u0443\u043f\u0430\u043b \u0432 \u043d\u043e\u043b\u044c, pending \u0434\u0435\u0440\u0436\u0430\u043b\u0441\u044f \u0432 \u0440\u0430\u0439\u043e\u043d\u0435 12, \u0430 timeout_total \u0440\u043e\u0441. \u0415\u0449\u0451 \u0434\u0432\u0430 \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u044e\u0442, \u0434\u043e\u043b\u0433\u043e \u043b\u0438 \u043f\u043e\u0442\u043e\u043a\u0438 \u0436\u0434\u0443\u0442 \u0432 \u043e\u0447\u0435\u0440\u0435\u0434\u0438 \u0438 \u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0434\u0435\u0440\u0436\u0430\u0442 \u0441\u0430\u043c\u043e \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0435:# \u0412\u0440\u0435\u043c\u044f \u043e\u0436\u0438\u0434\u0430\u043d\u0438\u044f \u0432 \u043e\u0447\u0435\u0440\u0435\u0434\u0438 (acquire)rate(hikaricp_connections_acquire_seconds_sum[1m])\/ rate(hikaricp_connections_acquire_seconds_count[1m])# \u0412\u0440\u0435\u043c\u044f \u0443\u0434\u0435\u0440\u0436\u0430\u043d\u0438\u044f \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f (usage)rate(hikaricp_connections_usage_seconds_sum[1m])\/ rate(hikaricp_connections_usage_seconds_count[1m])\u0414\u0430\u0448\u0431\u043e\u0440\u0434 \u043f\u0443\u043b\u0430 \u043d\u0430 \u0434\u0435\u043c\u043e-\u0441\u0442\u0435\u043d\u0434\u0435 \u043f\u043e\u0434 \u043d\u0430\u0433\u0440\u0443\u0437\u043a\u043e\u0439: \u0432\u0441\u0435 5 \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0439 \u0437\u0430\u043d\u044f\u0442\u044b, 5 \u043f\u043e\u0442\u043e\u043a\u043e\u0432 \u0436\u0434\u0443\u0442 \u0432 \u043e\u0447\u0435\u0440\u0435\u0434\u0438, usage \u0443\u0448\u0451\u043b \u0437\u0430 4 \u0441\u0435\u043a\u0443\u043d\u0434\u044b \u0438 \u043f\u043e\u0448\u043b\u0438 \u0442\u0430\u0439\u043c\u0430\u0443\u0442\u044b\u041e\u0431\u044b\u0447\u043d\u043e usage \u0443 \u043d\u0430\u0441 \u0431\u044b\u043b \u0432 \u0440\u0430\u0439\u043e\u043d\u0435 4\u20136 \u043c\u0441. \u0422\u043e\u0439 \u043d\u043e\u0447\u044c\u044e \u043e\u043d \u0441\u043a\u0430\u043a\u0430\u043b \u043e\u0442 1.2 \u0434\u043e 4.8 \u0441\u0435\u043a\u0443\u043d\u0434\u044b \u2014 \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f \u0431\u0440\u0430\u043b\u0438 \u0438 \u043d\u0435 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u043b\u0438.\u041f\u043e\u043b\u0435\u0437\u043b\u0438 \u0441\u043d\u0438\u043c\u0430\u0442\u044c thread dump. \u0412 \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u044b\u0445 \u043e\u0431\u0440\u0430\u0437\u0430\u0445 \u0432\u0440\u043e\u0434\u0435 eclipse-temurin:17-jre-alpine \u0443\u0442\u0438\u043b\u0438\u0442\u044b jstack \u0432\u043d\u0443\u0442\u0440\u0438 \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440\u0430 \u043d\u0435\u0442. \u0421\u0430\u043c\u044b\u0439 \u0431\u044b\u0441\u0442\u0440\u044b\u0439 \u0441\u043f\u043e\u0441\u043e\u0431 \u0431\u0435\u0437 JDK-\u0443\u0442\u0438\u043b\u0438\u0442 \u2014 \u043f\u043e\u0441\u043b\u0430\u0442\u044c \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0443 kill -3 1, \u0442\u043e\u0433\u0434\u0430 JVM \u0441\u0431\u0440\u043e\u0441\u0438\u0442 \u0434\u0430\u043c\u043f \u043f\u0440\u044f\u043c\u043e \u0432 docker logs \u0438\u043b\u0438 kubectl logs. \u0415\u0441\u043b\u0438 \u043d\u0443\u0436\u043d\u043e \u0441\u043e\u0445\u0440\u0430\u043d\u0438\u0442\u044c \u0435\u0433\u043e \u0432 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0439 \u0444\u0430\u0439\u043b, \u0432 k8s \u0432\u044b\u0440\u0443\u0447\u0430\u0435\u0442 kubectl debug, \u0430 \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u043e \u043d\u0430 docker compose \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0438\u0442\u044c JDK-\u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440 \u043a \u0442\u043e\u043c\u0443 \u0436\u0435 PID-\u043d\u0435\u0439\u043c\u0441\u043f\u0435\u0439\u0441\u0443:docker run &#8212;rm &#8212;pid=container:todo-tx-app &#8212;user 1001:1001 \\  eclipse-temurin:17-jdk jstack 1 &gt; threads.txt\u0412 \u0434\u0430\u043c\u043f\u0435 \u0441\u0440\u0430\u0437\u0443 \u0432\u0438\u0434\u043d\u044b \u043e\u0431\u0435 \u0441\u0442\u043e\u0440\u043e\u043d\u044b \u043a\u0430\u0440\u0442\u0438\u043d\u044b. \u041e\u0436\u0438\u0434\u0430\u044e\u0449\u0438\u0435 \u043f\u043e\u0442\u043e\u043a\u0438 Tomcat \u0432\u0438\u0441\u044f\u0442 \u0432 TIMED_WAITING (parking) \u043d\u0430 ConcurrentBag.borrow:&#187;http-nio-8080-exec-2&#8243; #37 daemon prio=5 os_prio=0 cpu=6.48ms elapsed=40.14s tid=0x00007f069f2716c0 nid=0x42 waiting on condition  [0x00007f069ea3e000]   java.lang.Thread.State: TIMED_WAITING (parking)at jdk.internal.misc.Unsafe.park(java.base@17.0.21\/Native Method)- parking to wait for  &lt;0x00000000e92bb3c0&gt; (a java.util.concurrent.SynchronousQueue$TransferQueue)at java.util.concurrent.locks.LockSupport.parkNanos(java.base@17.0.21\/Unknown Source)at java.util.concurrent.SynchronousQueue$TransferQueue.transfer(java.base@17.0.21\/Unknown Source)at java.util.concurrent.SynchronousQueue.poll(java.base@17.0.21\/Unknown Source)at com.zaxxer.hikari.util.ConcurrentBag.borrow(ConcurrentBag.java:151)at com.zaxxer.hikari.pool.HikariPool.getConnection(HikariPool.java:164)at com.zaxxer.hikari.pool.HikariPool.getConnection(HikariPool.java:146)at com.zaxxer.hikari.HikariDataSource.getConnection(HikariDataSource.java:128)\u0410 \u043f\u044f\u0442\u044c \u043f\u043e\u0442\u043e\u043a\u043e\u0432-\u0432\u0438\u043d\u043e\u0432\u043d\u0438\u043a\u043e\u0432 (exec-1, exec-7\u2026exec-10) \u0432 \u044d\u0442\u043e\u0442 \u0436\u0435 \u043c\u043e\u043c\u0435\u043d\u0442 \u0434\u0435\u0440\u0436\u0430\u0442 \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f \u0438 \u0432\u0438\u0441\u044f\u0442 \u0432 \u043e\u0436\u0438\u0434\u0430\u043d\u0438\u0438 \u043e\u0442\u0432\u0435\u0442\u0430 \u043e\u0442 \u0432\u043d\u0435\u0448\u043d\u0435\u0433\u043e \u0441\u0435\u0440\u0432\u0438\u0441\u0430 (\u0432 \u0434\u0435\u043c\u043e \u044d\u0442\u043e \u0438\u043c\u0438\u0442\u0438\u0440\u0443\u0435\u0442 SlowExternalClient.notifyExternalSystem:30, \u0432 \u043f\u0440\u043e\u0434\u0435 \u2014 \u0447\u0442\u0435\u043d\u0438\u0435 \u0438\u0437 HTTP-\u0441\u043e\u043a\u0435\u0442\u0430).\u041f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u044c\u043d\u043e \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u043b\u0438 pg_stat_activity:SELECT pid, state, wait_event_type,       now() &#8212; xact_start AS tx_age,       left(query, 50) AS queryFROM pg_stat_activityWHERE datname = &#8216;todo&#8217;ORDER BY xact_start;\u0412\u044b\u0432\u043e\u0434 pg_stat_activity \u0432\u043e \u0432\u0440\u0435\u043c\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f slow-tx: \u0432\u0441\u0435 \u043f\u044f\u0442\u044c \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0439 \u0432\u0438\u0441\u044f\u0442 \u0432 idle in transaction \u0438 \u0436\u0434\u0443\u0442 \u043a\u043b\u0438\u0435\u043d\u0442\u0430\u0422\u0430\u043c \u0432\u0438\u0441\u0435\u043b\u0430 \u043f\u0430\u0447\u043a\u0430 \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0439 \u0432 state = &#8216;idle in transaction&#8217; \u0441 \u0432\u043e\u0437\u0440\u0430\u0441\u0442\u043e\u043c \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u0438 \u0432 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0441\u0435\u043a\u0443\u043d\u0434. \u041f\u0440\u0438\u0447\u0438\u043d\u0430 \u043d\u0430\u0448\u043b\u0430\u0441\u044c \u0431\u044b\u0441\u0442\u0440\u043e: \u0441\u043e\u0441\u0435\u0434\u043d\u0438\u0439 \u0441\u0435\u0440\u0432\u0438\u0441 \u0443\u0432\u0435\u0434\u043e\u043c\u043b\u0435\u043d\u0438\u0439 \u043d\u0430\u0447\u0430\u043b \u0442\u043e\u0440\u043c\u043e\u0437\u0438\u0442\u044c, \u0430 \u0435\u0433\u043e HTTP-\u0432\u044b\u0437\u043e\u0432 \u0443 \u043d\u0430\u0441 \u0441\u0438\u0434\u0435\u043b \u043f\u0440\u044f\u043c\u043e \u0432\u043d\u0443\u0442\u0440\u0438 @Transactional.\u0427\u0442\u043e\u0431\u044b \u043d\u0435 \u043f\u0435\u0440\u0435\u043f\u0438\u0441\u044b\u0432\u0430\u0442\u044c \u043a\u043e\u0434 \u0432 \u0447\u0430\u0441 \u043d\u043e\u0447\u0438, \u043e\u043a\u043e\u043b\u043e 00:40 \u043c\u044b \u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e \u043f\u043e\u0434\u043d\u044f\u043b\u0438 \u043f\u0443\u043b \u0434\u043e 30 \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0439 \u0438 \u043f\u043e\u0441\u0442\u0430\u0432\u0438\u043b\u0438 \u0436\u0451\u0441\u0442\u043a\u0438\u0439 read-timeout \u043d\u0430 \u043a\u043b\u0438\u0435\u043d\u0442\u0435 \u0443\u0432\u0435\u0434\u043e\u043c\u043b\u0435\u043d\u0438\u0439. \u0420\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u0435 \u043f\u0443\u043b\u0430 \u043f\u043e\u043c\u043e\u0433\u043b\u043e \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u043e\u0442\u043e\u043c\u0443, \u0447\u0442\u043e \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f \u0432 idle in transaction \u043f\u043e\u0447\u0442\u0438 \u043d\u0435 \u0433\u0440\u0443\u0437\u044f\u0442 CPU \u0431\u0430\u0437\u044b (\u043a\u043b\u0430\u0441\u0441\u0438\u0447\u0435\u0441\u043a\u0430\u044f \u0444\u043e\u0440\u043c\u0443\u043b\u0430 HikariCP \u0440\u0430\u0441\u0441\u0447\u0438\u0442\u0430\u043d\u0430 \u043d\u0430 \u0430\u043a\u0442\u0438\u0432\u043d\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u044e\u0449\u0438\u0435 \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f). \u041e\u0447\u0435\u0440\u0435\u0434\u044c \u0440\u0430\u0441\u0441\u043e\u0441\u0430\u043b\u0430\u0441\u044c, \u0441\u043f\u0430\u0442\u044c \u0440\u0430\u0437\u043e\u0448\u043b\u0438\u0441\u044c \u0432 \u043d\u0430\u0447\u0430\u043b\u0435 \u0432\u0442\u043e\u0440\u043e\u0433\u043e.\u0427\u0442\u043e \u0441\u043b\u043e\u043c\u0430\u043b\u043e \u043f\u0440\u043e\u0434: \u0432\u043d\u0435\u0448\u043d\u0438\u0439 HTTP \u0432\u043d\u0443\u0442\u0440\u0438 @Transactional\u041a\u043e\u0434, \u0438\u0437-\u0437\u0430 \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u0432\u0441\u0451 \u043b\u0435\u0433\u043b\u043e, \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u043b \u0431\u0435\u0437\u043e\u0431\u0438\u0434\u043d\u043e:@Transactionalpublic Task createAndNotifySlow(String title) {    Task saved = taskRepository.save(new Task(title));   \/\/ ~5 \u043c\u0441    externalClient.notifyExternalSystem(saved);          \/\/ 5 \u0441\u0435\u043a\u0443\u043d\u0434    return saved;}@Transactional \u0434\u0435\u0440\u0436\u0438\u0442 JDBC-\u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0435 \u0434\u043e \u0432\u044b\u0445\u043e\u0434\u0430 \u0438\u0437 \u043c\u0435\u0442\u043e\u0434\u0430. \u0411\u0430\u0437\u0430 \u043e\u0442\u0440\u0430\u0431\u043e\u0442\u0430\u043b\u0430 \u0437\u0430 5 \u043c\u0441, \u043d\u043e \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u0435 5 \u0441\u0435\u043a\u0443\u043d\u0434 \u043a\u043e\u043d\u043d\u0435\u043a\u0442 \u0432\u0438\u0441\u0435\u043b \u0432 idle in transaction, \u043f\u043e\u043a\u0430 \u043c\u044b \u0436\u0434\u0430\u043b\u0438 \u043e\u0442\u0432\u0435\u0442\u0430 \u043f\u043e HTTP.\u0412 \u0434\u0435\u043c\u043e-\u043f\u0440\u043e\u0435\u043a\u0442\u0435 \u043f\u0440\u0438 \u043f\u0443\u043b\u0435 \u043d\u0430 5 \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0439 \u0437\u0430\u043f\u0443\u0441\u043a 7 \u043f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u044c\u043d\u044b\u0445 POST \/api\/crime\/slow-tx \u0441\u0440\u0430\u0437\u0443 \u0437\u0430\u0431\u0438\u0432\u0430\u0435\u0442 \u043f\u0443\u043b (active: 5, idle: 0, waiting: 2): \u043f\u044f\u0442\u044c \u043f\u043e\u0442\u043e\u043a\u043e\u0432 \u0443\u0445\u043e\u0434\u044f\u0442 \u0432\u043e \u0432\u043d\u0435\u0448\u043d\u0438\u0439 \u0432\u044b\u0437\u043e\u0432, \u0430 6-\u0439 \u0438 7-\u0439 \u0432\u0441\u0442\u0430\u044e\u0442 \u0432 \u043e\u0447\u0435\u0440\u0435\u0434\u044c. \u041f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u0432 \u0441\u0442\u0435\u043d\u0434\u0435 \u0437\u0430\u0434\u0435\u0440\u0436\u043a\u0430 \u0432\u043d\u0435\u0448\u043d\u0435\u0433\u043e \u0432\u044b\u0437\u043e\u0432\u0430 (5000 \u043c\u0441) \u0441\u043e\u0432\u043f\u0430\u0434\u0430\u0435\u0442 \u0441 connection-timeout, \u043f\u0440\u0438 \u0437\u0430\u043f\u0443\u0441\u043a\u0435 \u0447\u0435\u0440\u0435\u0437 for &#8230; &amp; 6-\u0439 \u0438 7-\u0439 \u043e\u0431\u044b\u0447\u043d\u043e \u0443\u0441\u043f\u0435\u0432\u0430\u044e\u0442 \u0441\u0445\u0432\u0430\u0442\u0438\u0442\u044c \u043e\u0441\u0432\u043e\u0431\u043e\u0434\u0438\u0432\u0448\u0438\u0439\u0441\u044f \u043a\u043e\u043d\u043d\u0435\u043a\u0442 (\u043e\u0442\u0432\u0435\u0447\u0430\u044f \u0437\u0430 ~10 \u0441\u0435\u043a\u0443\u043d\u0434) \u0442\u043e\u043b\u044c\u043a\u043e \u0437\u0430 \u0441\u0447\u0451\u0442 \u0442\u043e\u0433\u043e, \u0447\u0442\u043e \u043f\u0440\u0438\u0448\u043b\u0438 \u043d\u0430 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043c\u0438\u043b\u043b\u0438\u0441\u0435\u043a\u0443\u043d\u0434 \u043f\u043e\u0437\u0436\u0435 \u043f\u0435\u0440\u0432\u044b\u0445 \u043f\u044f\u0442\u0438. \u041f\u0440\u0438 \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e\u043c \u0437\u0430\u043f\u0443\u0441\u043a\u0435 (\u0447\u0435\u0440\u0435\u0437 hey \u0438\u043b\u0438 xargs -P), \u0447\u0443\u0442\u044c \u0431\u043e\u043b\u044c\u0448\u0435\u0439 \u0437\u0430\u0434\u0435\u0440\u0436\u043a\u0435 \u0438\u043b\u0438 \u0431\u043e\u043b\u044c\u0448\u0435\u043c \u0447\u0438\u0441\u043b\u0435 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 (\u043d\u0430 \u0441\u0442\u0435\u043d\u0434\u0435 \u0445\u0432\u0430\u0442\u0430\u0435\u0442 15 \u0448\u0442\u0443\u043a) \u0432 \u043e\u0442\u0432\u0435\u0442 \u0441\u0440\u0430\u0437\u0443 \u043b\u0435\u0442\u044f\u0442 \u043f\u044f\u0442\u0438\u0441\u043e\u0442\u044b\u0435.\u0413\u0440\u0430\u043d\u0438\u0446\u0443 \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u0438 \u043d\u0443\u0436\u043d\u043e \u0441\u0436\u0438\u043c\u0430\u0442\u044c \u0441\u0442\u0440\u043e\u0433\u043e \u0434\u043e \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u0411\u0414, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 \u0447\u0435\u0440\u0435\u0437 TransactionTemplate:public Task createAndNotifyFixed(String title) {    Task saved = transactionTemplate.execute(status -&gt;            taskRepository.save(new Task(title)));    externalClient.notifyExternalSystem(saved);    return saved;}\u0410\u043b\u044c\u0442\u0435\u0440\u043d\u0430\u0442\u0438\u0432\u0430 \u2014 \u0432\u044b\u043d\u043e\u0441\u0438\u0442\u044c \u0432\u043d\u0435\u0448\u043d\u0438\u0435 \u0432\u044b\u0437\u043e\u0432\u044b \u0432 @TransactionalEventListener(AFTER_COMMIT) \u0432 \u043f\u0430\u0440\u0435 \u0441 @Async. \u0411\u0435\u0437 @Async \u043b\u0438\u0441\u0442\u0435\u043d\u0435\u0440 \u043e\u0442\u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0432 \u0442\u043e\u043c \u0436\u0435 \u043f\u043e\u0442\u043e\u043a\u0435 \u0440\u0430\u043d\u044c\u0448\u0435, \u0447\u0435\u043c \u043c\u0435\u043d\u0435\u0434\u0436\u0435\u0440 \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u0439 \u0432\u0435\u0440\u043d\u0451\u0442 \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0435 \u0432 \u043f\u0443\u043b, \u0438 \u0442\u0435 \u0436\u0435 \u043f\u044f\u0442\u044c \u0441\u0435\u043a\u0443\u043d\u0434 HTTP \u0441\u043d\u043e\u0432\u0430 \u0431\u0443\u0434\u0443\u0442 \u043e\u043f\u043b\u0430\u0447\u0435\u043d\u044b \u043a\u043e\u043d\u043d\u0435\u043a\u0442\u043e\u043c. \u041f\u0440\u0430\u0432\u0434\u0430, \u043e\u0431\u0430 \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u0430 \u043f\u043e\u0442\u0435\u0440\u044f\u044e\u0442 \u0443\u0432\u0435\u0434\u043e\u043c\u043b\u0435\u043d\u0438\u0435, \u0435\u0441\u043b\u0438 \u043f\u043e\u0434 \u0443\u043f\u0430\u0434\u0451\u0442 \u043c\u0435\u0436\u0434\u0443 \u043a\u043e\u043c\u043c\u0438\u0442\u043e\u043c \u0438 HTTP-\u0432\u044b\u0437\u043e\u0432\u043e\u043c \u2014 \u0435\u0441\u043b\u0438 \u043d\u0443\u0436\u043d\u0430 \u0433\u0430\u0440\u0430\u043d\u0442\u0438\u044f \u0434\u043e\u0441\u0442\u0430\u0432\u043a\u0438, \u0437\u0434\u0435\u0441\u044c \u0443\u0436\u0435 \u043d\u0443\u0436\u0435\u043d \u043f\u0430\u0442\u0442\u0435\u0440\u043d Transactional Outbox.\u041d\u0430 \u043f\u0438\u0448\u0443\u0449\u0438\u0435 \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u0438 \u043f\u043e\u043b\u0435\u0437\u043d\u043e \u0432\u0435\u0448\u0430\u0442\u044c @Transactional(timeout = 5). \u041d\u043e \u0432\u0430\u0436\u043d\u043e \u043f\u043e\u043c\u043d\u0438\u0442\u044c: \u043d\u0438 Spring, \u043d\u0438 Hibernate \u043d\u0435 \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u044e\u0442 \u044d\u0442\u043e\u0442 \u0434\u0435\u0434\u043b\u0430\u0439\u043d \u043d\u0430 \u0441\u0430\u043c\u043e\u043c commit(). \u041e\u0441\u0442\u0430\u0432\u0448\u0435\u0435\u0441\u044f \u0432\u0440\u0435\u043c\u044f \u0441\u0432\u0435\u0440\u044f\u0435\u0442\u0441\u044f \u043f\u0440\u0438 \u043f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u043a\u0435 \u043e\u0447\u0435\u0440\u0435\u0434\u043d\u043e\u0433\u043e SQL-\u0437\u0430\u043f\u0440\u043e\u0441\u0430 (\u0432 \u0442\u043e\u043c \u0447\u0438\u0441\u043b\u0435 \u043f\u0440\u0438 flush \u043f\u0435\u0440\u0435\u0434 \u043a\u043e\u043c\u043c\u0438\u0442\u043e\u043c). \u041f\u043e\u0442\u043e\u043a, \u0437\u0430\u0432\u0438\u0441\u0448\u0438\u0439 \u043d\u0430 \u0447\u0442\u0435\u043d\u0438\u0438 \u0438\u0437 HTTP-\u0441\u043e\u043a\u0435\u0442\u0430 \u043f\u043e\u0441\u043b\u0435 \u0443\u0436\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u043d\u043e\u0433\u043e INSERT, \u0442\u0430\u043a\u043e\u0439 \u0442\u0430\u0439\u043c\u0430\u0443\u0442 \u043d\u0435 \u043f\u0440\u0435\u0440\u0432\u0451\u0442 \u2014 \u043e\u0442 \u043c\u0435\u0434\u043b\u0435\u043d\u043d\u044b\u0445 \u0441\u043e\u0441\u0435\u0434\u0435\u0439 \u0437\u0430\u0449\u0438\u0449\u0430\u044e\u0442 connect\/read \u0442\u0430\u0439\u043c\u0430\u0443\u0442\u044b \u0441\u0430\u043c\u043e\u0433\u043e HTTP-\u043a\u043b\u0438\u0435\u043d\u0442\u0430.\u041f\u043e\u043d\u0435\u0434\u0435\u043b\u044c\u043d\u0438\u043a, 10:15: \u043f\u043e\u0447\u0435\u043c\u0443 TransactionTemplate \u043d\u0435 \u043e\u0442\u0434\u0430\u043b \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0435\u0412 \u043f\u044f\u0442\u043d\u0438\u0446\u0443 \u0434\u043d\u0451\u043c \u043c\u044b \u0432\u044b\u043a\u0430\u0442\u0438\u043b\u0438 \u0444\u0438\u043a\u0441 \u0441 TransactionTemplate \u0438 \u0432\u0435\u0440\u043d\u0443\u043b\u0438 \u043f\u0443\u043b \u043e\u0431\u0440\u0430\u0442\u043d\u043e \u043a 15 \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f\u043c. \u0412\u044b\u0445\u043e\u0434\u043d\u044b\u0435 \u043f\u0440\u043e\u0448\u043b\u0438 \u0442\u0438\u0445\u043e.\u0412 \u043f\u043e\u043d\u0435\u0434\u0435\u043b\u044c\u043d\u0438\u043a \u0432 10:15, \u043a\u043e\u0433\u0434\u0430 \u043f\u0440\u0438\u0448\u0451\u043b \u0443\u0442\u0440\u0435\u043d\u043d\u0438\u0439 \u0442\u0440\u0430\u0444\u0438\u043a, \u0441\u0435\u0440\u0432\u0438\u0441 \u0443\u0432\u0435\u0434\u043e\u043c\u043b\u0435\u043d\u0438\u0439 \u0441\u043d\u043e\u0432\u0430 \u043f\u043e\u0434\u0442\u043e\u0440\u043c\u043e\u0437\u0438\u043b \u043d\u0430 \u043f\u0430\u0440\u0443 \u0441\u0435\u043a\u0443\u043d\u0434 \u2014 \u0438 \u043d\u0430 \u0433\u0440\u0430\u0444\u0438\u043a\u0435 hikaricp_connections_active \u0442\u0443\u0442 \u0436\u0435 \u043f\u043e\u0434\u0441\u043a\u043e\u0447\u0438\u043b \u043a \u043f\u043e\u0442\u043e\u043b\u043a\u0443, \u0430 pending \u043f\u043e\u043f\u043e\u043b\u0437 \u0432\u0432\u0435\u0440\u0445.\u0421\u043d\u043e\u0432\u0430 \u043e\u0442\u043a\u0440\u044b\u043b\u0438 pg_stat_activity \u2014 \u0438 \u0443\u0432\u0438\u0434\u0435\u043b\u0438 \u0441\u0442\u0440\u0430\u043d\u043d\u0443\u044e \u043a\u0430\u0440\u0442\u0438\u043d\u0443. \u0412 \u0447\u0435\u0442\u0432\u0435\u0440\u0433 \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f \u0432\u0438\u0441\u0435\u043b\u0438 \u0432 idle in transaction, \u0430 \u0442\u0435\u043f\u0435\u0440\u044c \u043e\u043d\u0438 \u0431\u044b\u043b\u0438 \u043f\u0440\u043e\u0441\u0442\u043e \u0432 idle. \u0422\u043e \u0435\u0441\u0442\u044c \u0441 \u0442\u043e\u0447\u043a\u0438 \u0437\u0440\u0435\u043d\u0438\u044f PostgreSQL \u043d\u0438\u043a\u0430\u043a\u043e\u0439 \u043e\u0442\u043a\u0440\u044b\u0442\u043e\u0439 \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u0438 \u043d\u0435\u0442, \u043d\u043e HikariCP \u043f\u0440\u0438 \u044d\u0442\u043e\u043c \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0430\u0435\u0442 \u0441\u0447\u0438\u0442\u0430\u0442\u044c \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f active \u0438 \u043d\u0438\u043a\u043e\u043c\u0443 \u0438\u0445 \u043d\u0435 \u043e\u0442\u0434\u0430\u0451\u0442. \u041a\u0441\u0442\u0430\u0442\u0438, \u043f\u043e\u043f\u0443\u043b\u044f\u0440\u043d\u0430\u044f \u0441\u0442\u0440\u0430\u0445\u043e\u0432\u043a\u0430 \u043d\u0430 \u0441\u0442\u043e\u0440\u043e\u043d\u0435 \u0431\u0430\u0437\u044b \u2014 idle_in_transaction_session_timeout \u2014 \u0447\u0435\u0442\u0432\u0435\u0440\u0433\u043e\u0432\u044b\u0439 \u0441\u0446\u0435\u043d\u0430\u0440\u0438\u0439 \u0431\u044b \u043f\u0440\u0438\u0431\u0438\u043b\u0430, \u0430 \u0432\u043e\u0442 \u043e\u0442 \u043f\u043e\u043d\u0435\u0434\u0435\u043b\u044c\u043d\u0438\u0447\u043d\u043e\u0433\u043e \u043d\u0435 \u0441\u043f\u0430\u0441\u043b\u0430 \u0431\u044b \u043d\u0438\u043a\u0430\u043a.\u00ab\u0421\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0435 \u0437\u0430\u043d\u044f\u0442\u043e, \u0430 \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u0438 \u043d\u0435\u0442\u00bb \u2014 \u043a\u043b\u0430\u0441\u0441\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u043f\u043e\u0447\u0435\u0440\u043a Open Session In View. \u041a\u043e\u0433\u0434\u0430 \u0443\u0432\u0438\u0434\u0435\u043b\u0438 \u0432 pg_stat_activity \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f \u0432 \u0441\u0442\u0430\u0442\u0443\u0441\u0435 idle \u043f\u0440\u0438 \u0437\u0430\u043d\u044f\u0442\u043e\u043c \u043f\u0443\u043b\u0435, \u043f\u0430\u0437\u043b \u0441\u043b\u043e\u0436\u0438\u043b\u0441\u044f. \u041e\u0442\u043a\u0440\u044b\u043b\u0438 \u043b\u043e\u0433 \u0441\u0442\u0430\u0440\u0442\u0430 \u2014 \u0438 \u0432\u043e\u0442 \u043e\u043d\u0430, \u0441\u0442\u0440\u043e\u0447\u043a\u0430, \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u043a\u0430\u0436\u0434\u044b\u0439 Spring-\u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a \u0432\u0438\u0434\u0435\u043b \u0442\u044b\u0441\u044f\u0447\u0443 \u0440\u0430\u0437, \u043d\u0438 \u0440\u0430\u0437\u0443 \u043d\u0435 \u0434\u043e\u0447\u0438\u0442\u0430\u043b \u0434\u043e \u043a\u043e\u043d\u0446\u0430 \u0438 \u0432\u0441\u0435\u0433\u0434\u0430 \u043e\u0442\u043a\u043b\u0430\u0434\u044b\u0432\u0430\u043b \u043d\u0430 \u00ab\u043f\u043e\u0442\u043e\u043c \u043a\u0430\u043a-\u043d\u0438\u0431\u0443\u0434\u044c \u0440\u0430\u0437\u0431\u0435\u0440\u0443\u0441\u044c\u00bb:2026-11-19T00:09:30.705Z  WARN 1 &#8212; [todo-transactions-demo] [           main] JpaBaseConfiguration$JpaWebConfiguration : spring.jpa.open-in-view is enabled by default. Therefore, database queries may be performed during view rendering. Explicitly configure spring.jpa.open-in-view to disable this warning\u0412 Spring Boot OSIV \u0432\u043a\u043b\u044e\u0447\u0451\u043d \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e: EntityManager \u043e\u0442\u043a\u0440\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0432 \u043d\u0430\u0447\u0430\u043b\u0435 HTTP-\u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u0438 \u0437\u0430\u043a\u0440\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u043e\u0441\u043b\u0435 \u0440\u0435\u043d\u0434\u0435\u0440\u0438\u043d\u0433\u0430 \u043e\u0442\u0432\u0435\u0442\u0430. \u041f\u0440\u0438 \u044d\u0442\u043e\u043c HibernateJpaVendorAdapter \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e \u0441\u0442\u0430\u0432\u0438\u0442 Hibernate \u0440\u0435\u0436\u0438\u043c DELAYED_ACQUISITION_AND_HOLD \u2014 JDBC-\u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0435 \u0431\u0435\u0440\u0451\u0442\u0441\u044f \u0438\u0437 \u043f\u0443\u043b\u0430 \u0443\u0436\u0435 \u043d\u0430 \u0441\u0442\u0430\u0440\u0442\u0435 \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u0438 (\u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e Hibernate \u0432\u044b\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 setAutoCommit(false), \u0435\u0441\u043b\u0438 \u043d\u0435 \u0432\u043a\u043b\u044e\u0447\u0451\u043d provider_disables_autocommit) \u0438 \u0434\u0435\u0440\u0436\u0438\u0442\u0441\u044f \u0434\u043e \u0437\u0430\u043a\u0440\u044b\u0442\u0438\u044f Session, \u0430 \u043d\u0435 \u0434\u043e \u043a\u043e\u043c\u043c\u0438\u0442\u0430 \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u0438.\u041f\u043e\u043b\u0443\u0447\u0438\u043b\u043e\u0441\u044c, \u0447\u0442\u043e \u043d\u0430\u0448 TransactionTemplate \u043a\u043e\u043c\u043c\u0438\u0442\u0438\u043b \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u044e \u0437\u0430 5 \u043c\u0441, \u043d\u043e \u0438\u0437-\u0437\u0430 \u043e\u0442\u043a\u0440\u044b\u0442\u043e\u0433\u043e EntityManager \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0435 \u043e\u0431\u0440\u0430\u0442\u043d\u043e \u0432&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-504415","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/504415","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=504415"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/504415\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=504415"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=504415"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=504415"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}