{"id":169619,"date":"2013-02-15T23:53:03","date_gmt":"2013-02-15T19:53:03","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=169619"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=169619","title":{"rendered":"<span class=\"post_title\">\u041f\u044f\u0442\u043d\u0438\u0447\u043d\u0430\u044f \u0438\u0441\u0442\u043e\u0440\u0438\u044f \u043f\u0440\u043e synchonized-\u043c\u0435\u0442\u043e\u0434\u044b \u0432 \u043a\u043b\u0430\u0441\u0441\u0435 Thread<\/span>"},"content":{"rendered":"<div class=\"content html_format\">   \t\u041d\u0435\u0434\u0430\u0432\u043d\u043e \u044f \u043d\u0430\u0442\u043a\u043d\u0443\u043b\u0441\u044f \u043d\u0430 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u0443\u044e \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e\u0441\u0442\u044c \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u0438\u0437\u0430\u0446\u0438\u0438 \u043d\u0430 \u043a\u043b\u0430\u0441\u0441\u0435 Thread. \u042f \u0441\u043e\u0437\u0434\u0430\u043b \u043a\u043b\u0430\u0441\u0441, \u043d\u0430\u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 Thread \u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b \u0432 \u043d\u0435\u043c \u043f\u0430\u0442\u0442\u0435\u0440\u043d lock object \u0434\u043b\u044f \u0432\u043d\u0443\u0442\u0440\u0435\u043d\u043d\u0435\u0439 \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u0438\u0437\u0430\u0446\u0438\u0438. \u0412 \u043a\u0430\u043a\u043e\u0439-\u0442\u043e \u043c\u043e\u043c\u0435\u043d\u0442 \u043c\u043d\u0435 \u043f\u043e\u043a\u0430\u0437\u0430\u043b\u043e\u0441\u044c \u0447\u0442\u043e lock object \u0440\u0430\u0437\u0434\u0443\u0432\u0430\u0435\u0442 \u043a\u043e\u0434, \u0430 \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u0441\u043e\u0437\u0434\u0430\u043d\u043d\u044b\u0439 \u043f\u043e\u0442\u043e\u043a \u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e \u0438\u0437 \u043e\u0447\u0435\u043d\u044c \u043c\u0430\u043b\u043e\u0433\u043e \u0447\u0438\u0441\u043b\u0430 \u043c\u0435\u0441\u0442, \u044f \u0435\u0433\u043e \u0432\u044b\u043a\u0438\u043d\u0443\u043b, \u0437\u0430\u043c\u0435\u043d\u0438\u0432 \u043d\u0430 synchronized \u043c\u0435\u0442\u043e\u0434\u044b \u0438 wait\/notify \u043d\u0430 this. \u0415\u0441\u043b\u0438 \u0445\u043e\u0442\u0438\u0442\u0435 \u0437\u043d\u0430\u0442\u044c, \u0447\u0442\u043e \u0438\u0437 \u044d\u0442\u043e\u0433\u043e \u043c\u0430\u043b\u0435\u043d\u044c\u043a\u043e\u0433\u043e \u043d\u0430\u0440\u0443\u0448\u0435\u043d\u0438\u044f \u00ab\u043a\u043e\u0434\u0435\u043a\u0441\u0430\u00bb \u0432\u044b\u0448\u043b\u043e \u2014 \u0434\u043e\u0431\u0440\u043e \u043f\u043e\u0436\u0430\u043b\u043e\u0432\u0430\u0442\u044c \u043f\u043e\u0434 \u043a\u0430\u0442.<br \/>  <a name=\"habracut\"><\/a><br \/>  \u0412-\u043e\u0431\u0449\u0435\u043c \u043d\u0438\u0447\u0435\u0433\u043e \u0445\u043e\u0440\u043e\u0448\u0435\u0433\u043e \u043d\u0435 \u0432\u044b\u0448\u043b\u043e. \u041f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0430 \u0440\u0430\u0431\u043e\u0442\u0430\u043b\u0430 \u043d\u043e\u0440\u043c\u0430\u043b\u044c\u043d\u043e \u043f\u043e\u0447\u0442\u0438 \u0432\u0441\u0435\u0433\u0434\u0430, \u043d\u043e \u043d\u0430 CI \u043f\u0435\u0440\u0438\u043e\u0434\u0438\u0447\u0435\u0441\u043a\u0438 \u043d\u0430\u0447\u0430\u043b\u0430 \u0432\u0435\u0441\u0442\u0438 \u0441\u0435\u0431\u044f \u043d\u0435\u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u043e.<br \/>  \u0411\u0435\u0433\u043b\u044b\u0439 \u043f\u0440\u043e\u0441\u043c\u043e\u0442\u0440 \u043a\u043b\u0430\u0441\u0441\u0430 Thread \u043f\u043e\u043a\u0430\u0437\u0430\u043b, \u0447\u0442\u043e \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c java synchronization \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0432 \u0441\u0430\u043c\u043e\u043c \u043a\u043b\u0430\u0441\u0441\u0435 Thread, \u0430 \u0438\u043c\u0435\u043d\u043d\u043e \u0432 \u043c\u0435\u0442\u043e\u0434\u0435 join:  <\/p>\n<pre><code class=\"java\">    public final synchronized void join(long millis)      throws InterruptedException { \tlong base = System.currentTimeMillis(); \tlong now = 0;  \tif (millis &lt; 0) {             throw new IllegalArgumentException(&quot;timeout value is negative&quot;); \t}  \tif (millis == 0) { \t    while (isAlive()) { \t\twait(0); \t    } \t} else { \t    while (isAlive()) { \t\tlong delay = millis - now; \t\tif (delay &lt;= 0) { \t\t    break; \t\t} \t\twait(delay); \t\tnow = System.currentTimeMillis() - base; \t    } \t}     }  <\/code><\/pre>\n<p>  \u0421\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u0441\u0430\u043c notify() \u0432 \u043a\u043b\u0430\u0441\u0441\u0435 Thread \u043d\u0435 \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f, \u0430 \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0432 cpp-\u0448\u043d\u043e\u043c \u043a\u043e\u0434\u0435 \u043f\u043e\u0441\u043b\u0435 \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u044f \u043f\u043e\u0442\u043e\u043a\u0430:  <\/p>\n<pre><code class=\"cpp\">static void ensure_join(JavaThread* thread) {   \/\/ We do not need to grap the Threads_lock, since we are operating on ourself.   Handle threadObj(thread, thread-&gt;threadObj());   assert(threadObj.not_null(), &quot;java thread object must exist&quot;);   ObjectLocker lock(threadObj, thread);   \/\/ Ignore pending exception (ThreadDeath), since we are exiting anyway   thread-&gt;clear_pending_exception();   \/\/ It is of profound importance that we set the stillborn bit and reset the thread object,   \/\/ before we do the notify. Since, changing these two variable will make JVM_IsAlive return   \/\/ false. So in case another thread is doing a join on this thread , it will detect that the thread   \/\/ is dead when it gets notified.   java_lang_Thread::set_stillborn(threadObj());   \/\/ Thread is exiting. So set thread_status field in  java.lang.Thread class to TERMINATED.   java_lang_Thread::set_thread_status(threadObj(), java_lang_Thread::TERMINATED);   java_lang_Thread::set_thread(threadObj(), NULL);   lock.notify_all(thread);    \/\/ Ignore pending exception (ThreadDeath), since we are exiting anyway   thread-&gt;clear_pending_exception(); } <\/code><\/pre>\n<p>  \u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u0441\u043e\u0437\u0434\u0430\u0435\u0442\u0441\u044f \u0434\u0432\u0435 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b \u2014 \u0434\u0435\u043b\u0430\u044f notify() \u0432\u044b, \u0435\u0441\u043b\u0438 \u043d\u0435 \u043f\u043e\u0432\u0435\u0437\u0435\u0442, \u043f\u0440\u043e\u0431\u0443\u0436\u0434\u0430\u0435\u0442\u0435 \u043f\u043e\u0442\u043e\u043a join, \u0447\u0442\u043e \u043d\u0435 \u0441\u0442\u0440\u0430\u0448\u043d\u043e, \u043d\u043e \u043d\u0435 \u043f\u0440\u043e\u0431\u0443\u0436\u0434\u0430\u0435\u0442\u0435 \u0441\u0432\u043e\u0439 \u043f\u043e\u0442\u043e\u043a, \u0447\u0442\u043e \u0441\u0442\u0440\u0430\u0448\u043d\u043e.<br \/>  \u0418 \u0432\u0442\u043e\u0440\u043e\u0435, \u043f\u043e\u0441\u043b\u0435 \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u044f \u043f\u043e\u0442\u043e\u043a\u0430, \u043d\u0430 \u043d\u0435\u043c \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f notifyAll() \u0447\u0442\u043e \u0440\u0430\u0437\u0431\u0443\u0434\u0438\u0442 \u0432\u0441\u0435 \u0432\u0430\u0448\u0438 wait(), \u0445\u043e\u0442\u044f \u0432\u044b \u043e\u0447\u0435\u0432\u0438\u0434\u043d\u043e \u044d\u0442\u043e\u0433\u043e \u043d\u0435 \u0445\u043e\u0442\u0435\u043b\u0438 \u0431\u044b. <\/p>\n<p>  \u0412-\u043e\u0431\u0449\u0435\u043c \u043c\u043e\u0440\u0430\u043b\u044c \u043f\u044f\u0442\u043d\u0438\u0447\u043d\u043e\u0439 \u0438\u0441\u0442\u043e\u0440\u0438\u0438 \u0431\u0430\u043d\u0430\u043b\u044c\u043d\u0430 \u2014 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0439\u0442\u0435 lock object, \u0435\u0441\u043b\u0438 \u0435\u0441\u0442\u044c \u0445\u043e\u0442\u044f \u0431\u044b \u043f\u043e\u0442\u0435\u043d\u0446\u0438\u0430\u043b\u044c\u043d\u0430\u044f \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0447\u0442\u043e \u043d\u0430 \u043e\u0431\u044a\u0435\u043a\u0442\u044b \u0432\u0430\u0448\u0435\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430 \u0431\u0443\u0434\u0435\u0442 \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u0438\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u043a\u0442\u043e-\u0442\u043e \u043a\u0440\u043e\u043c\u0435 \u0412\u0430\u0441. \u0410 \u0435\u0441\u043b\u0438 \u0432\u044b \u043d\u0430\u0441\u043b\u0435\u0434\u0443\u0435\u0442\u0435\u0441\u044c \u043e\u0442 \u0447\u0443\u0436\u043e\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043d\u0435 Object, \u0442\u043e \u0442\u0430\u043a\u0430\u044f \u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e\u0441\u0442\u044c \u0442\u043e\u0447\u043d\u043e \u0435\u0441\u0442\u044c.    \t \t\t   \t<\/p>\n<div class=\"clear\"><\/div>\n<\/p><\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"http:\/\/habrahabr.ru\/post\/169619\/\"> http:\/\/habrahabr.ru\/post\/169619\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div class=\"content html_format\">   \t\u041d\u0435\u0434\u0430\u0432\u043d\u043e \u044f \u043d\u0430\u0442\u043a\u043d\u0443\u043b\u0441\u044f \u043d\u0430 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u0443\u044e \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e\u0441\u0442\u044c \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u0438\u0437\u0430\u0446\u0438\u0438 \u043d\u0430 \u043a\u043b\u0430\u0441\u0441\u0435 Thread. \u042f \u0441\u043e\u0437\u0434\u0430\u043b \u043a\u043b\u0430\u0441\u0441, \u043d\u0430\u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 Thread \u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b \u0432 \u043d\u0435\u043c \u043f\u0430\u0442\u0442\u0435\u0440\u043d lock object \u0434\u043b\u044f \u0432\u043d\u0443\u0442\u0440\u0435\u043d\u043d\u0435\u0439 \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u0438\u0437\u0430\u0446\u0438\u0438. \u0412 \u043a\u0430\u043a\u043e\u0439-\u0442\u043e \u043c\u043e\u043c\u0435\u043d\u0442 \u043c\u043d\u0435 \u043f\u043e\u043a\u0430\u0437\u0430\u043b\u043e\u0441\u044c \u0447\u0442\u043e lock object \u0440\u0430\u0437\u0434\u0443\u0432\u0430\u0435\u0442 \u043a\u043e\u0434, \u0430 \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u0441\u043e\u0437\u0434\u0430\u043d\u043d\u044b\u0439 \u043f\u043e\u0442\u043e\u043a \u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e \u0438\u0437 \u043e\u0447\u0435\u043d\u044c \u043c\u0430\u043b\u043e\u0433\u043e \u0447\u0438\u0441\u043b\u0430 \u043c\u0435\u0441\u0442, \u044f \u0435\u0433\u043e \u0432\u044b\u043a\u0438\u043d\u0443\u043b, \u0437\u0430\u043c\u0435\u043d\u0438\u0432 \u043d\u0430 synchronized \u043c\u0435\u0442\u043e\u0434\u044b \u0438 wait\/notify \u043d\u0430 this. \u0415\u0441\u043b\u0438 \u0445\u043e\u0442\u0438\u0442\u0435 \u0437\u043d\u0430\u0442\u044c, \u0447\u0442\u043e \u0438\u0437 \u044d\u0442\u043e\u0433\u043e \u043c\u0430\u043b\u0435\u043d\u044c\u043a\u043e\u0433\u043e \u043d\u0430\u0440\u0443\u0448\u0435\u043d\u0438\u044f \u00ab\u043a\u043e\u0434\u0435\u043a\u0441\u0430\u00bb \u0432\u044b\u0448\u043b\u043e \u2014 \u0434\u043e\u0431\u0440\u043e \u043f\u043e\u0436\u0430\u043b\u043e\u0432\u0430\u0442\u044c \u043f\u043e\u0434 \u043a\u0430\u0442.  <\/p>\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-169619","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/169619","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=169619"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/169619\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=169619"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=169619"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=169619"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}