{"id":4498,"date":"2014-03-30T12:05:20","date_gmt":"2014-03-30T12:05:20","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/03\/30\/if-main-method-completes-the-execution-what-happens-to-any-long-running-thread-collection-of-common-programming-errors\/"},"modified":"2014-03-30T12:05:20","modified_gmt":"2014-03-30T12:05:20","slug":"if-main-method-completes-the-execution-what-happens-to-any-long-running-thread-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2014\/03\/30\/if-main-method-completes-the-execution-what-happens-to-any-long-running-thread-collection-of-common-programming-errors\/","title":{"rendered":"if main method completes the execution, what happens to any long running thread?-Collection of common programming errors"},"content":{"rendered":"<p>The process will terminate when there are no more non-daemon threads, killing any daemon threads if necessary. However, if you <em>do<\/em> have any non-daemon threads, those will prevent the process from terminating.<\/p>\n<p>From <code>Thread.setDaemon<\/code>:<\/p>\n<blockquote>\n<p>Marks this thread as either a daemon thread or a user thread. The Java Virtual Machine exits when the only threads running are all daemon threads.<\/p>\n<p>This method must be invoked before the thread is started.<\/p>\n<\/blockquote>\n<p>And from section 12.8 of the JLS:<\/p>\n<blockquote>\n<p>A program terminates all its activity and exits when one of two things happens:<\/p>\n<ul>\n<li>\n<p>All the threads that are not daemon threads terminate.<\/p>\n<\/li>\n<li>\n<p>Some thread invokes the exit method of class Runtime or class System, and the exit operation is not forbidden by the security manager.<\/p>\n<\/li>\n<\/ul>\n<\/blockquote>\n","protected":false},"excerpt":{"rendered":"<p>The process will terminate when there are no more non-daemon threads, killing any daemon threads if necessary. However, if you do have any non-daemon threads, those will prevent the process from terminating. From Thread.setDaemon: Marks this thread as either a daemon thread or a user thread. The Java Virtual Machine exits when the only threads [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-4498","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/4498","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=4498"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/4498\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=4498"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=4498"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=4498"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}