{"id":378078,"date":"2024-06-05T09:00:47","date_gmt":"2024-06-05T09:00:47","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=378078"},"modified":"-0001-11-30T00:00:00","modified_gmt":"2024-06-05T09:00:47","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=378078","title":{"rendered":"<span>\u041b\u043e\u0432\u0443\u0448\u043a\u0438 volatile, DCL \u0438 \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u0438\u0437\u0430\u0446\u0438\u0438 \u0432 Java<\/span>"},"content":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u0410 \u0447\u0442\u043e \u0435\u0441\u043b\u0438 \u043e\u043a\u0430\u0436\u0435\u0442\u0441\u044f, \u0447\u0442\u043e \u043f\u0440\u043e\u0441\u0442\u044b\u0435 \u0437\u043d\u0430\u043d\u0438\u044f \u043d\u0430 \u0441\u0430\u043c\u043e\u043c \u0434\u0435\u043b\u0435 \u0431\u043e\u043b\u0435\u0435 \u043d\u044e\u0430\u043d\u0441\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0435, \u0430 \u0441\u0442\u0430\u0440\u044b\u0435 \u0437\u043d\u0430\u043a\u043e\u043c\u044b\u0435, \u0442\u0430\u043a\u0438\u0435 \u043a\u0430\u043a Double-checked locking, \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u043d\u0435\u043e\u0434\u043d\u043e\u0437\u043d\u0430\u0447\u043d\u044b\u043c\u0438? \u0418\u043c\u0435\u043d\u043d\u043e \u043d\u0430 \u0442\u0430\u043a\u0438\u0435 \u043c\u044b\u0441\u043b\u0438 \u043d\u0430\u0442\u0430\u043b\u043a\u0438\u0432\u0430\u0435\u0442 \u0438\u0437\u0443\u0447\u0435\u043d\u0438\u0435 \u043a\u043e\u0434\u0430 \u0440\u0435\u0430\u043b\u044c\u043d\u044b\u0445 \u043f\u0440\u043e\u0435\u043a\u0442\u043e\u0432. \u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u044d\u0442\u043e\u0433\u043e \u0438\u0441\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u043d\u0438\u044f \u043c\u044b \u0438 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0432 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435.<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/b16\/434\/102\/b164341027631cb09a822062ea4f440e.png\" width=\"1600\" height=\"902\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/b16\/434\/102\/b164341027631cb09a822062ea4f440e.png\"\/><\/figure>\n<h3>\u041f\u0440\u0435\u0434\u0438\u0441\u043b\u043e\u0432\u0438\u0435<\/h3>\n<p>\u041d\u0435 \u0442\u0430\u043a \u0434\u0430\u0432\u043d\u043e \u044f \u2014 \u0432 \u043f\u043e\u0440\u044f\u0434\u043a\u0435 \u043e\u0431\u044b\u0447\u043d\u043e\u0439 \u0434\u0435\u044f\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u043f\u043e \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0435 \u043e\u0442\u043a\u0440\u044b\u0442\u044b\u0445 \u043f\u0440\u043e\u0435\u043a\u0442\u043e\u0432 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e PVS-Studio \u2014 \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u043b \u0442\u043e\u043b\u044c\u043a\u043e \u0432\u044b\u0448\u0435\u0434\u0448\u0443\u044e \u0442\u043e\u0433\u0434\u0430 24-\u044e \u0432\u0435\u0440\u0441\u0438\u044e \u0438\u0437\u0432\u0435\u0441\u0442\u043d\u043e\u0433\u043e \u043f\u0440\u043e\u0435\u043a\u0442\u0430 <a href=\"https:\/\/github.com\/dbeaver\/dbeaver\">DBeaver<\/a>. \u041d\u0430\u0434\u043e \u043f\u0440\u0438\u0437\u043d\u0430\u0442\u044c, \u043c\u0435\u043d\u044f \u043f\u0440\u0438\u044f\u0442\u043d\u043e \u0443\u0434\u0438\u0432\u0438\u043b\u043e \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u043e \u0435\u0433\u043e \u043a\u043e\u0434\u0430 \u2014 \u043d\u0435\u0434\u0430\u0440\u043e\u043c \u043e\u043d\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u044b \u0441\u0442\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0433\u043e \u0430\u043d\u0430\u043b\u0438\u0437\u0430. \u041d\u043e \u044f \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0438\u043b \u0438\u0441\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u043d\u0438\u0435 \u0438 \u043d\u0430\u0448\u0451\u043b \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043f\u043e\u0434\u043e\u0437\u0440\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u043c\u0435\u0441\u0442, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u0435\u043d\u044f \u0437\u0430\u0446\u0435\u043f\u0438\u043b\u0438. \u0417\u0430\u0446\u0435\u043f\u0438\u043b\u0438 \u043d\u0430\u0441\u0442\u043e\u043b\u044c\u043a\u043e, \u0447\u0442\u043e \u043a\u0430\u0436\u0434\u043e\u043c\u0443 \u044f \u0440\u0435\u0448\u0438\u043b \u043f\u043e\u0441\u0432\u044f\u0442\u0438\u0442\u044c \u043f\u043e \u0441\u0442\u0430\u0442\u044c\u0435, \u0442\u0430\u043a \u0447\u0442\u043e \u043f\u0440\u0438\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e \u0432 \u043f\u0435\u0440\u0432\u043e\u0439 \u0447\u0430\u0441\u0442\u0438 \u0446\u0438\u043a\u043b\u0430.<\/p>\n<h3>\u041f\u043e\u0442\u043e\u043a\u043e\u043d\u0435\u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e\u0435 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435<\/h3>\n<h4>\u041e \u0447\u0451\u043c \u0440\u0435\u0447\u044c?<\/h4>\n<p>\u041f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u044c\u043d\u043e\u0435 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0442\u0430\u0438\u0442 \u0432 \u0441\u0435\u0431\u0435 \u043a\u0443\u0447\u0443 \u0433\u0440\u0430\u0431\u043b\u0435\u0439. \u0418, \u0440\u0430\u0437\u0443\u043c\u0435\u0435\u0442\u0441\u044f, \u043d\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u0432 Java \u2014 \u0442\u043e\u0442 \u0436\u0435 \u0437\u043b\u043e\u0439 (\u0438\u043b\u0438 \u0434\u043e\u0431\u0440\u044b\u0439 \ud83d\ude42 ) \u0431\u0440\u0430\u0442-\u0431\u043b\u0438\u0437\u043d\u0435\u0446 C# \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043b\u0435\u0433\u043a\u043e \u043e\u0441\u0442\u0443\u043f\u0438\u0442\u044c\u0441\u044f \u043f\u0440\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0438 <a href=\"https:\/\/pvs-studio.ru\/ru\/docs\/warnings\/v3083\/\">\u0441\u043e\u0431\u044b\u0442\u0438\u0439<\/a> \u0432 \u043f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u044c\u043d\u044b\u0445 \u0441\u0446\u0435\u043d\u0430\u0440\u0438\u044f\u0445. \u0418\u0437\u0432\u0435\u0441\u0442\u043d\u043e, \u0447\u0442\u043e \u0437\u0430\u0447\u0430\u0441\u0442\u0443\u044e \u0438\u043c\u0435\u043d\u043d\u043e \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u044b\u0435 \u0438 \u043c\u043d\u043e\u0433\u043e\u043f\u043e\u0442\u043e\u0447\u043d\u044b\u0435 \u043e\u0448\u0438\u0431\u043a\u0438 \u0441\u043b\u043e\u0436\u043d\u0435\u0435 \u0432\u0441\u0435\u0433\u043e \u043e\u0442\u043b\u0430\u0432\u043b\u0438\u0432\u0430\u0442\u044c.<\/p>\n<p>\u0414\u0430\u043b\u0435\u0435 \u043c\u044b \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043d\u0430 \u0442\u0440\u0438 \u0442\u0438\u043f\u0430 \u0442\u0430\u043a\u0438\u0445 \u043e\u0448\u0438\u0431\u043e\u043a. \u041f\u0435\u0440\u0432\u043e\u0439 \u0438\u0437 \u043d\u0438\u0445 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043d\u0435\u0430\u0442\u043e\u043c\u0430\u0440\u043d\u043e\u0435 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0435 volatile \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445.<\/p>\n<h4>\u0415\u0449\u0451 \u0440\u0430\u0437, \u0447\u0442\u043e \u0442\u0430\u043a\u043e\u0435 volatile?<\/h4>\n<p>\u0418\u0437 <a href=\"https:\/\/docs.oracle.com\/javase\/tutorial\/essential\/concurrency\/atomic.html\">\u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438<\/a> \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0443\u0437\u043d\u0430\u0442\u044c, \u0447\u0442\u043e \u043a\u043b\u044e\u0447\u0435\u0432\u043e\u0435 \u0441\u043b\u043e\u0432\u043e <em>volatile<\/em>:<\/p>\n<ol>\n<li>\n<p>\u041f\u0440\u0435\u0434\u043e\u0442\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u043a\u044d\u0448\u0430 \u0434\u043b\u044f \u0440\u0430\u0437\u043d\u044b\u0445 \u043f\u043e\u0442\u043e\u043a\u043e\u0432, \u0442\u0435\u043c \u0441\u0430\u043c\u044b\u043c \u0433\u0430\u0440\u0430\u043d\u0442\u0438\u0440\u0443\u044f, \u0447\u0442\u043e \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u0432 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439 \u0431\u0443\u0434\u0443\u0442 \u0441\u0440\u0430\u0437\u0443 \u0432\u0438\u0434\u043d\u044b \u0432\u0441\u0435\u043c \u043f\u043e\u0442\u043e\u043a\u0430\u043c;<\/p>\n<\/li>\n<li>\n<p>\u0423\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u0442 happens-before \u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u0435 \u043c\u0435\u0436\u0434\u0443 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439 \u0438 \u0447\u0442\u0435\u043d\u0438\u044f\u043c\u0438\/\u0437\u0430\u043f\u0438\u0441\u044c\u044e \u0440\u044f\u0434\u043e\u043c, \u0442\u0435\u043c \u0441\u0430\u043c\u044b\u043c \u0437\u0430\u043f\u0440\u0435\u0449\u0430\u044f \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u044c \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u0438, \u043e\u0441\u043d\u043e\u0432\u0430\u043d\u043d\u044b\u0435 \u043d\u0430 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0438 \u043f\u043e\u0440\u044f\u0434\u043a\u0430 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0439.<\/p>\n<\/li>\n<\/ol>\n<p>\u041f\u0440\u043e\u0434\u0435\u043c\u043e\u043d\u0441\u0442\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0440\u0430\u0431\u043e\u0442\u0443 \u044d\u0442\u043e\u0433\u043e \u043a\u043b\u044e\u0447\u0435\u0432\u043e\u0433\u043e \u0441\u043b\u043e\u0432\u0430 \u043c\u043e\u0436\u0435\u0442 \u043f\u0440\u043e\u0437\u0430\u0438\u0447\u043d\u044b\u0439 \u043f\u0440\u0438\u043c\u0435\u0440 \u0441 \u043f\u043e\u0442\u043e\u043a\u043e\u043c, \u043e\u0436\u0438\u0434\u0430\u044e\u0449\u0438\u043c \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439:<\/p>\n<pre><code class=\"java\">private static volatile String str; public static void main() throws InterruptedException {     new Thread(() -> {         while (str == null) { }         System.out.println(str);     }).start();      Thread.sleep(1);      str = \"Hello World!\"; }<\/code><\/pre>\n<p>\u0415\u0441\u043b\u0438 \u0443\u0431\u0440\u0430\u0442\u044c <em>volatile<\/em>, \u0442\u043e \u0446\u0438\u043a\u043b \u0431\u0443\u0434\u0435\u0442 \u0431\u0435\u0441\u043a\u043e\u043d\u0435\u0447\u043d\u044b\u043c. \u041f\u043e \u043a\u0440\u0430\u0439\u043d\u0435\u0439 \u043c\u0435\u0440\u0435, \u0432 \u043c\u043e\u0451\u043c \u0441\u043b\u0443\u0447\u0430\u0435. \u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u043c\u043e\u0436\u0435\u0442 \u0441\u0438\u043b\u044c\u043d\u043e \u0437\u0430\u0432\u0438\u0441\u0435\u0442\u044c \u043e\u0442 JVM \u0438 \u0436\u0435\u043b\u0435\u0437\u0430.<\/p>\n<details class=\"spoiler\">\n<summary>\u0410 \u043a\u0430\u043a \u0443\u0432\u0438\u0434\u0435\u0442\u044c \u0440\u0430\u0431\u043e\u0442\u0443 happens-before \u0432 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0438?<\/summary>\n<div class=\"spoiler__content\">\n<p>\u0415\u0441\u043b\u0438 \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u043c\u043e\u0434\u0438\u0444\u0438\u0446\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043f\u0440\u0438\u043c\u0435\u0440, \u0434\u043e\u0431\u0430\u0432\u0438\u0432 \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u0443\u044e \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e, \u0442\u043e \u0441\u0442\u0430\u043d\u0435\u0442 \u044f\u0441\u0435\u043d \u0438 \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c \u0440\u0430\u0431\u043e\u0442\u044b happens-before:<\/p>\n<pre><code class=\"java\">private static String str; private static volatile boolean flag = false; public static void main() throws InterruptedException {     new Thread(() -> {         while (!flag) { }         System.out.println(str);     }).start();      Thread.sleep(1);      str = \"Hello World!\";     flag = true; }<\/code><\/pre>\n<p>\u0415\u0441\u043b\u0438 \u0431\u044b \u0443 \u043d\u0430\u0441 \u0431\u044b\u043b\u0430 <strong>\u0442\u043e\u043b\u044c\u043a\u043e<\/strong> \u0433\u0430\u0440\u0430\u043d\u0442\u0438\u044f \u0432\u0438\u0434\u0438\u043c\u043e\u0441\u0442\u0438, \u0442\u043e \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440 \u0438\u043b\u0438 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0440 \u043c\u043e\u0433\u043b\u0438 \u0431\u044b \u043f\u043e\u043c\u0435\u043d\u044f\u0442\u044c \u043f\u043e\u0440\u044f\u0434\u043e\u043a \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0439 \u043f\u0440\u0438\u0441\u0432\u0430\u0438\u0432\u0430\u043d\u0438\u044f \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u043c <em>str<\/em> \u0438 <em>flag<\/em>. \u0418 \u0442\u043e\u0433\u0434\u0430 \u0431\u044b\u043b\u0430 \u0431\u044b \u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e\u0441\u0442\u044c \u043f\u043e\u043f\u0430\u0441\u0442\u044c \u0432 <em>System.out.println(str)<\/em> \u0432 \u043c\u043e\u043c\u0435\u043d\u0442\u0435, \u043a\u043e\u0433\u0434\u0430 <em>str<\/em> \u0435\u0449\u0451 \u0440\u0430\u0432\u043d\u044f\u0435\u0442\u0441\u044f <em>null<\/em>.<\/p>\n<p>\u0422\u0435\u043c \u043d\u0435 \u043c\u0435\u043d\u0435\u0435 \u043f\u0440\u0438\u043d\u0446\u0438\u043f happens-before \u0433\u0430\u0440\u0430\u043d\u0442\u0438\u0440\u0443\u0435\u0442, \u0447\u0442\u043e \u0437\u0430\u043f\u0438\u0441\u044c, \u043d\u0430\u0445\u043e\u0434\u044f\u0449\u0430\u044f\u0441\u044f \u043f\u0435\u0440\u0435\u0434 \u0437\u0430\u043f\u0438\u0441\u044c\u044e \u0432 volatile \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e, \u043e\u0441\u0442\u0430\u043d\u0435\u0442\u0441\u044f \u0442\u0430\u043c \u0436\u0435.<\/p>\n<\/div>\n<\/details>\n<h4>\u0413\u043e\u043d\u043a\u0430<\/h4>\n<p>\u041d\u0435\u0441\u043c\u043e\u0442\u0440\u044f \u043d\u0430 \u0442\u043e, \u0447\u0442\u043e \u0443 \u043d\u0430\u0441 \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0435\u043d\u0430 \u0432\u0438\u0434\u0438\u043c\u043e\u0441\u0442\u044c \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439, \u044d\u0442\u043e\u0433\u043e, \u043a\u043e\u043d\u0435\u0447\u043d\u043e, \u043d\u0435 \u0445\u0432\u0430\u0442\u0438\u0442 \u0434\u043b\u044f \u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u043e\u0439 \u0440\u0430\u0431\u043e\u0442\u044b \u0432 \u043f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u044c\u043d\u044b\u0445 \u043f\u043e\u0442\u043e\u043a\u0430\u0445:<\/p>\n<pre><code class=\"java\">private static volatile int counter = 0; private static void increment() {     Thread.sleep(1);     counter++; } public static void main() {     var threads = Stream.generate(() -> new Thread(Main::increment))                         .limit(100)                         .toList();      threads.forEach(Thread::start);     while (threads.stream().anyMatch(Thread::isAlive)) {         Thread.yield();     }      System.out.println(counter); }<\/code><\/pre>\n<p>\u0422\u0430\u043a\u043e\u0439 \u043a\u043e\u0434 \u0431\u0443\u0434\u0435\u0442 \u0441\u0442\u0430\u0431\u0438\u043b\u044c\u043d\u043e \u0432\u044b\u0432\u043e\u0434\u0438\u0442\u044c \u0447\u0438\u0441\u043b\u043e \u043c\u0435\u043d\u044c\u0448\u0435\u0435, \u0447\u0435\u043c 100. \u041d\u0435\u0443\u0434\u0438\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u043e, \u0432\u0435\u0434\u044c \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u044f \u0438\u043d\u043a\u0440\u0435\u043c\u0435\u043d\u0442\u0430 \u043d\u0435 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0430\u0442\u043e\u043c\u0430\u0440\u043d\u043e\u0439, \u0438 \u043e\u0434\u0438\u043d \u043f\u043e\u0442\u043e\u043a \u043c\u043e\u0436\u0435\u0442 \u0432\u043b\u0435\u0437\u0442\u044c \u043f\u043e\u043f\u0435\u0440\u0451\u043a \u0434\u0440\u0443\u0433\u043e\u0433\u043e. \u042d\u0442\u043e \u043c\u043e\u0436\u0435\u0442 \u043f\u0440\u043e\u0438\u0437\u043e\u0439\u0442\u0438 \u043a\u0430\u043a \u0440\u0430\u0437 \u043c\u0435\u0436\u0434\u0443 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u044f\u043c\u0438 \u0432\u0437\u044f\u0442\u0438\u044f \u0441\u0442\u0430\u0440\u043e\u0433\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f <em>counter<\/em> \u0438 \u0443\u0432\u0435\u043b\u0438\u0447\u0435\u043d\u0438\u044f \u0435\u0433\u043e \u043d\u0430 1. \u0418\u0441\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u0439 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0434\u0432\u0430, \u043e\u0434\u043d\u043e \u043f\u0440\u043e\u0449\u0435 \u0434\u0440\u0443\u0433\u043e\u0433\u043e:<\/p>\n<details class=\"spoiler\">\n<summary>Atomic \u0442\u0438\u043f\u044b<\/summary>\n<div class=\"spoiler__content\">\n<p>\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u044b\u0435 \u0442\u0438\u043f\u044b \u0434\u0430\u043d\u043d\u044b\u0445, \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u044e\u0449\u0438\u0435 \u0433\u043e\u0442\u043e\u0432\u044b\u0439 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0438\u0437 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u0445 \u043f\u043e\u0442\u043e\u043a\u043e\u0432. \u0412 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u2014 <em>AtomicInteger<\/em>.<\/p>\n<pre><code class=\"java\">private static final AtomicInteger counter = new AtomicInteger(0); private static void increment() {     Thread.sleep(1);     counter.incrementAndGet(); }<\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<details class=\"spoiler\">\n<summary>\u0421\u0438\u043d\u0445\u0440\u043e\u043d\u0438\u0437\u0430\u0446\u0438\u044f<\/summary>\n<div class=\"spoiler__content\">\n<p>\u041f\u0440\u043e\u0441\u0442\u043e \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u043a\u043b\u044e\u0447\u0435\u0432\u043e\u0435 \u0441\u043b\u043e\u0432\u043e <em>synchronized<\/em> (\u043b\u0438\u0431\u043e <em>synchronized<\/em> \u0431\u043b\u043e\u043a). \u042d\u0442\u043e \u0433\u0430\u0440\u0430\u043d\u0442\u0438\u0440\u0443\u0435\u0442, \u0447\u0442\u043e \u0442\u043e\u043b\u044c\u043a\u043e \u043e\u0434\u0438\u043d \u043f\u043e\u0442\u043e\u043a \u0441\u043c\u043e\u0436\u0435\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u044c \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438 \u0432 \u044d\u0442\u043e\u043c \u043c\u0435\u0442\u043e\u0434\u0435.<\/p>\n<pre><code class=\"java\">private synchronized static void increment() {     Thread.sleep(1);     counter++; }<\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<h4>\u0420\u0435\u0430\u043b\u044c\u043d\u0430\u044f \u043f\u0440\u0430\u043a\u0442\u0438\u043a\u0430<\/h4>\n<p>\u0415\u0441\u043b\u0438 \u0432\u0430\u043c \u0432\u0434\u0440\u0443\u0433 \u043f\u043e\u043a\u0430\u0437\u0430\u043b\u043e\u0441\u044c, \u0447\u0442\u043e \u044d\u0442\u043e \u0431\u0430\u0437\u043e\u0432\u044b\u0435 \u0437\u043d\u0430\u043d\u0438\u044f \u0438 \u0441\u043e\u0432\u0435\u0440\u0448\u0430\u0442\u044c \u043e\u0448\u0438\u0431\u043a\u0443, \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u043d\u0443\u044e \u0432\u044b\u0448\u0435, \u0432 \u0440\u0435\u0430\u043b\u044c\u043d\u044b\u0445 \u043f\u0440\u043e\u0435\u043a\u0442\u0430\u0445 \u043d\u0438\u043a\u0442\u043e \u043d\u0435 \u0431\u0443\u0434\u0435\u0442, \u0442\u043e \u0442\u0443\u0442 \u0432\u044b&#8230; \u043f\u043e\u0447\u0442\u0438 \u0443\u0433\u0430\u0434\u0430\u043b\u0438. \u0412 DBeaver \u044f \u043d\u0430\u0448\u0451\u043b \u0442\u0440\u0438 \u043c\u0435\u0441\u0442\u0430, \u0433\u0434\u0435 \u0440\u0430\u0431\u043e\u0442\u0430 \u0432\u0435\u0434\u0451\u0442\u0441\u044f \u0441 <em>volatile<\/em> \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u043c\u0438 \u043f\u0440\u0438\u043c\u0438\u0442\u0438\u0432\u043d\u044b\u0445 \u0442\u0438\u043f\u043e\u0432. \u0418, \u043a\u0430\u043a \u044d\u0442\u043e \u0447\u0430\u0441\u0442\u043e \u0431\u044b\u0432\u0430\u0435\u0442 \u0432 \u0440\u0435\u0430\u043b\u044c\u043d\u043e\u0439 \u0436\u0438\u0437\u043d\u0438, \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u0438 \u043d\u0435 \u0442\u0430\u043a\u0438\u0435 \u043e\u0434\u043d\u043e\u0437\u043d\u0430\u0447\u043d\u044b\u0435. \u0413\u0434\u0435-\u0442\u043e \u043e\u043f\u0430\u0441\u043d\u0443\u044e \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u044e \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u0438\u0442\u044f\u043d\u0443\u0442\u044c, \u043d\u043e \u043f\u043e \u0431\u043e\u043b\u044c\u0448\u0435\u0439 \u0447\u0430\u0441\u0442\u0438 \u043d\u0438\u0447\u0435\u0433\u043e \u0441\u0442\u0440\u0430\u0448\u043d\u043e\u0433\u043e \u043f\u0440\u043e\u0438\u0437\u043e\u0439\u0442\u0438 \u043d\u0435 \u043c\u043e\u0436\u0435\u0442. \u0422\u0435\u043c \u043d\u0435 \u043c\u0435\u043d\u0435\u0435 \u0432\u043e\u0442 \u044d\u0442\u0438 \u0442\u0440\u0438 \u043c\u0435\u0441\u0442\u0430:<\/p>\n<details class=\"spoiler\">\n<summary>\u041f\u043e\u0434\u0441\u0447\u0451\u0442 \u0434\u0435\u0439\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0445 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0439<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"java\">public class MultiPageWizardDialog extends .... {     ....     private volatile int runningOperations = 0;      ....       @Override     public void run(....) {         ....         try {             runningOperations++;               \/\/ &lt;=             ModalContext.run(                runnable,                true,                monitorPart,                getShell().getDisplay()             );         } finally {             runningOperations--;               \/\/ &lt;=             ....         }     } }<\/code><\/pre>\n<p>\u041f\u0440\u0435\u0434\u0443\u043f\u0440\u0435\u0436\u0434\u0435\u043d\u0438\u044f PVS-Studio:<\/p>\n<ul>\n<li>\n<p><a href=\"https:\/\/pvs-studio.ru\/ru\/docs\/warnings\/v6074\/\">V6074<\/a> Non-atomic modification of volatile variable. Inspect &#8216;runningOperations&#8217;. MultiPageWizardDialog.java(590)<\/p>\n<\/li>\n<li>\n<p><a href=\"https:\/\/pvs-studio.ru\/ru\/docs\/warnings\/v6074\/\">V6074<\/a> Non-atomic modification of volatile variable. Inspect &#8216;runningOperations&#8217;. MultiPageWizardDialog.java(593)<\/p>\n<\/li>\n<\/ul>\n<p>\u0414\u0432\u0430 \u043f\u0440\u0435\u0434\u0443\u043f\u0440\u0435\u0436\u0434\u0435\u043d\u0438\u044f \u043f\u043e \u0446\u0435\u043d\u0435 \u043e\u0434\u043d\u043e\u0433\u043e, \u0438 \u043f\u043e \u0441\u043e\u0432\u043c\u0435\u0441\u0442\u0438\u0442\u0435\u043b\u044c\u0441\u0442\u0432\u0443 \u0435\u0434\u0438\u043d\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0435 \u043c\u0435\u0441\u0442\u043e, \u0433\u0434\u0435 \u0435\u0441\u0442\u044c \u0441\u043a\u043e\u043b\u044c\u043a\u043e-\u0442\u043e \u043e\u0441\u044f\u0437\u0430\u0435\u043c\u044b\u0439 \u0440\u0438\u0441\u043a. \u041a\u0430\u0437\u0430\u043b\u043e\u0441\u044c \u0431\u044b, \u0438\u043c\u0435\u0435\u043c \u043f\u043e\u0447\u0442\u0438 \u0447\u0442\u043e \u044d\u0442\u0430\u043b\u043e\u043d\u043d\u044b\u0439 \u0441\u043b\u0443\u0447\u0430\u0439 \u0438\u0434\u0435\u043d\u0442\u0438\u0447\u043d\u044b\u0439 \u0442\u043e\u043c\u0443, \u0447\u0442\u043e \u0431\u044b\u043b \u0432 \u0438\u0441\u043a\u0443\u0441\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u0432\u044b\u0448\u0435. \u0418 \u0432\u0441\u0451 \u0436\u0435, \u0435\u0441\u043b\u0438 \u043f\u0440\u0438\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c\u0441\u044f \u043a \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u044e \u043a\u043b\u0430\u0441\u0441\u0430 \u0438 \u043c\u0435\u0442\u043e\u0434\u0430, \u0433\u0434\u0435 \u0432\u0441\u0451 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 (<em>MultiPageWizardDialog<\/em> \u0438 <em>run<\/em> \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e), \u0442\u043e \u0441\u0442\u0430\u043d\u0435\u0442 \u043f\u043e\u043d\u044f\u0442\u043d\u043e, \u0447\u0442\u043e \u043c\u044b \u0438\u043c\u0435\u0435\u043c \u0434\u0435\u043b\u043e \u0441 UI, \u0438 \u043d\u0430\u0441\u0442\u043e\u044f\u0449\u0435\u0435 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u0433\u043e\u043d\u043a\u0438 \u0437\u0434\u0435\u0441\u044c \u0435\u0441\u043b\u0438 \u0438 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e \u0432\u043e\u043e\u0431\u0449\u0435, \u0442\u043e \u043e\u0447\u0435\u043d\u044c \u043c\u0430\u043b\u043e\u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e.<\/p>\n<p>\u0425\u043e\u0442\u044f \u0435\u0441\u043b\u0438 \u0432\u0441\u0451 \u0436\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u0438\u0442\u044c, \u0447\u0442\u043e \u043c\u0435\u0442\u043e\u0434 <em>run<\/em> \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u043b\u0438 \u0431\u044b \u043e\u0434\u043d\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e \u0438\u0437 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u0445 \u043f\u043e\u0442\u043e\u043a\u043e\u0432, \u0442\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 <em>runningOperations<\/em> \u0437\u0430\u043f\u0440\u043e\u0441\u0442\u043e \u043c\u043e\u0433\u043b\u043e \u0431\u044b \u043e\u043a\u0430\u0437\u0430\u0442\u044c\u0441\u044f \u043d\u0435\u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u044b\u043c.<\/p>\n<\/div>\n<\/details>\n<details class=\"spoiler\">\n<summary>\u041e\u0442\u0440\u0438\u0441\u043e\u0432\u043a\u0430 \u043f\u0440\u043e\u0433\u0440\u0435\u0441\u0441\u0430<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"java\">private volatile int drawCount = 0;  ....  private void showProgress() {     if (loadStartTime == 0) {         return;     }     if (progressOverlay == null) {         ....         painListener = e -> {             ....             Image image = DBeaverIcons.getImage(                 PROGRESS_IMAGES[drawCount % PROGRESS_IMAGES.length]             );             ....         };         ....     }     drawCount++;     .... }<\/code><\/pre>\n<p>\u041f\u0440\u0435\u0434\u0443\u043f\u0440\u0435\u0436\u0434\u0435\u043d\u0438\u0435 PVS-Studio:<\/p>\n<p><a href=\"https:\/\/pvs-studio.ru\/ru\/docs\/warnings\/v6074\/\">V6074<\/a> Non-atomic modification of volatile variable. Inspect &#8216;drawCount&#8217;. ProgressLoaderVisualizer.java(192)<\/p>\n<p>\u0421 \u0432\u0438\u0434\u0443 \u0441\u0430\u043c\u043e\u0435 \u043d\u0435\u043a\u0440\u0438\u0442\u0438\u0447\u043d\u043e\u0435 \u043c\u0435\u0441\u0442\u043e. <em>drawCount<\/em> \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u043a\u0430\u043a \u0441\u0435\u043b\u0435\u043a\u0442\u043e\u0440 \u043a\u0430\u0440\u0442\u0438\u043d\u043a\u0438 \u043f\u0440\u043e\u0433\u0440\u0435\u0441\u0441\u0430, \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0438\u0432\u0430\u044f \u0446\u0438\u043a\u043b\u0438\u0447\u0435\u0441\u043a\u0443\u044e \u043f\u0440\u043e\u043a\u0440\u0443\u0442\u043a\u0443 \u0438\u043d\u0434\u0435\u043a\u0441\u0430. \u0412\u043e-\u043f\u0435\u0440\u0432\u044b\u0445, \u043a\u0430\u0436\u0435\u0442\u0441\u044f, \u0447\u0442\u043e \u0446\u0435\u043d\u0430 \u043e\u0448\u0438\u0431\u043a\u0438 \u0432 \u0442\u0430\u043a\u043e\u043c \u043c\u0435\u0441\u0442\u0435 \u043d\u0435 \u0441\u0430\u043c\u0430\u044f \u0432\u044b\u0441\u043e\u043a\u0430\u044f. \u0412\u043e-\u0432\u0442\u043e\u0440\u044b\u0445, \u0441\u0430\u043c \u0444\u0430\u043a\u0442 \u0434\u043e\u0441\u0442\u0443\u043f\u0430 \u043a \u043e\u0442\u0440\u0438\u0441\u043e\u0432\u043a\u0435 \u0438\u0437 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u0445 <strong>\u043f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u044c\u043d\u044b\u0445<\/strong> \u043f\u043e\u0442\u043e\u043a\u043e\u0432 \u0437\u0432\u0443\u0447\u0438\u0442 \u0441\u043e\u043c\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u043e. \u0415\u0441\u043b\u0438 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u0435 \u043f\u0440\u0435\u0434\u043f\u043e\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u0432\u0435\u0440\u043d\u043e, \u0442\u043e \u043c\u043e\u0434\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440 <em>volatile<\/em> \u0437\u0434\u0435\u0441\u044c \u043d\u0435 \u043d\u0443\u0436\u0435\u043d.<\/p>\n<\/div>\n<\/details>\n<details class=\"spoiler\">\n<summary>\u041e\u0442\u0441\u043b\u0435\u0436\u0438\u0432\u0430\u043d\u0438\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0430 \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0439<\/summary>\n<div class=\"spoiler__content\">\n<p>\u0410\u043d\u0430\u043b\u0438\u0437\u0430\u0442\u043e\u0440 \u0432\u044b\u0434\u0430\u0451\u0442 \u043f\u0440\u0435\u0434\u0443\u043f\u0440\u0435\u0436\u0434\u0435\u043d\u0438\u0435 \u043d\u0430 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u043a\u043e\u0434:<\/p>\n<pre><code class=\"java\">private volatile int initializedCount = 0;  .... public CompareObjectsExecutor(CompareObjectsSettings settings) {     ....     initializeFinisher = new DBRProgressListener() {         @Override         public void onTaskFinished(IStatus status)         {             if (!status.isOK()) {                 initializeError = status;             } else {                 initializedCount++;             }         }     };     .... }<\/code><\/pre>\n<p>\u041f\u0440\u0435\u0434\u0443\u043f\u0440\u0435\u0436\u0434\u0435\u043d\u0438\u0435 PVS-Studio<\/p>\n<p><a href=\"https:\/\/pvs-studio.ru\/ru\/docs\/warnings\/v6074\/\">V6074<\/a> Non-atomic modification of volatile variable. Inspect &#8216;initializedCount&#8217;. CompareObjectsExecutor.java(130)<\/p>\n<p>\u0418 \u044d\u0442\u043e \u043c\u0435\u0441\u0442\u043e \u0431\u043e\u043b\u044c\u0448\u0435 \u0434\u0440\u0443\u0433\u0438\u0445 \u043f\u043e\u0445\u043e\u0436\u0435 \u043d\u0430 \u043e\u043f\u0430\u0441\u043d\u043e\u0435. \u041d\u043e \u043f\u043e\u043a\u0430 \u043d\u0430\u043c \u043d\u0435 \u0445\u0432\u0430\u0442\u0430\u0435\u0442 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0430, \u043d\u0430\u0434\u043e \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u043d\u0430 \u043c\u0435\u0441\u0442\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f <em>initializeFinisher<\/em> \u0438 <em>initializecCount<\/em>:<\/p>\n<pre><code class=\"java\">this.initializedCount = 0;  for (DBNDatabaseNode node : nodes) {     node.initializeNode(null, initializeFinisher);     .... } while (initializedCount != nodes.size()) {     Thread.sleep(50);     if (monitor.isCanceled()) {         throw new InterruptedException();     }     .... }<\/code><\/pre>\n<p>\u0418\u0442\u043e\u0433\u043e:<\/p>\n<ol>\n<li>\n<p>\u0421\u0447\u0451\u0442\u0447\u0438\u043a \u043e\u0431\u043d\u0443\u043b\u044f\u0435\u0442\u0441\u044f;<\/p>\n<\/li>\n<li>\n<p>\u0415\u0433\u043e \u0443\u0432\u0435\u043b\u0438\u0447\u0435\u043d\u0438\u0435 \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u0442\u0441\u044f \u0432 <em>node.initializeNode<\/em>;<\/p>\n<\/li>\n<li>\n<p>\u0414\u0430\u043b\u0435\u0435 \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u0442\u0441\u044f, \u0432\u0441\u0435 \u043b\u0438 \u0443\u0437\u043b\u044b \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u044b. \u0412 \u043f\u0440\u043e\u0442\u0438\u0432\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043f\u043e\u0442\u043e\u043a \u0437\u0430\u0441\u044b\u043f\u0430\u0435\u0442 \u043d\u0430 50 \u043c\u0438\u043b\u043b\u0438\u0441\u0435\u043a\u0443\u043d\u0434.<\/p>\n<\/li>\n<\/ol>\n<p>\u041a\u0430\u0437\u0430\u043b\u043e\u0441\u044c \u0431\u044b, \u044d\u0442\u0430\u043b\u043e\u043d\u043d\u044b\u0439 \u0441\u043b\u0443\u0447\u0430\u0439: \u0435\u0441\u043b\u0438 \u0434\u0432\u0430 \u043f\u043e\u0442\u043e\u043a\u0430 \u043e\u0434\u043d\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e \u0438\u043d\u043a\u0440\u0435\u043c\u0435\u043d\u0442\u0438\u0440\u0443\u044e\u0442 \u0441\u0447\u0451\u0442\u0447\u0438\u043a, \u0442\u043e \u0432\u0441\u044f \u043b\u043e\u0433\u0438\u043a\u0430 \u0441\u043b\u043e\u043c\u0430\u0435\u0442\u0441\u044f. \u0422\u0430\u043a \u0432\u0435\u0434\u044c? \u041d\u0435\u0442, \u0432 <em>node.initializeNode<\/em> \u043d\u0435\u0442 \u043d\u0438\u043a\u0430\u043a\u0438\u0445 \u043f\u043e\u0442\u043e\u043a\u043e\u0432. \u0422\u0430\u043c \u0432\u043e\u043e\u0431\u0449\u0435 \u043d\u0438\u0447\u0435\u0433\u043e \u043d\u0435\u0442 \ud83d\ude42<\/p>\n<pre><code class=\"java\">public boolean initializeNode(     DBRProgressMonitor monitor,     DBRProgressListener onFinish ) throws DBException {     if (onFinish != null) {         onFinish.onTaskFinished(Status.OK_STATUS);     }     return true; }<\/code><\/pre>\n<p>\u0412 \u043e\u0431\u0449\u0435\u043c, \u043d\u0435\u0441\u043c\u043e\u0442\u0440\u044f \u043d\u0430 \u0442\u043e \u0447\u0442\u043e <em>DBRProgressListener<\/em> \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0432 \u043f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u044c\u043d\u044b\u0445 \u0441\u0446\u0435\u043d\u0430\u0440\u0438\u044f\u0445, \u044d\u0442\u043e \u043d\u0435 \u0442\u043e\u0442 \u0441\u043b\u0443\u0447\u0430\u0439, \u0438 <em>volatile<\/em> \u0434\u043b\u044f <em>initializedCount<\/em> \u043a\u0430\u0436\u0435\u0442\u0441\u044f \u043f\u043e\u043f\u0440\u043e\u0441\u0442\u0443 \u0438\u0437\u0431\u044b\u0442\u043e\u0447\u043d\u044b\u043c, \u043a\u0430\u043a \u0438 \u0446\u0438\u043a\u043b \u0441 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u043e\u0439 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0430 \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0439.<\/p>\n<\/div>\n<\/details>\n<h4>\u0412\u043d\u0435\u0437\u0430\u043f\u043d\u044b\u0439 \u043f\u043e\u0432\u043e\u0440\u043e\u0442<\/h4>\n<p>\u0414\u043e \u044d\u0442\u043e\u0433\u043e \u043c\u044b \u0441\u043c\u043e\u0442\u0440\u0435\u043b\u0438 \u043d\u0430 \u043f\u0440\u043e\u0441\u0442\u044b\u0435 \u043f\u0440\u0438\u043c\u0435\u0440\u044b \u0441 \u043f\u0440\u0438\u043c\u0438\u0442\u0438\u0432\u043d\u044b\u043c\u0438 \u0442\u0438\u043f\u0430\u043c\u0438. \u0410 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u043b\u0438 \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u043f\u043e\u043b\u0435 \u0441\u0441\u044b\u043b\u043e\u0447\u043d\u043e\u0433\u043e \u0442\u0438\u043f\u0430 volatile, \u0447\u0442\u043e\u0431\u044b \u0433\u0430\u0440\u0430\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0430\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u0443\u044e \u0440\u0430\u0431\u043e\u0442\u0443? \u041e\u0442\u043d\u044e\u0434\u044c. \u041f\u043e\u0434\u0440\u043e\u0431\u043d\u0435\u0435 \u043c\u043e\u0436\u043d\u043e \u0443\u0437\u043d\u0430\u0442\u044c <a href=\"https:\/\/wiki.sei.cmu.edu\/confluence\/display\/java\/CON50-J.+Do+not+assume+that+declaring+a+reference+volatile+guarantees+safe+publication+of+the+members+of+the+referenced+object\">\u0437\u0434\u0435\u0441\u044c<\/a>. \u041d\u0435\u043c\u043d\u043e\u0433\u043e \u043c\u043e\u0434\u0438\u0444\u0438\u0446\u0438\u0440\u043e\u0432\u0430\u0432 \u043f\u0440\u043e\u0448\u043b\u044b\u0439 \u043f\u0440\u0438\u043c\u0435\u0440, \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u043b\u0435\u0433\u043a\u043e \u0434\u043e\u0431\u0438\u0442\u044c\u0441\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u0443 \u043d\u0430\u0441 \u0441\u043d\u043e\u0432\u0430 \u0432\u043e\u0437\u043d\u0438\u043a \u0431\u0435\u0441\u043a\u043e\u043d\u0435\u0447\u043d\u044b\u0439 \u0446\u0438\u043a\u043b:<\/p>\n<pre><code class=\"java\">private static class Proxy {     public String str; } private static volatile Proxy proxy = new Proxy(); public static void main() throws InterruptedException {     var proxy = Main.proxy;      new Thread(() -> {         while (proxy.str == null) { }         System.out.println(proxy.str);     }).start();      Thread.sleep(1);      proxy.str = \"Hello World!\"; }<\/code><\/pre>\n<p>\u041e\u0434\u043d\u043e \u0438\u0437 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u044b\u0445 \u0438\u0441\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u0439 \u2014 \u043e\u0442\u043c\u0435\u0442\u0438\u0442\u044c \u043f\u043e\u043b\u0435 <em>str<\/em> \u043a\u0430\u043a volatile, \u0438 \u0442\u043e\u0433\u0434\u0430 \u0432\u0441\u0451 \u0437\u0430\u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u043a\u0430\u043a \u043f\u0440\u0435\u0436\u0434\u0435. \u0427\u0442\u043e \u0436\u0435 \u0434\u043e \u0441\u0430\u043c\u043e\u0433\u043e \u043f\u043e\u043b\u044f <em>proxy<\/em>, \u0442\u043e \u0432 \u044d\u0442\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043a\u0430\u043a-\u043b\u0438\u0431\u043e \u043e\u0442\u043c\u0435\u0447\u0430\u0442\u044c \u0435\u0433\u043e \u0441\u043c\u044b\u0441\u043b\u0430 \u043d\u0435\u0442.<\/p>\n<details class=\"spoiler\">\n<summary>\u0418\u0441\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u043d\u0430\u044f \u0432\u0435\u0440\u0441\u0438\u044f<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"java\">private static class Proxy {     public volatile String str; } private static Proxy proxy = new Proxy(); public static void main() throws InterruptedException {     var proxy = TaskRunner.proxy;      new Thread(() -> {         while (proxy.str == null) { }         System.out.println(proxy.str);     }).start();      Thread.sleep(1);      proxy.str = \"Hello World!\"; }<\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<p>\u0422\u0430\u043a \u0447\u0442\u043e, \u043d\u0435\u0442 \u043d\u0438\u043a\u0430\u043a\u043e\u0433\u043e \u0441\u043c\u044b\u0441\u043b\u0430 \u0434\u0435\u043b\u0430\u0442\u044c \u0441\u0441\u044b\u043b\u043e\u0447\u043d\u043e\u0435 \u043f\u043e\u043b\u0435 volatile? \u0412\u043e\u0442 \u0442\u0443\u0442 \u043c\u044b, \u043d\u0430\u043a\u043e\u043d\u0435\u0446, \u0438 \u043f\u043e\u0434\u0445\u043e\u0434\u0438\u043c \u043a \u043f\u0430\u0442\u0442\u0435\u0440\u043d\u0443 Double-checked locking.<\/p>\n<h3>Double-checked locking<\/h3>\n<h4>\u0417\u0430\u0447\u0435\u043c?<\/h4>\n<p>\u042d\u0442\u043e\u0442 <a href=\"https:\/\/java-design-patterns.com\/patterns\/double-checked-locking\/\">\u043f\u0430\u0442\u0442\u0435\u0440\u043d<\/a> \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u043a\u0430\u043a \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u0441\u043f\u043e\u0441\u043e\u0431 \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u043e\u0442\u043b\u043e\u0436\u0435\u043d\u043d\u0443\u044e \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e \u0432 \u043c\u043d\u043e\u0433\u043e\u043f\u043e\u0442\u043e\u0447\u043d\u043e\u0439 \u0441\u0440\u0435\u0434\u0435. \u0415\u0433\u043e \u0441\u0443\u0442\u044c \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e \u043f\u0440\u043e\u0441\u0442\u0430: \u043f\u0435\u0440\u0435\u0434 &#171;\u0442\u044f\u0436\u0451\u043b\u043e\u0439&#187; \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u043e\u0439 \u0432 \u0431\u043b\u043e\u043a\u0435 \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u0438\u0437\u0430\u0446\u0438\u0438 \u0434\u0435\u043b\u0430\u0435\u0442\u0441\u044f \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0430 \u043e\u0431\u044b\u0447\u043d\u0430\u044f, \u0438 \u0442\u043e\u043b\u044c\u043a\u043e \u0435\u0441\u043b\u0438 \u0437\u0430\u043f\u0440\u0430\u0448\u0438\u0432\u0430\u0435\u043c\u044b\u0439 \u0440\u0435\u0441\u0443\u0440\u0441 \u0435\u0449\u0451 \u043d\u0435 \u0431\u044b\u043b \u0441\u043e\u0437\u0434\u0430\u043d, \u0442\u043e \u043f\u043e\u0442\u043e\u043a \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u043f\u043e\u0439\u0434\u0451\u0442 \u0434\u0430\u043b\u044c\u0448\u0435. \u0420\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u0438 \u043f\u0440\u0430\u0432\u0434\u0430 \u043a\u0430\u0436\u0435\u0442\u0441\u044f \u043d\u0435\u0437\u0430\u043c\u044b\u0441\u043b\u043e\u0432\u0430\u0442\u043e\u0439:<\/p>\n<pre><code class=\"java\">public class HolderThreadSafe {     private volatile ResourceClass resource;      public ResourceClass getResource() {         if (resource == null) {             synchronized (this) {                 if (resource == null) {                     resource = new ResourceClass();                 }             }         }         return resource;     } }<\/code><\/pre>\n<p>\u041f\u0430\u0442\u0442\u0435\u0440\u043d \u0447\u0430\u0449\u0435 \u0432\u0441\u0435\u0433\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0434\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u043e\u0434\u0438\u043d\u043e\u0447\u0435\u043a (\u0441\u0438\u043d\u0433\u043b\u0442\u043e\u043d\u043e\u0432) \u0438 \u043e\u0442\u043b\u043e\u0436\u0435\u043d\u043d\u043e\u0439 \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0442\u044f\u0436\u0451\u043b\u044b\u0445 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432. \u041d\u043e \u0432\u0441\u0451 \u043b\u0438 \u0442\u0443\u0442 \u0442\u0430\u043a \u043f\u0440\u043e\u0441\u0442\u043e?<\/p>\n<h4>\u0410\u043d\u0442\u0438\u043f\u0430\u0442\u0442\u0435\u0440\u043d?<\/h4>\n<p>\u0421 \u044d\u0442\u0438\u043c \u043f\u0430\u0442\u0442\u0435\u0440\u043d\u043e\u043c \u0441\u0432\u044f\u0437\u0430\u043d\u0430 \u043e\u0434\u043d\u0430 \u0437\u0430\u0431\u0430\u0432\u043d\u0430\u044f \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e\u0441\u0442\u044c. <a href=\"https:\/\/www.cs.umd.edu\/~pugh\/java\/memoryModel\/DoubleCheckedLocking.html\">\u041e\u043d \u043d\u0435 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442<\/a>. \u0412\u043e \u0432\u0441\u044f\u043a\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435, \u0435\u0441\u043b\u0438 \u0432\u0430\u0448 \u0432\u043e\u0437\u0440\u0430\u0441\u0442 \u043f\u0440\u0438\u043c\u0435\u0440\u043d\u043e \u0440\u0430\u0432\u0435\u043d \u0432\u043e\u0437\u0440\u0430\u0441\u0442\u0443 \u0434\u0438\u043d\u043e\u0437\u0430\u0432\u0440\u043e\u0432, \u0438 \u0432\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0435 Java \u043c\u0435\u043d\u044c\u0448\u0435\u0439 \u0432\u0435\u0440\u0441\u0438\u0438, \u0447\u0435\u043c \u043f\u044f\u0442\u0430\u044f. \u041d\u043e \u043d\u0435 \u043f\u0435\u0440\u0435\u043a\u043b\u044e\u0447\u0430\u0439\u0442\u0435\u0441\u044c. \u041d\u0430 \u0441\u0430\u043c\u043e\u043c \u0434\u0435\u043b\u0435, \u044d\u0442\u043e \u043a\u043b\u044e\u0447\u0435\u0432\u0430\u044f \u0442\u043e\u0447\u043a\u0430 \u043d\u0430\u0448\u0435\u0433\u043e \u043f\u043e\u0432\u0435\u0441\u0442\u0432\u043e\u0432\u0430\u043d\u0438\u044f \ud83d\ude42<\/p>\n<p>\u0418\u0442\u0430\u043a, \u0447\u0442\u043e \u0442\u0430\u043a\u043e\u0433\u043e \u0438\u0437\u043c\u0435\u043d\u0438\u043b\u043e\u0441\u044c \u0432 JDK 5? \u0412 \u043d\u0451\u043c \u0434\u043e\u0431\u0430\u0432\u0438\u043b\u0438 \u0442\u043e \u0441\u0430\u043c\u043e\u0435 \u043a\u043b\u044e\u0447\u0435\u0432\u043e\u0435 \u0441\u043b\u043e\u0432\u043e <em>volatile<\/em>. \u0422\u0443\u0442 \u043c\u043e\u0436\u043d\u043e \u0441\u0440\u0430\u0437\u0443 \u043c\u0435\u043d\u044f \u0440\u0430\u0441\u043a\u0443\u0441\u0438\u0442\u044c \u0438 \u0441\u043a\u0430\u0437\u0430\u0442\u044c, \u0447\u0442\u043e \u0432 \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u0432\u044b\u0448\u0435 <em>resource<\/em> \u043e\u0442\u043c\u0435\u0447\u0435\u043d \u043a\u0430\u043a volatile, \u043d\u043e \u044f \u0431\u044b \u0441\u0434\u0435\u043b\u0430\u043b \u0448\u0430\u0433 \u043d\u0430\u0437\u0430\u0434 \u0438 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u043b \u043d\u0430 \u043a\u043e\u0434. \u0410 \u0432 \u0447\u0451\u043c, \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u043e, \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430? \u041f\u043e\u0440\u044f\u0434\u043e\u043a \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0439 \u0442\u0443\u0442 \u0442\u0430\u043a\u043e\u0439:<\/p>\n<ol>\n<li>\n<p>\u041f\u0440\u043e\u0432\u0435\u0440\u043a\u0430 <em>resource<\/em> \u043d\u0430 <em>null<\/em>. \u042d\u0442\u0443 \u0442\u043e\u0447\u043a\u0443 \u043c\u043e\u0436\u0435\u0442 \u043f\u0440\u043e\u0439\u0442\u0438 \u043e\u0434\u043d\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043f\u043e\u0442\u043e\u043a\u043e\u0432;<\/p>\n<\/li>\n<li>\n<p>\u0412\u0445\u043e\u0434 \u0432 \u0431\u043b\u043e\u043a \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u0438\u0437\u0430\u0446\u0438\u0438. \u041f\u043e\u043f\u0430\u0441\u0442\u044c \u0442\u0443\u0434\u0430 \u043c\u043e\u0436\u0435\u0442 \u0442\u043e\u043b\u044c\u043a\u043e \u043e\u0434\u0438\u043d \u043f\u043e\u0442\u043e\u043a: <\/p>\n<ul>\n<li>\n<p>\u043f\u0435\u0440\u0432\u044b\u0439 \u043f\u043e\u0442\u043e\u043a, \u0441\u0434\u0435\u043b\u0430\u0432\u0448\u0438\u0439 \u044d\u0442\u043e, \u0432\u043e \u0432\u0442\u043e\u0440\u043e\u0439 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0435 \u0443\u0434\u043e\u0441\u0442\u043e\u0432\u0435\u0440\u0438\u0442\u0441\u044f, \u0447\u0442\u043e <em>resource<\/em> \u0435\u0449\u0451 \u043d\u0435 \u0441\u043e\u0437\u0434\u0430\u043d, \u043f\u043e\u0441\u043b\u0435 \u0447\u0435\u0433\u043e \u0441\u043e\u0437\u0434\u0430\u0441\u0442 \u0435\u0433\u043e \u0441\u0430\u043c;<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>\u0414\u0440\u0443\u0433\u0438\u0435 \u043f\u043e\u0442\u043e\u043a\u0438, \u043f\u0440\u043e\u0441\u043a\u043e\u0447\u0438\u0432\u0448\u0438\u0435 \u043f\u0435\u0440\u0432\u0443\u044e \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0443, \u043f\u043e\u043e\u0447\u0435\u0440\u0451\u0434\u043d\u043e \u043f\u043e\u043f\u0430\u0434\u0430\u044e\u0442 \u0432 \u0431\u043b\u043e\u043a \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u0438\u0437\u0430\u0446\u0438\u0438: <\/p>\n<ul>\n<li>\n<p>\u0442\u0430\u043c \u043e\u043d\u0438 \u0432\u0438\u0434\u044f\u0442, \u0447\u0442\u043e <em>resource<\/em> \u0443\u0436\u0435 \u0441\u043e\u0437\u0434\u0430\u043d, \u0438 \u0432\u044b\u0445\u043e\u0434\u044f\u0442 \u043e\u0442\u0442\u0443\u0434\u0430;<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>\u0412\u0441\u0435 \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u044b \u0438 \u0441\u0447\u0430\u0441\u0442\u043b\u0438\u0432\u044b.<\/p>\n<\/li>\n<\/ol>\n<p>\u041a\u0430\u0437\u0430\u043b\u043e\u0441\u044c \u0431\u044b, \u0437\u0430\u0447\u0435\u043c \u043d\u0430\u043c <em>volatile<\/em>, \u0435\u0441\u043b\u0438 \u043c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u0438\u0437\u0430\u0446\u0438\u044e \u0434\u043b\u044f \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u044f \u0434\u043e\u0441\u0442\u0443\u043f\u0430 \u043a \u043f\u043e\u043b\u044e? \u0418 \u043f\u0440\u0430\u0432\u0434\u0430, \u0432\u0438\u0434\u0438\u043c\u043e\u0441\u0442\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0434\u043b\u044f \u043f\u043e\u0442\u043e\u043a\u043e\u0432 \u0442\u0443\u0442 \u043d\u0435 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043a\u0430\u043c\u043d\u0435\u043c \u043f\u0440\u0435\u0442\u043a\u043d\u043e\u0432\u0435\u043d\u0438\u044f, \u043d\u043e \u0443 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c \u0434\u0432\u0435 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b:<\/p>\n<ul>\n<li>\n<p>\u043e\u043f\u0435\u0440\u0430\u0446\u0438\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432 <strong>\u043d\u0435 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0430\u0442\u043e\u043c\u0430\u0440\u043d\u043e\u0439<\/strong> (\u0441 \u043f\u0440\u0438\u043c\u0438\u0442\u0438\u0432\u043d\u044b\u043c\u0438 \u0442\u0438\u043f\u0430\u043c\u0438, \u0437\u0430 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435\u043c 64-\u0445 \u0431\u0438\u0442\u043d\u044b\u0445, \u043f\u0440\u043e\u0431\u043b\u0435\u043c \u043d\u0435 \u0431\u0443\u0434\u0435\u0442);<\/p>\n<\/li>\n<li>\n<p>\u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e \u043a\u0430\u043a \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440, \u0442\u0430\u043a \u0438 \u0431\u043e\u043b\u0435\u0435 \u043d\u0438\u0437\u043a\u043e\u0443\u0440\u043e\u0432\u043d\u0435\u0432\u044b\u0435 \u0441\u0438\u0441\u0442\u0435\u043c\u044b \u0438\u043c\u0435\u044e\u0442 \u043f\u0440\u0430\u0432\u043e** \u043f\u0435\u0440\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0442\u044c \u043f\u043e\u0440\u044f\u0434\u043e\u043a \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0439**.<\/p>\n<\/li>\n<\/ul>\n<p>\u0422\u043e \u0435\u0441\u0442\u044c \u043f\u043e\u0441\u043b\u0435\u0434\u0441\u0442\u0432\u0438\u044f \u0442\u0430\u043a\u0438\u0445 \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u0439 \u043c\u043e\u0433\u0443\u0442 \u043e\u043a\u0430\u0437\u0430\u0442\u044c\u0441\u044f \u043d\u0435\u043f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u0443\u0435\u043c\u044b\u043c\u0438. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440 \u043c\u043e\u0436\u0435\u0442 \u0437\u0430\u0438\u043d\u043b\u0430\u0439\u043d\u0438\u0442\u044c \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440 \u0438 \u043a\u0430\u043a \u0443\u0433\u043e\u0434\u043d\u043e \u043f\u043e\u043c\u0435\u043d\u044f\u0442\u044c \u043f\u043e\u0440\u044f\u0434\u043e\u043a \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u043f\u043e\u043b\u0435\u0439. \u041a\u0430\u043a \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442, \u043e\u0431\u044a\u0435\u043a\u0442 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043e\u0442\u043c\u0435\u0447\u0435\u043d \u043a\u0430\u043a \u0441\u043e\u0437\u0434\u0430\u043d\u043d\u044b\u0439, \u0434\u0440\u0443\u0433\u043e\u0439 \u043f\u043e\u0442\u043e\u043a \u044d\u0442\u043e \u0443\u0432\u0438\u0434\u0438\u0442 \u0438 \u043d\u0430\u0447\u043d\u0451\u0442 \u0435\u0433\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c, \u0438 \u043d\u0430\u0439\u0434\u0451\u0442 \u0442\u0430\u043c \u0435\u0449\u0451 \u043d\u0435\u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0435 \u043f\u043e\u043b\u044f. \u0418\u043c\u0435\u043d\u043d\u043e \u043e\u0442 \u044d\u0442\u043e\u0439 \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u0438 \u0441\u043f\u0430\u0441\u0430\u0435\u0442 \u0432\u044b\u0448\u0435\u043e\u043f\u0438\u0441\u0430\u043d\u043d\u044b\u0439 \u043f\u0440\u0438\u043d\u0446\u0438\u043f happens-before. \u0418 \u0434\u0430, \u0438\u043c\u0435\u043d\u043d\u043e \u0431\u043b\u0430\u0433\u043e\u0434\u0430\u0440\u044f volatile \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u043c double-check locking \u0432\u0441\u0451-\u0442\u0430\u043a\u0438 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442, \u043d\u0430\u0447\u0438\u043d\u0430\u044f \u0441 \u043f\u044f\u0442\u043e\u0439 \u0432\u0435\u0440\u0441\u0438\u0438 Java.<\/p>\n<h4>\u0422\u0430\u043a \u0432\u0441\u0451-\u0442\u0430\u043a\u0438 \u043f\u0430\u0442\u0442\u0435\u0440\u043d?<\/h4>\n<p>\u0427\u0442\u043e \u0436\u0435 \u043f\u043e\u0431\u0443\u0434\u0438\u043b\u043e \u043c\u0435\u043d\u044f \u0442\u0430\u043a \u0433\u043b\u0443\u0431\u043e\u043a\u043e \u0437\u0430\u043a\u043e\u043f\u0430\u0442\u044c\u0441\u044f \u0432 \u0442\u0435\u043e\u0440\u0438\u044e? \u041e\u0447\u0435\u0440\u0435\u0434\u043d\u043e\u0435 \u043f\u0440\u0435\u0434\u0443\u043f\u0440\u0435\u0436\u0434\u0435\u043d\u0438\u0435 \u0430\u043d\u0430\u043b\u0438\u0437\u0430\u0442\u043e\u0440\u0430 \u043d\u0430 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u043c\u0435\u0442\u043e\u0434 \u043f\u0440\u043e\u0435\u043a\u0442\u0430 DBeaver:<\/p>\n<pre><code class=\"java\">private List&lt;DBTTaskRun> runs; .... private void loadRunsIfNeeded() {     if (runs == null) {         synchronized (this) {             if (runs == null) {                 runs = new ArrayList&lt;>(loadRunStatistics());             }         }     } }<\/code><\/pre>\n<p><a href=\"https:\/\/pvs-studio.ru\/ru\/docs\/warnings\/v6082\/\">V6082<\/a> Unsafe double-checked locking. The field should be declared as volatile. TaskImpl.java(59), TaskImpl.java(317)<\/p>\n<p>\u0417\u0430\u0431\u0430\u0432\u043d\u043e, \u0447\u0442\u043e \u0432 <a href=\"https:\/\/java-design-patterns.com\/patterns\/double-checked-locking\/#applicability\">\u0441\u0431\u043e\u0440\u043d\u0438\u043a\u0435 \u043f\u0430\u0442\u0442\u0435\u0440\u043d\u043e\u0432<\/a>, \u043d\u0430 \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u044f \u0443\u0436\u0435 \u0441\u0441\u044b\u043b\u0430\u043b\u0441\u044f, \u0443\u043a\u0430\u0437\u0430\u043d \u0432\u043e\u0442 \u0442\u0430\u043a\u043e\u0439 \u043c\u0438\u043d\u0443\u0441:<\/p>\n<blockquote>\n<p>Complex implementation can lead to mistakes, such as incorrect publishing of objects due to memory visibility issues.<\/p>\n<\/blockquote>\n<details class=\"spoiler\">\n<summary>\u041f\u0435\u0440\u0435\u0432\u043e\u0434<\/summary>\n<div class=\"spoiler__content\">\n<p>\u0421\u043b\u043e\u0436\u043d\u0430\u044f \u0438\u043c\u043f\u043b\u0435\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u044f \u044d\u0442\u043e\u0433\u043e \u043f\u0430\u0442\u0442\u0435\u0440\u043d\u0430 \u043c\u043e\u0436\u0435\u0442 \u043f\u0440\u0438\u0432\u0435\u0441\u0442\u0438 \u043a \u043e\u0448\u0438\u0431\u043a\u0430\u043c. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043d\u0435\u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u0430\u044f \u043f\u0443\u0431\u043b\u0438\u043a\u0430\u0446\u0438\u044f \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432 \u0438\u0437-\u0437\u0430 \u043f\u0440\u043e\u0431\u043b\u0435\u043c \u0441 \u0432\u0438\u0434\u0438\u043c\u043e\u0441\u0442\u044c\u044e.<\/p>\n<\/div>\n<\/details>\n<p>\u0417\u0430\u043a\u043e\u043d\u043e\u043c\u0435\u0440\u043d\u043e, \u0447\u0442\u043e \u0438\u043c\u0435\u043d\u043d\u043e \u044d\u0442\u043e \u0438 \u043f\u0440\u043e\u0438\u0437\u043e\u0448\u043b\u043e \u0432 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \ud83d\ude42<\/p>\n<p>\u0412\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u044f\u0441\u044c \u043a \u0432\u043e\u043f\u0440\u043e\u0441\u0443, \u0437\u0430\u0434\u0430\u043d\u043d\u043e\u043c\u0443 \u043c\u043d\u043e\u044e \u0432 \u0442\u0435\u043e\u0440\u0435\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u043c \u0440\u0430\u0437\u0434\u0435\u043b\u0435:<\/p>\n<blockquote>\n<p>\u0422\u0430\u043a \u0447\u0442\u043e, \u043d\u0435\u0442 \u043d\u0438\u043a\u0430\u043a\u043e\u0433\u043e \u0441\u043c\u044b\u0441\u043b\u0430 \u0434\u0435\u043b\u0430\u0442\u044c \u0441\u0441\u044b\u043b\u043e\u0447\u043d\u043e\u0435 \u043f\u043e\u043b\u0435 volatile?<\/p>\n<\/blockquote>\n<p>\u0422\u043e\u0433\u0434\u0430 \u044f \u0441\u043b\u0443\u043a\u0430\u0432\u0438\u043b \u0438 \u043d\u0430\u043c\u0435\u0440\u0435\u043d\u043d\u043e \u043e\u043f\u0443\u0441\u0442\u0438\u043b \u043e\u0447\u0435\u0432\u0438\u0434\u043d\u0443\u044e \u0432\u0435\u0449\u044c. \u041a\u043e\u0433\u0434\u0430 \u043c\u044b \u043c\u0435\u043d\u044f\u0435\u043c \u043f\u043e\u043b\u0435 \u043e\u0431\u044a\u0435\u043a\u0442\u0430, \u043c\u044b \u043d\u0438\u043a\u0430\u043a \u043d\u0435 \u0442\u0440\u043e\u0433\u0430\u0435\u043c \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e, \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0449\u0443\u044e \u0441\u0441\u044b\u043b\u043a\u0443 \u043d\u0430 \u043e\u0431\u044a\u0435\u043a\u0442. \u041d\u043e \u0432\u043e\u0442 \u043f\u0440\u0438 <strong>\u043f\u0435\u0440\u0435\u0437\u0430\u043f\u0438\u0441\u0438<\/strong> \u044d\u0442\u043e\u0439 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439 \u0432\u0441\u044f \u0443\u043a\u0430\u0437\u0430\u043d\u043d\u0430\u044f \u0432 \u0442\u043e\u043c \u0440\u0430\u0437\u0434\u0435\u043b\u0435 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044f \u0441\u043d\u043e\u0432\u0430 \u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u0441\u044f \u0430\u043a\u0442\u0443\u0430\u043b\u044c\u043d\u043e\u0439. \u041f\u043e\u044d\u0442\u043e\u043c\u0443, \u0445\u043e\u0442\u044f \u0438 \u0441 \u0443\u043a\u0430\u0437\u0430\u043d\u043d\u044b\u043c\u0438 \u0440\u0430\u043d\u0435\u0435 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u044f\u043c\u0438 (volatile \u043f\u043e\u043b\u0435 \u043d\u0435 \u0433\u0430\u0440\u0430\u043d\u0442\u0438\u0440\u0443\u0435\u0442 \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e\u0439 \u043f\u0443\u0431\u043b\u0438\u043a\u0430\u0446\u0438\u0438 \u0447\u043b\u0435\u043d\u043e\u0432 \u043e\u0431\u044a\u0435\u043a\u0442\u0430, \u043d\u0430 \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043e\u043d\u043e \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u0441\u0441\u044b\u043b\u043a\u0443), \u0441\u0446\u0435\u043d\u0430\u0440\u0438\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0442, \u0438 \u044d\u0442\u043e \u043e\u0434\u0438\u043d \u0438\u0437 \u043d\u0438\u0445.<\/p>\n<h4>\u0418\u043b\u0438 \u0432\u0441\u0451-\u0442\u0430\u043a\u0438 \u043d\u0435\u0442?!<\/h4>\n<p>\u041a\u0430\u0436\u0435\u0442\u0441\u044f, \u0447\u0442\u043e \u0438\u0441\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0432 \u044d\u0442\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0441\u0430\u043c\u043e\u043e\u0447\u0435\u0432\u0438\u0434\u043d\u043e: \u043f\u0440\u043e\u0441\u0442\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0441\u043f\u0438\u0441\u043e\u043a <em>runs<\/em> volatile \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439. \u041f\u0440\u043e\u0431\u043b\u0435\u043c\u0443 \u044d\u0442\u043e \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0438\u0441\u043f\u0440\u0430\u0432\u0438\u0442, \u043d\u043e \u044f \u043f\u0440\u0435\u0434\u043b\u0430\u0433\u0430\u044e \u0435\u0449\u0451 \u0440\u0430\u0437 \u0432\u0441\u043f\u043e\u043c\u043d\u0438\u0442\u044c \u043f\u0440\u0435\u0434\u043d\u0430\u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u044d\u0442\u043e\u0433\u043e \u043f\u0430\u0442\u0442\u0435\u0440\u043d\u0430:<\/p>\n<blockquote>\n<p>The Double-Checked Locking pattern aims to reduce the overhead of acquiring a lock by first testing the locking criterion (the &#8216;lock hint&#8217;) without actually acquiring the lock. Only if the locking criterion check indicates that locking is necessary does the actual locking logic proceed.<\/p>\n<\/blockquote>\n<details class=\"spoiler\">\n<summary>\u041f\u0435\u0440\u0435\u0432\u043e\u0434<\/summary>\n<div class=\"spoiler__content\">\n<p>Double-checked locking \u043f\u0440\u0435\u0441\u043b\u0435\u0434\u0443\u0435\u0442 \u0446\u0435\u043b\u044c \u0443\u043c\u0435\u043d\u044c\u0448\u0438\u0442\u044c \u043d\u0430\u043a\u043b\u0430\u0434\u043d\u044b\u0435 \u0440\u0430\u0441\u0445\u043e\u0434\u044b \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0441\u0442\u0430\u0442\u0443\u0441\u0430 \u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u043a\u0438. \u042d\u0442\u043e \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u043f\u043e\u0441\u0440\u0435\u0434\u0441\u0442\u0432\u043e\u043c \u043f\u0435\u0440\u0432\u043e\u043e\u0447\u0435\u0440\u0435\u0434\u043d\u043e\u0439 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u043a\u0440\u0438\u0442\u0435\u0440\u0438\u044f \u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u043a\u0438 \u0431\u0435\u0437 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u043a\u0438 \u043a\u0430\u043a \u0442\u0430\u043a\u043e\u0432\u043e\u0439. \u0418 \u0442\u043e\u043b\u044c\u043a\u043e \u0435\u0441\u043b\u0438 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0430 \u043a\u0440\u0438\u0442\u0435\u0440\u0438\u044f \u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u043a\u0438 \u0433\u043e\u0432\u043e\u0440\u0438\u0442 \u043e \u0442\u043e\u043c, \u0447\u0442\u043e \u043e\u043d\u0430 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u0430, \u043b\u043e\u0433\u0438\u043a\u0430 \u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u043a\u0438 \u0437\u0430\u0434\u0435\u0439\u0441\u0442\u0432\u0443\u0435\u0442\u0441\u044f.<\/p>\n<\/div>\n<\/details>\n<p>\u0422\u043e \u0435\u0441\u0442\u044c \u043f\u0435\u0440\u0435\u0434 \u043d\u0430\u043c\u0438 \u043f\u0430\u0442\u0442\u0435\u0440\u043d, \u043f\u0440\u0435\u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u0441\u0432\u043e\u0435\u0439 \u0446\u0435\u043b\u044c\u044e \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u044e. \u0412 \u0447\u0451\u043c \u0442\u0443\u0442 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430? \u0421\u0434\u0435\u043b\u0430\u044e \u043d\u0430\u043c\u0451\u043a: \u0430 \u0432\u044b \u043f\u043e\u043c\u043d\u0438\u0442\u0435 \u043c\u043e\u044e \u0440\u0435\u043c\u0430\u0440\u043a\u0443 \u043f\u0440\u043e \u0434\u0438\u043d\u043e\u0437\u0430\u0432\u0440\u043e\u0432? \ud83d\ude42<\/p>\n<p>\u042d\u0442\u043e\u0442 \u043f\u0430\u0442\u0442\u0435\u0440\u043d \u0431\u044b\u043b \u0440\u043e\u0436\u0434\u0451\u043d \u0432 <strong>\u043e\u0447\u0435\u043d\u044c<\/strong> \u0434\u0430\u043b\u0451\u043a\u0438\u0435 \u0432\u0440\u0435\u043c\u0435\u043d\u0430, \u043a\u043e\u0433\u0434\u0430 <em>synchronized<\/em> \u043c\u0435\u0442\u043e\u0434\u044b \u0431\u044b\u043b\u0438 \u043e\u0447\u0435\u043d\u044c \u043c\u0435\u0434\u043b\u0435\u043d\u043d\u044b\u043c\u0438. \u041d\u0430 \u0441\u0435\u0433\u043e\u0434\u043d\u044f \u0438 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c JVM, \u0438 \u0436\u0435\u043b\u0435\u0437\u0430 \u043a\u0430\u043a \u0442\u0430\u043a\u043e\u0432\u043e\u0433\u043e \u0448\u0430\u0433\u043d\u0443\u043b\u0430 \u0434\u0430\u043b\u0435\u043a\u043e \u0432\u043f\u0435\u0440\u0451\u0434, \u0438\u0437-\u0437\u0430 \u0447\u0435\u0433\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u044d\u0442\u0443 (\u043c\u0438\u043a\u0440\u043e)\u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u044e \u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u0441\u044f \u043d\u0430\u043a\u043b\u0430\u0434\u043d\u043e \u0431\u0430\u043d\u0430\u043b\u044c\u043d\u043e \u0438\u0437-\u0437\u0430 \u0440\u0438\u0441\u043a\u0430 \u0432\u043e\u0442 \u0442\u0430\u043a\u0438\u0445 \u043e\u0448\u0438\u0431\u043e\u043a. \u0412 \u043f\u0440\u043e\u0441\u0442\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0441\u0438\u043d\u0433\u043b\u0442\u043e\u043d\u043e\u0432 \u0434\u043b\u044f \u043f\u043e\u0442\u043e\u043a\u043e\u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e\u0441\u0442\u0438 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0438\u0445 \u043a\u0430\u043a \u043f\u043e\u043b\u0435 \u043a\u043b\u0430\u0441\u0441\u0430:<\/p>\n<pre><code class=\"java\">class Holder {     static SomeSingleton singleton = new SomeSingleton(); } <\/code><\/pre>\n<p>\u0410 \u0432 \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u0445 \u0441\u043b\u0443\u0447\u0430\u044f\u0445 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u043f\u0440\u043e\u0441\u0442\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0435 \u043c\u0435\u0442\u043e\u0434\u044b, \u0435\u0441\u043b\u0438 \u0442\u043e\u043b\u044c\u043a\u043e \u0432\u0441\u0451 \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u043e\u0435 \u0435\u0449\u0451 \u043d\u0435 \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u043e.<\/p>\n<p>\u041a\u0441\u0442\u0430\u0442\u0438, \u0440\u0430\u0437 \u044f \u0443\u0436\u0435 \u0443\u043f\u043e\u043c\u0438\u043d\u0430\u043b C# \u0434\u043e \u044d\u0442\u043e\u0433\u043e, \u0441\u0434\u0435\u043b\u0430\u044e \u044d\u0442\u043e \u0435\u0449\u0451 \u0440\u0430\u0437. \u0417\u0430\u0431\u0430\u0432\u043d\u043e, \u043d\u043e \u0442\u0430\u043c \u0442\u043e\u0436\u0435 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u0442\u043e\u0447\u043d\u043e \u0442\u0430\u043a\u0430\u044f \u0436\u0435 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430, \u043e \u0447\u0451\u043c \u043c\u044b \u0443\u0436\u0435 <a href=\"https:\/\/pvs-studio.ru\/ru\/blog\/posts\/csharp\/0715\/\">\u043f\u0438\u0441\u0430\u043b\u0438<\/a>.<\/p>\n<h4>\u0418 \u0441\u043d\u043e\u0432\u0430 \u0432\u043d\u0435\u0437\u0430\u043f\u043d\u044b\u0439 \u043f\u043e\u0432\u043e\u0440\u043e\u0442<\/h4>\n<p>\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0435 \u043c\u0435\u0442\u043e\u0434\u044b? \u0410 \u0447\u0442\u043e, \u0435\u0441\u043b\u0438 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0438 \u0443\u0436\u0435 \u044d\u0442\u043e \u0434\u0435\u043b\u0430\u044e\u0442? \u0422\u043e\u0433\u0434\u0430 \u043f\u043e\u043b\u0435 <em>volatile<\/em> \u0431\u044b\u043b\u043e \u0431\u044b \u043f\u0440\u043e\u0441\u0442\u043e \u0438\u0437\u0431\u044b\u0442\u043e\u0447\u043d\u044b\u043c. \u041e\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0432 20 \u043c\u0435\u0441\u0442\u0430\u0445, \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043d\u0430 \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u044b\u0435 \u0442\u0440\u0438:<\/p>\n<details class=\"spoiler\">\n<summary>\u0420\u0430\u0437<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"java\">void addNewRun(@NotNull DBTTaskRun taskRun) {     synchronized (this) {         loadRunsIfNeeded();          runs.add(taskRun);          while (runs.size() > MAX_RUNS_IN_STATS) {             runs.remove(0);         }          flushRunStatistics(runs);     }      TaskRegistry.getInstance().notifyTaskListeners(....); }<\/code><\/pre>\n<p>\u0422\u0430\u043a, \u043c\u044b \u0441\u0440\u0430\u0437\u0443 \u043f\u043e\u043f\u0430\u043b\u0438 \u043d\u0430 \u0447\u0435\u0442\u044b\u0440\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f, \u043d\u043e \u0442\u0443\u0442 \u0435\u0441\u0442\u044c <em>synchronized<\/em> \u0431\u043b\u043e\u043a&#8230;<\/p>\n<\/div>\n<\/details>\n<details class=\"spoiler\">\n<summary>\u0414\u0432\u0430<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"java\">private void loadRunsIfNeeded() {     if (runs == null) {         synchronized (this) {             if (runs == null) {                 runs = new ArrayList&lt;>(loadRunStatistics());             }         }     } }<\/code><\/pre>\n<p>\u0415\u0449\u0451 \u0442\u0440\u0438 \u043f\u043e \u0446\u0435\u043d\u0435 \u043e\u0434\u043d\u043e\u0433\u043e, \u0438 \u0441\u043d\u043e\u0432\u0430 <em>synchronized<\/em>. \u041d\u0435\u0443\u0436\u0435\u043b\u0438 \u044f \u0432\u0441\u0451 \u044d\u0442\u043e \u0432\u0440\u0435\u043c\u044f \u043f\u0440\u043e\u0441\u0442\u043e \u0432\u0430\u043c \u043c\u043e\u0440\u043e\u0447\u0438\u043b \u0433\u043e\u043b\u043e\u0432\u0443?<\/p>\n<\/div>\n<\/details>\n<details class=\"spoiler\">\n<summary>\u0422\u0440\u0438<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"java\">@Override public void cleanRunStatistics() {     Path statsFolder = getTaskStatsFolder(false);     if (Files.exists(statsFolder)) {         ....     }     if (runs != null) {         runs.clear();     }     flushRunStatistics(List.of());     TaskRegistry.getInstance().notifyTaskListeners(....); }<\/code><\/pre>\n<p>\u0415\u0441\u0442\u044c! \u0415\u0441\u043b\u0438 \u043f\u0440\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u044c \u043f\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f\u043c \u044d\u0442\u043e\u0433\u043e \u043c\u0435\u0442\u043e\u0434\u0430, \u0442\u043e \u0432\u044b\u0448\u0435 \u043d\u0438\u0433\u0434\u0435 \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u0438\u0437\u0430\u0446\u0438\u0438 \u043d\u0435\u0442. \u041f\u043e\u043b\u0443\u0447\u0430\u0435\u0442\u0441\u044f, \u043c\u044b \u043d\u0430\u0448\u043b\u0438 \u0442\u043e, \u0447\u0442\u043e \u0438\u0441\u043a\u0430\u043b\u0438. \u041a \u0441\u043b\u043e\u0432\u0443, \u043c\u0435\u0441\u0442\u043e \u044d\u0442\u043e \u043d\u0435 \u0435\u0434\u0438\u043d\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0435.<\/p>\n<\/div>\n<\/details>\n<p>\u041a \u0447\u0435\u043c\u0443 \u0431\u044b\u043b\u043e \u043d\u0443\u0436\u043d\u043e \u044d\u0442\u043e \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435, \u0435\u0441\u043b\u0438 \u044f \u0441\u0440\u0430\u0437\u0443 \u043c\u043e\u0433 \u043f\u043e\u043a\u0430\u0437\u0430\u0442\u044c \u043c\u0435\u0441\u0442\u043e, \u0433\u0434\u0435 \u043d\u0435\u0442 \u043d\u0438\u043a\u0430\u043a\u043e\u0439 \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u0438\u0437\u0430\u0446\u0438\u0438? \u041f\u0440\u043e\u0441\u0442\u043e \u044d\u0442\u043e \u0435\u0449\u0451 \u043e\u0434\u043d\u0430 \u0441\u0430\u043c\u043e\u0441\u0442\u043e\u044f\u0442\u0435\u043b\u044c\u043d\u0430\u044f <a href=\"https:\/\/pvs-studio.ru\/ru\/docs\/warnings\/v6102\/\">\u043f\u043e\u0442\u0435\u043d\u0446\u0438\u0430\u043b\u044c\u043d\u0430\u044f \u0443\u044f\u0437\u0432\u0438\u043c\u043e\u0441\u0442\u044c<\/a>. \u0415\u0451 \u043f\u0440\u0438\u0441\u0443\u0442\u0441\u0442\u0432\u0438\u0435 \u043c\u043e\u0436\u0435\u0442 \u0441\u043f\u0440\u043e\u0432\u043e\u0446\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u0433\u043e\u043d\u043a\u0438 \u0441\u0430\u043c\u043e \u043f\u043e \u0441\u0435\u0431\u0435, \u0438 \u044d\u0442\u043e \u043f\u043e\u043c\u0438\u043c\u043e \u0442\u043e\u0433\u043e, \u0447\u0442\u043e \u043e\u043d\u0430 \u0434\u0435\u043b\u0430\u0435\u0442 \u043f\u043e\u0441\u043b\u0435\u0434\u0441\u0442\u0432\u0438\u044f \u043e\u0448\u0438\u0431\u043a\u0438 \u0441 double-check locking \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u044b\u043c\u0438.<\/p>\n<p>\u0412 \u043e\u0431\u0449\u0435\u043c, \u0447\u0442\u043e\u0431\u044b \u0438\u0441\u043f\u0440\u0430\u0432\u0438\u0442\u044c \u044d\u0442\u043e \u043c\u0435\u0441\u0442\u043e, \u043f\u043e\u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u043f\u0440\u0438\u043b\u043e\u0436\u0438\u0442\u044c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0431\u043e\u043b\u044c\u0448\u0435 \u0443\u0441\u0438\u043b\u0438\u0439, \u0432\u0435\u0434\u044c \u043f\u043e\u043a\u0430 \u0438\u0437\u0443\u0447\u0430\u043b\u0430\u0441\u044c \u043e\u0434\u043d\u0430 \u043e\u0448\u0438\u0431\u043a\u0430, \u043d\u0430\u0448\u043b\u0430\u0441\u044c \u0434\u0440\u0443\u0433\u0430\u044f.<\/p>\n<h3>\u0417\u0430\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435<\/h3>\n<p>\u041d\u0430\u0434\u0435\u044e\u0441\u044c, \u0432\u0430\u043c \u0431\u044b\u043b\u043e \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e \u043f\u043e\u0433\u0440\u0443\u0437\u0438\u0442\u044c\u0441\u044f \u0441\u043e \u043c\u043d\u043e\u0439 \u0432 \u0443\u0434\u0438\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u043c\u0438\u0440 \u043b\u043e\u0432\u0443\u0448\u0435\u043a \u043f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u044c\u043d\u043e\u0433\u043e \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f. \u041c\u043d\u043e\u0433\u0438\u0435 \u0443\u0442\u0432\u0435\u0440\u0436\u0434\u0430\u044e\u0442, \u0447\u0442\u043e \u0435\u0441\u043b\u0438 \u0432\u0430\u043c \u043f\u0440\u0438\u0445\u043e\u0434\u0438\u043b\u043e\u0441\u044c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c volatile \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435 \u0438\u043b\u0438 \u043f\u0430\u0442\u0442\u0435\u0440\u043d double-checked locking, \u0442\u043e \u0432\u044b \u0443\u0436\u0435 \u0434\u0435\u043b\u0430\u043b\u0438 \u0447\u0442\u043e-\u0442\u043e \u043d\u0435 \u0442\u0430\u043a. \u041b\u0438\u0431\u043e \u0432\u044b \u044d\u043a\u0441\u043f\u0435\u0440\u0442 \u0438 \u0442\u043e\u0447\u043d\u043e \u0437\u043d\u0430\u043b\u0438, \u0447\u0442\u043e \u0434\u0435\u043b\u0430\u043b\u0438 \ud83d\ude42<\/p>\n<p>\u0422\u0435\u043c \u043d\u0435 \u043c\u0435\u043d\u0435\u0435 \u0434\u0443\u043c\u0430\u044e, \u044d\u0442\u0430 \u0440\u0435\u043c\u0430\u0440\u043a\u0430 \u043d\u0435\u043f\u043b\u043e\u0445\u043e \u0440\u0435\u0437\u044e\u043c\u0438\u0440\u0443\u0435\u0442 \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u043d\u0438\u0435 \u0432\u0441\u0435\u0439 \u0441\u0442\u0430\u0442\u044c\u0438: \u043a\u0440\u043e\u043b\u0438\u0447\u044c\u044f \u043d\u043e\u0440\u0430 \u0438 \u043f\u0440\u0430\u0432\u0434\u0430 \u0433\u043b\u0443\u0431\u043e\u043a\u0430. \u0412\u043e \u0432\u0441\u044f\u043a\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0433\u043b\u0443\u0431\u043e\u043a\u0430 \u0434\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u0431\u044b\u0442\u044c \u0432\u0434\u0432\u043e\u0439\u043d\u0435 \u0432\u043d\u0438\u043c\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u043c, \u043a\u043e\u0433\u0434\u0430 \u0438\u043c\u0435\u0435\u0448\u044c \u0434\u0435\u043b\u043e \u0441 \u043f\u0440\u0435\u0434\u043c\u0435\u0442\u043e\u043c \u0441\u0442\u0430\u0442\u044c\u0438.<\/p>\n<p>\u0415\u0441\u043b\u0438 \u0445\u043e\u0447\u0435\u0442\u0441\u044f \u043f\u043e\u0438\u0441\u043a\u0430\u0442\u044c \u044d\u0442\u0438 \u0438\u043b\u0438 \u0434\u0440\u0443\u0433\u0438\u0435 \u043e\u0448\u0438\u0431\u043a\u0438 \u0432 \u0441\u0432\u043e\u0451\u043c \u043f\u0440\u043e\u0435\u043a\u0442\u0435, \u0442\u043e \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0431\u0435\u0441\u043f\u043b\u0430\u0442\u043d\u043e \u043f\u043e\u043f\u0440\u043e\u0431\u043e\u0432\u0430\u0442\u044c PVS-Studio, \u043f\u0435\u0440\u0435\u0439\u0434\u044f \u043f\u043e <a href=\"https:\/\/pvs-studio.ru\/ru\/pvs-studio\/try-free\/?utm_source=website&amp;utm_medium=habr&amp;utm_campaign=article&amp;utm_content=1128\">\u044d\u0442\u043e\u0439<\/a> \u0441\u0441\u044b\u043b\u043a\u0435.<\/p>\n<p>\u0410 \u0435\u0449\u0451 \u044f \u043d\u0430\u043f\u043e\u043c\u043d\u044e, \u0447\u0442\u043e \u044d\u0442\u043e \u043d\u0435 \u0432\u0441\u0435 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u044b\u0435 \u0432\u0435\u0449\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0431\u044b\u043b\u0438 \u043d\u0430\u0439\u0434\u0435\u043d\u044b \u0432 <a href=\"https:\/\/github.com\/dbeaver\/dbeaver\">DBeaver<\/a>, \u0438 \u043a \u0432\u044b\u0445\u043e\u0434\u0443 \u043f\u043b\u0430\u043d\u0438\u0440\u0443\u044e\u0442\u0441\u044f \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u0441\u0442\u0430\u0442\u044c\u0438. \u041f\u043e\u0441\u043b\u0435 \u0438\u0445 \u043f\u0443\u0431\u043b\u0438\u043a\u0430\u0446\u0438\u0438 \u044f \u0434\u043e\u0431\u0430\u0432\u043b\u044e \u0441\u0441\u044b\u043b\u043a\u0438 \u0441\u044e\u0434\u0430, \u0430 \u043f\u043e\u043a\u0430 \u043f\u0440\u0435\u0434\u043b\u0430\u0433\u0430\u044e \u043f\u043e\u0434\u043f\u0438\u0441\u0430\u0442\u044c\u0441\u044f \u043d\u0430 \u043c\u043e\u0439 <a href=\"https:\/\/x.com\/kvolokhovskii\">\u0425-\u0442\u0432\u0438\u0442\u0442\u0435\u0440<\/a>, \u0447\u0442\u043e\u0431\u044b \u043d\u0435 \u043f\u0440\u043e\u043f\u0443\u0441\u0442\u0438\u0442\u044c \u0438\u0445 \u0432\u044b\u0445\u043e\u0434.<\/p>\n<p>\u0415\u0441\u043b\u0438 \u0445\u043e\u0442\u0438\u0442\u0435 \u043f\u043e\u0434\u0435\u043b\u0438\u0442\u044c\u0441\u044f \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435\u0439 \u0441 \u0430\u043d\u0433\u043b\u043e\u044f\u0437\u044b\u0447\u043d\u043e\u0439 \u0430\u0443\u0434\u0438\u0442\u043e\u0440\u0438\u0435\u0439, \u0442\u043e \u043f\u0440\u043e\u0448\u0443 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0441\u0441\u044b\u043b\u043a\u0443 \u043d\u0430 \u043f\u0435\u0440\u0435\u0432\u043e\u0434: Konstantin Volohovsky. <a href=\"https:\/\/pvs-studio.com\/en\/blog\/posts\/java\/1128\/\">Volatile, DCL, and synchronization pitfalls in Java<\/a>.<\/p>\n<\/div>\n<\/div>\n<\/div>\n<p><!----><!----><\/div>\n<p><!----><!----><br \/> \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\/819625\/\"> https:\/\/habr.com\/ru\/articles\/819625\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u0410 \u0447\u0442\u043e \u0435\u0441\u043b\u0438 \u043e\u043a\u0430\u0436\u0435\u0442\u0441\u044f, \u0447\u0442\u043e \u043f\u0440\u043e\u0441\u0442\u044b\u0435 \u0437\u043d\u0430\u043d\u0438\u044f \u043d\u0430 \u0441\u0430\u043c\u043e\u043c \u0434\u0435\u043b\u0435 \u0431\u043e\u043b\u0435\u0435 \u043d\u044e\u0430\u043d\u0441\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0435, \u0430 \u0441\u0442\u0430\u0440\u044b\u0435 \u0437\u043d\u0430\u043a\u043e\u043c\u044b\u0435, \u0442\u0430\u043a\u0438\u0435 \u043a\u0430\u043a Double-checked locking, \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u043d\u0435\u043e\u0434\u043d\u043e\u0437\u043d\u0430\u0447\u043d\u044b\u043c\u0438? \u0418\u043c\u0435\u043d\u043d\u043e \u043d\u0430 \u0442\u0430\u043a\u0438\u0435 \u043c\u044b\u0441\u043b\u0438 \u043d\u0430\u0442\u0430\u043b\u043a\u0438\u0432\u0430\u0435\u0442 \u0438\u0437\u0443\u0447\u0435\u043d\u0438\u0435 \u043a\u043e\u0434\u0430 \u0440\u0435\u0430\u043b\u044c\u043d\u044b\u0445 \u043f\u0440\u043e\u0435\u043a\u0442\u043e\u0432. \u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u044d\u0442\u043e\u0433\u043e \u0438\u0441\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u043d\u0438\u044f \u043c\u044b \u0438 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0432 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435.<\/p>\n<figure class=\"full-width\"><\/figure>\n<h3>\u041f\u0440\u0435\u0434\u0438\u0441\u043b\u043e\u0432\u0438\u0435<\/h3>\n<p>\u041d\u0435 \u0442\u0430\u043a \u0434\u0430\u0432\u043d\u043e \u044f \u2014 \u0432 \u043f\u043e\u0440\u044f\u0434\u043a\u0435 \u043e\u0431\u044b\u0447\u043d\u043e\u0439 \u0434\u0435\u044f\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u043f\u043e \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0435 \u043e\u0442\u043a\u0440\u044b\u0442\u044b\u0445 \u043f\u0440\u043e\u0435\u043a\u0442\u043e\u0432 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e PVS-Studio \u2014 \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u043b \u0442\u043e\u043b\u044c\u043a\u043e \u0432\u044b\u0448\u0435\u0434\u0448\u0443\u044e \u0442\u043e\u0433\u0434\u0430 24-\u044e \u0432\u0435\u0440\u0441\u0438\u044e \u0438\u0437\u0432\u0435\u0441\u0442\u043d\u043e\u0433\u043e \u043f\u0440\u043e\u0435\u043a\u0442\u0430 <a href=\"https:\/\/github.com\/dbeaver\/dbeaver\">DBeaver<\/a>. \u041d\u0430\u0434\u043e \u043f\u0440\u0438\u0437\u043d\u0430\u0442\u044c, \u043c\u0435\u043d\u044f \u043f\u0440\u0438\u044f\u0442\u043d\u043e \u0443\u0434\u0438\u0432\u0438\u043b\u043e \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u043e \u0435\u0433\u043e \u043a\u043e\u0434\u0430 \u2014 \u043d\u0435\u0434\u0430\u0440\u043e\u043c \u043e\u043d\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u044b \u0441\u0442\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0433\u043e \u0430\u043d\u0430\u043b\u0438\u0437\u0430. \u041d\u043e \u044f \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0438\u043b \u0438\u0441\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u043d\u0438\u0435 \u0438 \u043d\u0430\u0448\u0451\u043b \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043f\u043e\u0434\u043e\u0437\u0440\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u043c\u0435\u0441\u0442, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u0435\u043d\u044f \u0437\u0430\u0446\u0435\u043f\u0438\u043b\u0438. \u0417\u0430\u0446\u0435\u043f\u0438\u043b\u0438 \u043d\u0430\u0441\u0442\u043e\u043b\u044c\u043a\u043e, \u0447\u0442\u043e \u043a\u0430\u0436\u0434\u043e\u043c\u0443 \u044f \u0440\u0435\u0448\u0438\u043b \u043f\u043e\u0441\u0432\u044f\u0442\u0438\u0442\u044c \u043f\u043e \u0441\u0442\u0430\u0442\u044c\u0435, \u0442\u0430\u043a \u0447\u0442\u043e \u043f\u0440\u0438\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e \u0432 \u043f\u0435\u0440\u0432\u043e\u0439 \u0447\u0430\u0441\u0442\u0438 \u0446\u0438\u043a\u043b\u0430.<\/p>\n<h3>\u041f\u043e\u0442\u043e\u043a\u043e\u043d\u0435\u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e\u0435 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435<\/h3>\n<h4>\u041e \u0447\u0451\u043c \u0440\u0435\u0447\u044c?<\/h4>\n<p>\u041f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u044c\u043d\u043e\u0435 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0442\u0430\u0438\u0442 \u0432 \u0441\u0435\u0431\u0435 \u043a\u0443\u0447\u0443 \u0433\u0440\u0430\u0431\u043b\u0435\u0439. \u0418, \u0440\u0430\u0437\u0443\u043c\u0435\u0435\u0442\u0441\u044f, \u043d\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u0432 Java \u2014 \u0442\u043e\u0442 \u0436\u0435 \u0437\u043b\u043e\u0439 (\u0438\u043b\u0438 \u0434\u043e\u0431\u0440\u044b\u0439 \ud83d\ude42 ) \u0431\u0440\u0430\u0442-\u0431\u043b\u0438\u0437\u043d\u0435\u0446 C# \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043b\u0435\u0433\u043a\u043e \u043e\u0441\u0442\u0443\u043f\u0438\u0442\u044c\u0441\u044f \u043f\u0440\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0438 <a href=\"https:\/\/pvs-studio.ru\/ru\/docs\/warnings\/v3083\/\">\u0441\u043e\u0431\u044b\u0442\u0438\u0439<\/a> \u0432 \u043f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u044c\u043d\u044b\u0445 \u0441\u0446\u0435\u043d\u0430\u0440\u0438\u044f\u0445. \u0418\u0437\u0432\u0435\u0441\u0442\u043d\u043e, \u0447\u0442\u043e \u0437\u0430\u0447\u0430\u0441\u0442\u0443\u044e \u0438\u043c\u0435\u043d\u043d\u043e \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u044b\u0435 \u0438 \u043c\u043d\u043e\u0433\u043e\u043f\u043e\u0442\u043e\u0447\u043d\u044b\u0435 \u043e\u0448\u0438\u0431\u043a\u0438 \u0441\u043b\u043e\u0436\u043d\u0435\u0435 \u0432\u0441\u0435\u0433\u043e \u043e\u0442\u043b\u0430\u0432\u043b\u0438\u0432\u0430\u0442\u044c.<\/p>\n<p>\u0414\u0430\u043b\u0435\u0435 \u043c\u044b \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043d\u0430 \u0442\u0440\u0438 \u0442\u0438\u043f\u0430 \u0442\u0430\u043a\u0438\u0445 \u043e\u0448\u0438\u0431\u043e\u043a. \u041f\u0435\u0440\u0432\u043e\u0439 \u0438\u0437 \u043d\u0438\u0445 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043d\u0435\u0430\u0442\u043e\u043c\u0430\u0440\u043d\u043e\u0435 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0435 volatile \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445.<\/p>\n<h4>\u0415\u0449\u0451 \u0440\u0430\u0437, \u0447\u0442\u043e \u0442\u0430\u043a\u043e\u0435 volatile?<\/h4>\n<p>\u0418\u0437 <a href=\"https:\/\/docs.oracle.com\/javase\/tutorial\/essential\/concurrency\/atomic.html\">\u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438<\/a> \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0443\u0437\u043d\u0430\u0442\u044c, \u0447\u0442\u043e \u043a\u043b\u044e\u0447\u0435\u0432\u043e\u0435 \u0441\u043b\u043e\u0432\u043e <em>volatile<\/em>:<\/p>\n<ol>\n<li>\n<p>\u041f\u0440\u0435\u0434\u043e\u0442\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u043a\u044d\u0448\u0430 \u0434\u043b\u044f \u0440\u0430\u0437\u043d\u044b\u0445 \u043f\u043e\u0442\u043e\u043a\u043e\u0432, \u0442\u0435\u043c \u0441\u0430\u043c\u044b\u043c \u0433\u0430\u0440\u0430\u043d\u0442\u0438\u0440\u0443\u044f, \u0447\u0442\u043e \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u0432 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439 \u0431\u0443\u0434\u0443\u0442 \u0441\u0440\u0430\u0437\u0443 \u0432\u0438\u0434\u043d\u044b \u0432\u0441\u0435\u043c \u043f\u043e\u0442\u043e\u043a\u0430\u043c;<\/p>\n<\/li>\n<li>\n<p>\u0423\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u0442 happens-before \u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u0435 \u043c\u0435\u0436\u0434\u0443 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439 \u0438 \u0447\u0442\u0435\u043d\u0438\u044f\u043c\u0438\/\u0437\u0430\u043f\u0438\u0441\u044c\u044e \u0440\u044f\u0434\u043e\u043c, \u0442\u0435\u043c \u0441\u0430\u043c\u044b\u043c \u0437\u0430\u043f\u0440\u0435\u0449\u0430\u044f \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u044c \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u0438, \u043e\u0441\u043d\u043e\u0432\u0430\u043d\u043d\u044b\u0435 \u043d\u0430 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0438 \u043f\u043e\u0440\u044f\u0434\u043a\u0430 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0439.<\/p>\n<\/li>\n<\/ol>\n<p>\u041f\u0440\u043e\u0434\u0435\u043c\u043e\u043d\u0441\u0442\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0440\u0430\u0431\u043e\u0442\u0443 \u044d\u0442\u043e\u0433\u043e \u043a\u043b\u044e\u0447\u0435\u0432\u043e\u0433\u043e \u0441\u043b\u043e\u0432\u0430 \u043c\u043e\u0436\u0435\u0442 \u043f\u0440\u043e\u0437\u0430\u0438\u0447\u043d\u044b\u0439 \u043f\u0440\u0438\u043c\u0435\u0440 \u0441 \u043f\u043e\u0442\u043e\u043a\u043e\u043c, \u043e\u0436\u0438\u0434\u0430\u044e\u0449\u0438\u043c \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439:<\/p>\n<pre><code class=\"java\">private static volatile String str; public static void main() throws InterruptedException {     new Thread(() -> {         while (str == null) { }         System.out.println(str);     }).start();      Thread.sleep(1);      str = \"Hello World!\"; }<\/code><\/pre>\n<p>\u0415\u0441\u043b\u0438 \u0443\u0431\u0440\u0430\u0442\u044c <em>volatile<\/em>, \u0442\u043e \u0446\u0438\u043a\u043b \u0431\u0443\u0434\u0435\u0442 \u0431\u0435\u0441\u043a\u043e\u043d\u0435\u0447\u043d\u044b\u043c. \u041f\u043e \u043a\u0440\u0430\u0439\u043d\u0435\u0439 \u043c\u0435\u0440\u0435, \u0432 \u043c\u043e\u0451\u043c \u0441\u043b\u0443\u0447\u0430\u0435. \u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u043c\u043e\u0436\u0435\u0442 \u0441\u0438\u043b\u044c\u043d\u043e \u0437\u0430\u0432\u0438\u0441\u0435\u0442\u044c \u043e\u0442 JVM \u0438 \u0436\u0435\u043b\u0435\u0437\u0430.<\/p>\n<details class=\"spoiler\">\n<summary>\u0410 \u043a\u0430\u043a \u0443\u0432\u0438\u0434\u0435\u0442\u044c \u0440\u0430\u0431\u043e\u0442\u0443 happens-before \u0432 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0438?<\/summary>\n<div class=\"spoiler__content\">\n<p>\u0415\u0441\u043b\u0438 \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u043c\u043e\u0434\u0438\u0444\u0438\u0446\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043f\u0440\u0438\u043c\u0435\u0440, \u0434\u043e\u0431\u0430\u0432\u0438\u0432 \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u0443\u044e \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e, \u0442\u043e \u0441\u0442\u0430\u043d\u0435\u0442 \u044f\u0441\u0435\u043d \u0438 \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c \u0440\u0430\u0431\u043e\u0442\u044b happens-before:<\/p>\n<pre><code class=\"java\">private static String str; private static volatile boolean flag = false; public static void main() throws InterruptedException {     new Thread(() -> {         while (!flag) { }         System.out.println(str);     }).start();      Thread.sleep(1);      str = \"Hello World!\";     flag = true; }<\/code><\/pre>\n<p>\u0415\u0441\u043b\u0438 \u0431\u044b \u0443 \u043d\u0430\u0441 \u0431\u044b\u043b\u0430 <strong>\u0442\u043e\u043b\u044c\u043a\u043e<\/strong> \u0433\u0430\u0440\u0430\u043d\u0442\u0438\u044f \u0432\u0438\u0434\u0438\u043c\u043e\u0441\u0442\u0438, \u0442\u043e \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440 \u0438\u043b\u0438 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0440 \u043c\u043e\u0433\u043b\u0438 \u0431\u044b \u043f\u043e\u043c\u0435\u043d\u044f\u0442\u044c \u043f\u043e\u0440\u044f\u0434\u043e\u043a \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0439 \u043f\u0440\u0438\u0441\u0432\u0430\u0438\u0432\u0430\u043d\u0438\u044f \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u043c <em>str<\/em> \u0438 <em>flag<\/em>. \u0418 \u0442\u043e\u0433\u0434\u0430 \u0431\u044b\u043b\u0430 \u0431\u044b \u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e\u0441\u0442\u044c \u043f\u043e\u043f\u0430\u0441\u0442\u044c \u0432 <em>System.out.println(str)<\/em> \u0432 \u043c\u043e\u043c\u0435\u043d\u0442\u0435, \u043a\u043e\u0433\u0434\u0430 <em>str<\/em> \u0435\u0449\u0451 \u0440\u0430\u0432\u043d\u044f\u0435\u0442\u0441\u044f <em>null<\/em>.<\/p>\n<p>\u0422\u0435\u043c \u043d\u0435 \u043c\u0435\u043d\u0435\u0435 \u043f\u0440\u0438\u043d\u0446\u0438\u043f happens-before \u0433\u0430\u0440\u0430\u043d\u0442\u0438\u0440\u0443\u0435\u0442, \u0447\u0442\u043e \u0437\u0430\u043f\u0438\u0441\u044c, \u043d\u0430\u0445\u043e\u0434\u044f\u0449\u0430\u044f\u0441\u044f \u043f\u0435\u0440\u0435\u0434 \u0437\u0430\u043f\u0438\u0441\u044c\u044e \u0432 volatile \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e, \u043e\u0441\u0442\u0430\u043d\u0435\u0442\u0441\u044f \u0442\u0430\u043c \u0436\u0435.<\/p>\n<\/div>\n<\/details>\n<h4>\u0413\u043e\u043d\u043a\u0430<\/h4>\n<p>\u041d\u0435\u0441\u043c\u043e\u0442\u0440\u044f \u043d\u0430 \u0442\u043e, \u0447\u0442\u043e \u0443 \u043d\u0430\u0441 \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0435\u043d\u0430 \u0432\u0438\u0434\u0438\u043c\u043e\u0441\u0442\u044c \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439, \u044d\u0442\u043e\u0433\u043e, \u043a\u043e\u043d\u0435\u0447\u043d\u043e, \u043d\u0435 \u0445\u0432\u0430\u0442\u0438\u0442 \u0434\u043b\u044f \u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u043e\u0439 \u0440\u0430\u0431\u043e\u0442\u044b \u0432 \u043f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u044c\u043d\u044b\u0445 \u043f\u043e\u0442\u043e\u043a\u0430\u0445:<\/p>\n<pre><code class=\"java\">private static volatile int counter = 0; private static void increment() {     Thread.sleep(1);     counter++; } public static void main() {     var threads = Stream.generate(() -> new Thread(Main::increment))                         .limit(100)                         .toList();      threads.forEach(Thread::start);     while (threads.stream().anyMatch(Thread::isAlive)) {         Thread.yield();     }      System.out.println(counter); }<\/code><\/pre>\n<p>\u0422\u0430\u043a\u043e\u0439 \u043a\u043e\u0434 \u0431\u0443\u0434\u0435\u0442 \u0441\u0442\u0430\u0431\u0438\u043b\u044c\u043d\u043e \u0432\u044b\u0432\u043e\u0434\u0438\u0442\u044c \u0447\u0438\u0441\u043b\u043e \u043c\u0435\u043d\u044c\u0448\u0435\u0435, \u0447\u0435\u043c 100. \u041d\u0435\u0443\u0434\u0438\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u043e, \u0432\u0435\u0434\u044c \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u044f \u0438\u043d\u043a\u0440\u0435\u043c\u0435\u043d\u0442\u0430 \u043d\u0435 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0430\u0442\u043e\u043c\u0430\u0440\u043d\u043e\u0439, \u0438 \u043e\u0434\u0438\u043d \u043f\u043e\u0442\u043e\u043a \u043c\u043e\u0436\u0435\u0442 \u0432\u043b\u0435\u0437\u0442\u044c \u043f\u043e\u043f\u0435\u0440\u0451\u043a \u0434\u0440\u0443\u0433\u043e\u0433\u043e. \u042d\u0442\u043e \u043c\u043e\u0436\u0435\u0442 \u043f\u0440\u043e\u0438\u0437\u043e\u0439\u0442\u0438 \u043a\u0430\u043a \u0440\u0430\u0437 \u043c\u0435\u0436\u0434\u0443 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u044f\u043c\u0438 \u0432\u0437\u044f\u0442\u0438\u044f \u0441\u0442\u0430\u0440\u043e\u0433\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f <em>counter<\/em> \u0438 \u0443\u0432\u0435\u043b\u0438\u0447\u0435\u043d\u0438\u044f \u0435\u0433\u043e \u043d\u0430 1. \u0418\u0441\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u0439 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0434\u0432\u0430, \u043e\u0434\u043d\u043e \u043f\u0440\u043e\u0449\u0435 \u0434\u0440\u0443\u0433\u043e\u0433\u043e:<\/p>\n<details class=\"spoiler\">\n<summary>Atomic \u0442\u0438\u043f\u044b<\/summary>\n<div class=\"spoiler__content\">\n<p>\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u044b\u0435 \u0442\u0438\u043f\u044b \u0434\u0430\u043d\u043d\u044b\u0445, \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u044e\u0449\u0438\u0435 \u0433\u043e\u0442\u043e\u0432\u044b\u0439 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0438\u0437 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u0445 \u043f\u043e\u0442\u043e\u043a\u043e\u0432. \u0412 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u2014 <em>AtomicInteger<\/em>.<\/p>\n<pre><code class=\"java\">private static final AtomicInteger counter = new AtomicInteger(0); private static void increment() {     Thread.sleep(1);     counter.incrementAndGet(); }<\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<details class=\"spoiler\">\n<summary>\u0421\u0438\u043d\u0445\u0440\u043e\u043d\u0438\u0437\u0430\u0446\u0438\u044f<\/summary>\n<div class=\"spoiler__content\">\n<p>\u041f\u0440\u043e\u0441\u0442\u043e \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u043a\u043b\u044e\u0447\u0435\u0432\u043e\u0435 \u0441\u043b\u043e\u0432\u043e <em>synchronized<\/em> (\u043b\u0438\u0431\u043e <em>synchronized<\/em> \u0431\u043b\u043e\u043a). \u042d\u0442\u043e \u0433\u0430\u0440\u0430\u043d\u0442\u0438\u0440\u0443\u0435\u0442, \u0447\u0442\u043e \u0442\u043e\u043b\u044c\u043a\u043e \u043e\u0434\u0438\u043d \u043f\u043e\u0442\u043e\u043a \u0441\u043c\u043e\u0436\u0435\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u044c \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438 \u0432 \u044d\u0442\u043e\u043c \u043c\u0435\u0442\u043e\u0434\u0435.<\/p>\n<pre><code class=\"java\">private synchronized static void increment() {     Thread.sleep(1);     counter++; }<\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<h4>\u0420\u0435\u0430\u043b\u044c\u043d\u0430\u044f \u043f\u0440\u0430\u043a\u0442\u0438\u043a\u0430<\/h4>\n<p>\u0415\u0441\u043b\u0438 \u0432\u0430\u043c \u0432\u0434\u0440\u0443\u0433 \u043f\u043e\u043a\u0430\u0437\u0430\u043b\u043e\u0441\u044c, \u0447\u0442\u043e \u044d\u0442\u043e \u0431\u0430\u0437\u043e\u0432\u044b\u0435 \u0437\u043d\u0430\u043d\u0438\u044f \u0438 \u0441\u043e\u0432\u0435\u0440\u0448\u0430\u0442\u044c \u043e\u0448\u0438\u0431\u043a\u0443, \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u043d\u0443\u044e \u0432\u044b\u0448\u0435, \u0432 \u0440\u0435\u0430\u043b\u044c\u043d\u044b\u0445 \u043f\u0440\u043e\u0435\u043a\u0442\u0430\u0445 \u043d\u0438\u043a\u0442\u043e \u043d\u0435 \u0431\u0443\u0434\u0435\u0442, \u0442\u043e \u0442\u0443\u0442 \u0432\u044b&#8230; \u043f\u043e\u0447\u0442\u0438 \u0443\u0433\u0430\u0434\u0430\u043b\u0438. \u0412 DBeaver \u044f \u043d\u0430\u0448\u0451\u043b \u0442\u0440\u0438 \u043c\u0435\u0441\u0442\u0430, \u0433\u0434\u0435 \u0440\u0430\u0431\u043e\u0442\u0430 \u0432\u0435\u0434\u0451\u0442\u0441\u044f \u0441 <em>volatile<\/em> \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u043c\u0438 \u043f\u0440\u0438\u043c\u0438\u0442\u0438\u0432\u043d\u044b\u0445 \u0442\u0438\u043f\u043e\u0432. \u0418, \u043a\u0430\u043a \u044d\u0442\u043e \u0447\u0430\u0441\u0442\u043e \u0431\u044b\u0432\u0430\u0435\u0442 \u0432 \u0440\u0435\u0430\u043b\u044c\u043d\u043e\u0439 \u0436\u0438\u0437\u043d\u0438, \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u0438 \u043d\u0435 \u0442\u0430\u043a\u0438\u0435 \u043e\u0434\u043d\u043e\u0437\u043d\u0430\u0447\u043d\u044b\u0435. \u0413\u0434\u0435-\u0442\u043e \u043e\u043f\u0430\u0441\u043d\u0443\u044e \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u044e \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u0438\u0442\u044f\u043d\u0443\u0442\u044c, \u043d\u043e \u043f\u043e \u0431\u043e\u043b\u044c\u0448\u0435\u0439 \u0447\u0430\u0441\u0442\u0438 \u043d\u0438\u0447\u0435\u0433\u043e \u0441\u0442\u0440\u0430\u0448\u043d\u043e\u0433\u043e \u043f\u0440\u043e\u0438\u0437\u043e\u0439\u0442\u0438 \u043d\u0435 \u043c\u043e\u0436\u0435\u0442. \u0422\u0435\u043c \u043d\u0435 \u043c\u0435\u043d\u0435\u0435 \u0432\u043e\u0442 \u044d\u0442\u0438 \u0442\u0440\u0438 \u043c\u0435\u0441\u0442\u0430:<\/p>\n<details class=\"spoiler\">\n<summary>\u041f\u043e\u0434\u0441\u0447\u0451\u0442 \u0434\u0435\u0439\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0445 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0439<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"java\">public class MultiPageWizardDialog extends .... {     ....     private volatile int runningOperations = 0;      ....       @Override     public void run(....) {         ....         try {             runningOperations++;               \/\/ &lt;=             ModalContext.run(                runnable,                true,                monitorPart,                getShell().getDisplay()             );         } finally {             runningOperations--;               \/\/ &lt;=             ....         }     } }<\/code><\/pre>\n<p>\u041f\u0440\u0435\u0434\u0443\u043f\u0440\u0435\u0436\u0434\u0435\u043d\u0438\u044f PVS-Studio:<\/p>\n<ul>\n<li>\n<p><a href=\"https:\/\/pvs-studio.ru\/ru\/docs\/warnings\/v6074\/\">V6074<\/a> Non-atomic modification of volatile variable. Inspect &#8216;runningOperations&#8217;. MultiPageWizardDialog.java(590)<\/p>\n<\/li>\n<li>\n<p><a href=\"https:\/\/pvs-studio.ru\/ru\/docs\/warnings\/v6074\/\">V6074<\/a> Non-atomic modification of volatile variable. Inspect &#8216;runningOperations&#8217;. MultiPageWizardDialog.java(593)<\/p>\n<\/li>\n<\/ul>\n<p>\u0414\u0432\u0430 \u043f\u0440\u0435\u0434\u0443\u043f\u0440\u0435\u0436\u0434\u0435\u043d\u0438\u044f \u043f\u043e \u0446\u0435\u043d\u0435 \u043e\u0434\u043d\u043e\u0433\u043e, \u0438 \u043f\u043e \u0441\u043e\u0432\u043c\u0435\u0441\u0442\u0438\u0442\u0435\u043b\u044c\u0441\u0442\u0432\u0443 \u0435\u0434\u0438\u043d\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0435 \u043c\u0435\u0441\u0442\u043e, \u0433\u0434\u0435 \u0435\u0441\u0442\u044c \u0441\u043a\u043e\u043b\u044c\u043a\u043e-\u0442\u043e \u043e\u0441\u044f\u0437\u0430\u0435\u043c\u044b\u0439 \u0440\u0438\u0441\u043a. \u041a\u0430\u0437\u0430\u043b\u043e\u0441\u044c \u0431\u044b, \u0438\u043c\u0435\u0435\u043c \u043f\u043e\u0447\u0442\u0438 \u0447\u0442\u043e \u044d\u0442\u0430\u043b\u043e\u043d\u043d\u044b\u0439 \u0441\u043b\u0443\u0447\u0430\u0439 \u0438\u0434\u0435\u043d\u0442\u0438\u0447\u043d\u044b\u0439 \u0442\u043e\u043c\u0443, \u0447\u0442\u043e \u0431\u044b\u043b \u0432 \u0438\u0441\u043a\u0443\u0441\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u0432\u044b\u0448\u0435. \u0418 \u0432\u0441\u0451 \u0436\u0435, \u0435\u0441\u043b\u0438 \u043f\u0440\u0438\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c\u0441\u044f \u043a \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u044e \u043a\u043b\u0430\u0441\u0441\u0430 \u0438 \u043c\u0435\u0442\u043e\u0434\u0430, \u0433\u0434\u0435 \u0432\u0441\u0451 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 (<em>MultiPageWizardDialog<\/em> \u0438 <em>run<\/em> \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e), \u0442\u043e \u0441\u0442\u0430\u043d\u0435\u0442 \u043f\u043e\u043d\u044f\u0442\u043d\u043e, \u0447\u0442\u043e \u043c\u044b \u0438\u043c\u0435\u0435\u043c \u0434\u0435\u043b\u043e \u0441 UI, \u0438 \u043d\u0430\u0441\u0442\u043e\u044f\u0449\u0435\u0435 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u0433\u043e\u043d\u043a\u0438 \u0437\u0434\u0435\u0441\u044c \u0435\u0441\u043b\u0438 \u0438 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e \u0432\u043e\u043e\u0431\u0449\u0435, \u0442\u043e \u043e\u0447\u0435\u043d\u044c \u043c\u0430\u043b\u043e\u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e.<\/p>\n<p>\u0425\u043e\u0442\u044f \u0435\u0441\u043b\u0438 \u0432\u0441\u0451 \u0436\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u0438\u0442\u044c, \u0447\u0442\u043e \u043c\u0435\u0442\u043e\u0434 <em>run<\/em> \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u043b\u0438 \u0431\u044b \u043e\u0434\u043d\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e \u0438\u0437 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u0445 \u043f\u043e\u0442\u043e\u043a\u043e\u0432, \u0442\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 <em>runningOperations<\/em> \u0437\u0430\u043f\u0440\u043e\u0441\u0442\u043e \u043c\u043e\u0433\u043b\u043e \u0431\u044b \u043e\u043a\u0430\u0437\u0430\u0442\u044c\u0441\u044f \u043d\u0435\u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u044b\u043c.<\/p>\n<\/div>\n<\/details>\n<details class=\"spoiler\">\n<summary>\u041e\u0442\u0440\u0438\u0441\u043e\u0432\u043a\u0430 \u043f\u0440\u043e\u0433\u0440\u0435\u0441\u0441\u0430<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"java\">private volatile int drawCount = 0;  ....  private void showProgress() {     if (loadStartTime == 0) {         return;     }     if (progressOverlay == null) {         ....         painListener = e -> {             ....             Image image = DBeaverIcons.getImage(                 PROGRESS_IMAGES[drawCount % PROGRESS_IMAGES.length]             );             ....         };         ....     }     drawCount++;     .... }<\/code><\/pre>\n<p>\u041f\u0440\u0435\u0434\u0443\u043f\u0440\u0435\u0436\u0434\u0435\u043d\u0438\u0435 PVS-Studio:<\/p>\n<p><a href=\"https:\/\/pvs-studio.ru\/ru\/docs\/warnings\/v6074\/\">V6074<\/a> Non-atomic modification of volatile variable. Inspect &#8216;drawCount&#8217;. ProgressLoaderVisualizer.java(192)<\/p>\n<p>\u0421 \u0432\u0438\u0434\u0443 \u0441\u0430\u043c\u043e\u0435 \u043d\u0435\u043a\u0440\u0438\u0442\u0438\u0447\u043d\u043e\u0435 \u043c\u0435\u0441\u0442\u043e. <em>drawCount<\/em> \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u043a\u0430\u043a \u0441\u0435\u043b\u0435\u043a\u0442\u043e\u0440 \u043a\u0430\u0440\u0442\u0438\u043d\u043a\u0438 \u043f\u0440\u043e\u0433\u0440\u0435\u0441\u0441\u0430, \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0438\u0432\u0430\u044f \u0446\u0438\u043a\u043b\u0438\u0447\u0435\u0441\u043a\u0443\u044e \u043f\u0440\u043e\u043a\u0440\u0443\u0442\u043a\u0443 \u0438\u043d\u0434\u0435\u043a\u0441\u0430. \u0412\u043e-\u043f\u0435\u0440\u0432\u044b\u0445, \u043a\u0430\u0436\u0435\u0442\u0441\u044f, \u0447\u0442\u043e \u0446\u0435\u043d\u0430 \u043e\u0448\u0438\u0431\u043a\u0438 \u0432 \u0442\u0430\u043a\u043e\u043c \u043c\u0435\u0441\u0442\u0435 \u043d\u0435 \u0441\u0430\u043c\u0430\u044f \u0432\u044b\u0441\u043e\u043a\u0430\u044f. \u0412\u043e-\u0432\u0442\u043e\u0440\u044b\u0445, \u0441\u0430\u043c \u0444\u0430\u043a\u0442 \u0434\u043e\u0441\u0442\u0443\u043f\u0430 \u043a \u043e\u0442\u0440\u0438\u0441\u043e\u0432\u043a\u0435 \u0438\u0437 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u0445 <strong>\u043f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u044c\u043d\u044b\u0445<\/strong> \u043f\u043e\u0442\u043e\u043a\u043e\u0432 \u0437\u0432\u0443\u0447\u0438\u0442 \u0441\u043e\u043c\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u043e. \u0415\u0441\u043b\u0438 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u0435 \u043f\u0440\u0435\u0434\u043f\u043e\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u0432\u0435\u0440\u043d\u043e, \u0442\u043e \u043c\u043e\u0434\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440 <em>volatile<\/em> \u0437\u0434\u0435\u0441\u044c \u043d\u0435 \u043d\u0443\u0436\u0435\u043d.<\/p>\n<\/div>\n<\/details>\n<details class=\"spoiler\">\n<summary>\u041e\u0442\u0441\u043b\u0435\u0436\u0438\u0432\u0430\u043d\u0438\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0430 \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0439<\/summary>\n<div class=\"spoiler__content\">\n<p>\u0410\u043d\u0430\u043b\u0438\u0437\u0430\u0442\u043e\u0440 \u0432\u044b\u0434\u0430\u0451\u0442 \u043f\u0440\u0435\u0434\u0443\u043f\u0440\u0435\u0436\u0434\u0435\u043d\u0438\u0435 \u043d\u0430 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u043a\u043e\u0434:<\/p>\n<pre><code class=\"java\">private volatile int initializedCount = 0;  .... public CompareObjectsExecutor(CompareObjectsSettings settings) {     ....     initializeFinisher = new DBRProgressListener() {         @Override         public void onTaskFinished(IStatus status)         {             if (!status.isOK()) {                 initializeError = status;             } else {                 initializedCount++;             }         }     };     .... }<\/code><\/pre>\n<p>\u041f\u0440\u0435\u0434\u0443\u043f\u0440\u0435\u0436\u0434\u0435\u043d\u0438\u0435 PVS-Studio<\/p>\n<p><a href=\"https:\/\/pvs-studio.ru\/ru\/docs\/warnings\/v6074\/\">V6074<\/a> Non-atomic modification of volatile variable. Inspect &#8216;initializedCount&#8217;. CompareObjectsExecutor.java(130)<\/p>\n<p>\u0418 \u044d\u0442\u043e \u043c\u0435\u0441\u0442\u043e \u0431\u043e\u043b\u044c\u0448\u0435 \u0434\u0440\u0443\u0433\u0438\u0445 \u043f\u043e\u0445\u043e\u0436\u0435 \u043d\u0430 \u043e\u043f\u0430\u0441\u043d\u043e\u0435. \u041d\u043e \u043f\u043e\u043a\u0430 \u043d\u0430\u043c \u043d\u0435 \u0445\u0432\u0430\u0442\u0430\u0435\u0442 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0430, \u043d\u0430\u0434\u043e \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u043d\u0430 \u043c\u0435\u0441\u0442\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f <em>initializeFinisher<\/em> \u0438 <em>initializecCount<\/em>:<\/p>\n<pre><code class=\"java\">this.initializedCount = 0;  for (DBNDatabaseNode node : nodes) {     node.initializeNode(null, initializeFinisher);     .... } while (initializedCount != nodes.size()) {     Thread.sleep(50);     if (monitor.isCanceled()) {         throw new InterruptedException();     }     .... }<\/code><\/pre>\n<p>\u0418\u0442\u043e\u0433\u043e:<\/p>\n<ol>\n<li>\n<p>\u0421\u0447\u0451\u0442\u0447\u0438\u043a \u043e\u0431\u043d\u0443\u043b\u044f\u0435\u0442\u0441\u044f;<\/p>\n<\/li>\n<li>\n<p>\u0415\u0433\u043e \u0443\u0432\u0435\u043b\u0438\u0447\u0435\u043d\u0438\u0435 \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u0442\u0441\u044f \u0432 <em>node.initializeNode<\/em>;<\/p>\n<\/li>\n<li>\n<p>\u0414\u0430\u043b\u0435\u0435 \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u0442\u0441\u044f, \u0432\u0441\u0435 \u043b\u0438 \u0443\u0437\u043b\u044b \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u044b. \u0412 \u043f\u0440\u043e\u0442\u0438\u0432\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043f\u043e\u0442\u043e\u043a \u0437\u0430\u0441\u044b\u043f\u0430\u0435\u0442 \u043d\u0430 50 \u043c\u0438\u043b\u043b\u0438\u0441\u0435\u043a\u0443\u043d\u0434.<\/p>\n<\/li>\n<\/ol>\n<p>\u041a\u0430\u0437\u0430\u043b\u043e\u0441\u044c \u0431\u044b, \u044d\u0442\u0430\u043b\u043e\u043d\u043d\u044b\u0439 \u0441\u043b\u0443\u0447\u0430\u0439: \u0435\u0441\u043b\u0438 \u0434\u0432\u0430 \u043f\u043e\u0442\u043e\u043a\u0430 \u043e\u0434\u043d\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e \u0438\u043d\u043a\u0440\u0435\u043c\u0435\u043d\u0442\u0438\u0440\u0443\u044e\u0442 \u0441\u0447\u0451\u0442\u0447\u0438\u043a, \u0442\u043e \u0432\u0441\u044f \u043b\u043e\u0433\u0438\u043a\u0430 \u0441\u043b\u043e\u043c\u0430\u0435\u0442\u0441\u044f. \u0422\u0430\u043a \u0432\u0435\u0434\u044c? \u041d\u0435\u0442, \u0432 <em>node.initializeNode<\/em> \u043d\u0435\u0442 \u043d\u0438\u043a\u0430\u043a\u0438\u0445 \u043f\u043e\u0442\u043e\u043a\u043e\u0432. \u0422\u0430\u043c \u0432\u043e\u043e\u0431\u0449\u0435 \u043d\u0438\u0447\u0435\u0433\u043e \u043d\u0435\u0442 \ud83d\ude42<\/p>\n<pre><code class=\"java\">public boolean initializeNode(     DBRProgressMonitor monitor,     DBRProgressListener onFinish ) throws DBException {     if (onFinish != null) {         onFinish.onTaskFinished(Status.OK_STATUS);     }     return true; }<\/code><\/pre>\n<p>\u0412 \u043e\u0431\u0449\u0435\u043c, \u043d\u0435\u0441\u043c\u043e\u0442\u0440\u044f \u043d\u0430 \u0442\u043e \u0447\u0442\u043e <em>DBRProgressListener<\/em> \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0432 \u043f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u044c\u043d\u044b\u0445 \u0441\u0446\u0435\u043d\u0430\u0440\u0438\u044f\u0445, \u044d\u0442\u043e \u043d\u0435 \u0442\u043e\u0442 \u0441\u043b\u0443\u0447\u0430\u0439, \u0438 <em>volatile<\/em> \u0434\u043b\u044f <em>initializedCount<\/em> \u043a\u0430\u0436\u0435\u0442\u0441\u044f \u043f\u043e\u043f\u0440\u043e\u0441\u0442\u0443 \u0438\u0437\u0431\u044b\u0442\u043e\u0447\u043d\u044b\u043c, \u043a\u0430\u043a \u0438 \u0446\u0438\u043a\u043b \u0441 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u043e\u0439 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0430 \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0439.<\/p>\n<\/div>\n<\/details>\n<h4>\u0412\u043d\u0435\u0437\u0430\u043f\u043d\u044b\u0439 \u043f\u043e\u0432\u043e\u0440\u043e\u0442<\/h4>\n<p>\u0414\u043e \u044d\u0442\u043e\u0433\u043e \u043c\u044b \u0441\u043c\u043e\u0442\u0440\u0435\u043b\u0438 \u043d\u0430 \u043f\u0440\u043e\u0441\u0442\u044b\u0435 \u043f\u0440\u0438\u043c\u0435\u0440\u044b \u0441 \u043f\u0440\u0438\u043c\u0438\u0442\u0438\u0432\u043d\u044b\u043c\u0438 \u0442\u0438\u043f\u0430\u043c\u0438. \u0410 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u043b\u0438 \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u043f\u043e\u043b\u0435 \u0441\u0441\u044b\u043b\u043e\u0447\u043d\u043e\u0433\u043e \u0442\u0438\u043f\u0430 volatile, \u0447\u0442\u043e\u0431\u044b \u0433\u0430\u0440\u0430\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0430\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u0443\u044e \u0440\u0430\u0431\u043e\u0442\u0443? \u041e\u0442\u043d\u044e\u0434\u044c. \u041f\u043e\u0434\u0440\u043e\u0431\u043d\u0435\u0435 \u043c\u043e\u0436\u043d\u043e \u0443\u0437\u043d\u0430\u0442\u044c <a href=\"https:\/\/wiki.sei.cmu.edu\/confluence\/display\/java\/CON50-J.+Do+not+assume+that+declaring+a+reference+volatile+guarantees+safe+publication+of+the+members+of+the+referenced+object\">\u0437\u0434\u0435\u0441\u044c<\/a>. \u041d\u0435\u043c\u043d\u043e\u0433\u043e \u043c\u043e\u0434\u0438\u0444\u0438\u0446\u0438\u0440\u043e\u0432\u0430\u0432 \u043f\u0440\u043e\u0448\u043b\u044b\u0439 \u043f\u0440\u0438\u043c\u0435\u0440, \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u043b\u0435\u0433\u043a\u043e \u0434\u043e\u0431\u0438\u0442\u044c\u0441\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u0443 \u043d\u0430\u0441 \u0441\u043d\u043e\u0432\u0430 \u0432\u043e\u0437\u043d\u0438\u043a \u0431\u0435\u0441\u043a\u043e\u043d\u0435\u0447\u043d\u044b\u0439 \u0446\u0438\u043a\u043b:<\/p>\n<pre><code class=\"java\">private static class Proxy {     public String str; } private static volatile Proxy proxy = new Proxy(); public static void main() throws InterruptedException {     var proxy = Main.proxy;      new Thread(() -> {         while (proxy.str == null) { }         System.out.println(proxy.str);     }).start();      Thread.sleep(1);      proxy.str = \"Hello World!\"; }<\/code><\/pre>\n<p>\u041e\u0434\u043d\u043e \u0438\u0437 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u044b\u0445 \u0438\u0441\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u0439 \u2014 \u043e\u0442\u043c\u0435\u0442\u0438\u0442\u044c \u043f\u043e\u043b\u0435 <em>str<\/em> \u043a\u0430\u043a volatile, \u0438 \u0442\u043e\u0433\u0434\u0430 \u0432\u0441\u0451 \u0437\u0430\u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u043a\u0430\u043a \u043f\u0440\u0435\u0436\u0434\u0435. \u0427\u0442\u043e \u0436\u0435 \u0434\u043e \u0441\u0430\u043c\u043e\u0433\u043e \u043f\u043e\u043b\u044f <em>proxy<\/em>, \u0442\u043e \u0432 \u044d\u0442\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043a\u0430\u043a-\u043b\u0438\u0431\u043e \u043e\u0442\u043c\u0435\u0447\u0430\u0442\u044c \u0435\u0433\u043e \u0441\u043c\u044b\u0441\u043b\u0430 \u043d\u0435\u0442.<\/p>\n<details class=\"spoiler\">\n<summary>\u0418\u0441\u043f\u0440\u0430\u0432<\/summary>\n<\/details>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-378078","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/378078","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=378078"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/378078\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=378078"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=378078"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=378078"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}