{"id":10352,"date":"2020-10-03T04:14:31","date_gmt":"2020-10-02T19:14:31","guid":{"rendered":"http:\/\/www.gisdeveloper.co.kr\/?p=10352"},"modified":"2020-10-05T07:10:34","modified_gmt":"2020-10-04T22:10:34","slug":"safe-termination-%ed%8c%a8%ed%84%b4","status":"publish","type":"post","link":"http:\/\/www.gisdeveloper.co.kr\/?p=10352","title":{"rendered":"Safe Termination \ud328\ud134"},"content":{"rendered":"<h4>\ud328\ud134 \uba85\uce6d<\/h4>\n<p>Safe Termination<\/p>\n<h4>\ud544\uc694\ud55c \uc0c1\ud669<\/h4>\n<p>\uc2a4\ub808\ub4dc\uc758 \uc885\ub8cc\ub97c \uc548\uc804\ud558\uac8c \ud558\uae30 \uc704\ud55c \ud328\ud134\uc774\ub2e4. \uc2a4\ub808\ub4dc\ub294 \uae30\ubcf8\uc801\uc73c\ub85c stop \ub9e4\uc11c\ub4dc\ub97c \uc81c\uacf5\ud558\uc9c0\ub9cc, \uc774 \ub9e4\uc11c\ub4dc\ub294 \uc548\uc815\uc131 \ubb38\uc81c\ub85c deprecated \ub418\uc5c8\ub2e4. \uc2a4\ub808\ub4dc\ub294 \uc790\uc2e0\uc758 \ucf54\ub4dc\uac00 \ubaa8\ub450 \uc2e4\ud589\ub418\uace0 \uc885\ub8cc\ub418\ub294 \uac83\uc774 \uac00\uc7a5 \uc774\uc0c1\uc801\uc774\uc9c0\ub9cc, \uc2e4\ud589 \uc911\uac04\uc5d0 \uc885\ub8cc\ub418\uc5b4\uc57c \ud560 \uc0c1\ud669\uc5d0\uc11c \uc548\uc804\ud558\uac8c \uc885\ub8cc\ub420 \uc218\ub3c4 \uc788\uc5b4\uc57c \ud55c\ub2e4.<\/p>\n<h4>\uc608\uc81c \ucf54\ub4dc<\/h4>\n<p>\uba3c\uc800 \uc218\ub97c \uacc4\uc18d \uce74\uc6b4\ud305\ud558\ub294 \uc2a4\ub808\ub4dc Worker\ub97c \uae30\ub3d9\uc2dc\ud0a4\ub294 \uc544\ub798\uc758 \ucf54\ub4dc\uac00 \uc788\ub2e4.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"java\">\r\npackage tstThread;\r\n\r\npublic class Main {\r\n\tpublic static void main(String[] args) {\r\n\t\tSystem.out.println(\"BEGIN\");\r\n\t\t\r\n\t\tWorker worker = new Worker();\r\n\t\tworker.start();\r\n\t\t\r\n\t\ttry {\r\n\t\t\tThread.sleep(2000);\r\n\t\t\t\r\n\t\t\tSystem.out.println(\"[stopRequest BEGIN]\");\r\n\t\t\tworker.stopRequest();\r\n\t\t\tSystem.out.println(\"[stopRequest END]\");\r\n\t\t\tworker.join();\r\n\t\t} catch(InterruptedException e) {\r\n\t\t\t\/\/.\r\n\t\t}\r\n\t\t\r\n\t\tSystem.out.println(\"END\");\r\n\t}\r\n}\r\n<\/pre>\n<p>Worker \uc2a4\ub808\ub4dc\ub294 \ub2e4\uc74c\uacfc \uac19\ub2e4.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"java\">\r\npackage tstThread;\r\n\r\npublic class Worker extends Thread {\r\n\tprivate volatile boolean bStop = false;\r\n\t\r\n\tpublic void stopRequest() {\r\n\t\tbStop = true;\r\n\t\tinterrupt();\r\n\t}\r\n\t\r\n\tpublic void run() {\r\n\t\ttry {\r\n\t\t\tfor(int i=0; true; i++) {\r\n\t\t\t\tif(bStop) break;\r\n\t\t\t\tSystem.out.println(\"Counting: \" + i);\r\n\t\t\t\tThread.sleep(100);\r\n\t\t\t}\r\n\t\t} catch(InterruptedException e) {\r\n\t\t\t\/\/.\r\n\t\t} finally {\r\n\t\t\trelease();\r\n\t\t}\r\n\t}\r\n\t\r\n\tprivate void release() {\r\n\t\tSystem.out.println(\"SAFE TERMINATION\");\r\n\t}\r\n}\r\n<\/pre>\n<p>bStop \ubcc0\uc218\uac00 \uc2a4\ub808\ub4dc\ub97c \uc548\uc804\ud558\uac8c \uc885\ub8cc\uc2dc\ud0a4\ub294 \uc7a5\uce58\uc778\ub370, volatile\ub85c \uc120\uc5b8\ub418\uc5c8\ub2e4. \uc774 \ubcc0\uc218\ub294 stopRequest \ub9e4\uc11c\ub4dc\ub85c \uc778\ud574 true\ub85c \uc124\uc815\ub418\uba70, interrupt \ub9e4\uc11c\ub4dc\uc758 \ud638\ucd9c\uc744 \ub3d9\ubc18\ud55c\ub2e4. interrupt \ub9e4\uc11c\ub4dc\uc758 \ud638\ucd9c\uc740 wait, sleep\ub85c \uc778\ud574 \uc2a4\ub808\ub4dc\uac00 \ub300\uae30\ud558\ub294 \uc0c1\ud669\uc5d0\uc11c\ub3c4 \uc548\uc804\ud558\uac8c \uc2a4\ub808\ub4dc\ub97c \uc885\ub8cc\uc2dc\ud0a4\uae30 \uc704\ud568\uc774\ub2e4. \uc2e4\ud589 \uacb0\uacfc\ub294 \ub2e4\uc74c\uacfc \uac19\ub2e4.<\/p>\n<pre class='code'>\r\nBEGIN\r\nCounting: 0\r\nCounting: 1\r\nCounting: 2\r\nCounting: 3\r\nCounting: 4\r\nCounting: 5\r\nCounting: 6\r\nCounting: 7\r\nCounting: 8\r\nCounting: 9\r\nCounting: 10\r\nCounting: 11\r\nCounting: 12\r\nCounting: 13\r\nCounting: 14\r\nCounting: 15\r\nCounting: 16\r\nCounting: 17\r\nCounting: 18\r\nCounting: 19\r\n[stopRequest BEGIN]\r\n[stopRequest END]\r\nSAFE TERMINATION\r\nEND\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\ud328\ud134 \uba85\uce6d Safe Termination \ud544\uc694\ud55c \uc0c1\ud669 \uc2a4\ub808\ub4dc\uc758 \uc885\ub8cc\ub97c \uc548\uc804\ud558\uac8c \ud558\uae30 \uc704\ud55c \ud328\ud134\uc774\ub2e4. \uc2a4\ub808\ub4dc\ub294 \uae30\ubcf8\uc801\uc73c\ub85c stop \ub9e4\uc11c\ub4dc\ub97c \uc81c\uacf5\ud558\uc9c0\ub9cc, \uc774 \ub9e4\uc11c\ub4dc\ub294 \uc548\uc815\uc131 \ubb38\uc81c\ub85c deprecated \ub418\uc5c8\ub2e4. \uc2a4\ub808\ub4dc\ub294 \uc790\uc2e0\uc758 \ucf54\ub4dc\uac00 \ubaa8\ub450 \uc2e4\ud589\ub418\uace0 \uc885\ub8cc\ub418\ub294 \uac83\uc774 \uac00\uc7a5 \uc774\uc0c1\uc801\uc774\uc9c0\ub9cc, \uc2e4\ud589 \uc911\uac04\uc5d0 \uc885\ub8cc\ub418\uc5b4\uc57c \ud560 \uc0c1\ud669\uc5d0\uc11c \uc548\uc804\ud558\uac8c \uc885\ub8cc\ub420 \uc218\ub3c4 \uc788\uc5b4\uc57c \ud55c\ub2e4. \uc608\uc81c \ucf54\ub4dc \uba3c\uc800 \uc218\ub97c \uacc4\uc18d \uce74\uc6b4\ud305\ud558\ub294 \uc2a4\ub808\ub4dc Worker\ub97c \uae30\ub3d9\uc2dc\ud0a4\ub294 \uc544\ub798\uc758 \ucf54\ub4dc\uac00 \uc788\ub2e4. package &hellip; <\/p>\n<p class=\"link-more\"><a href=\"http:\/\/www.gisdeveloper.co.kr\/?p=10352\" class=\"more-link\">\ub354 \ubcf4\uae30<span class=\"screen-reader-text\"> &#8220;Safe Termination \ud328\ud134&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[13,1],"tags":[],"class_list":["post-10352","post","type-post","status-publish","format-standard","hentry","category-design","category-uncategorized"],"_links":{"self":[{"href":"http:\/\/www.gisdeveloper.co.kr\/index.php?rest_route=\/wp\/v2\/posts\/10352","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.gisdeveloper.co.kr\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.gisdeveloper.co.kr\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.gisdeveloper.co.kr\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.gisdeveloper.co.kr\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=10352"}],"version-history":[{"count":3,"href":"http:\/\/www.gisdeveloper.co.kr\/index.php?rest_route=\/wp\/v2\/posts\/10352\/revisions"}],"predecessor-version":[{"id":10355,"href":"http:\/\/www.gisdeveloper.co.kr\/index.php?rest_route=\/wp\/v2\/posts\/10352\/revisions\/10355"}],"wp:attachment":[{"href":"http:\/\/www.gisdeveloper.co.kr\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=10352"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.gisdeveloper.co.kr\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=10352"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.gisdeveloper.co.kr\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=10352"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}