{"id":5219,"date":"2014-03-30T19:50:40","date_gmt":"2014-03-30T19:50:40","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/03\/30\/java-killing-process-after-a-period-of-time-collection-of-common-programming-errors\/"},"modified":"2014-03-30T19:50:40","modified_gmt":"2014-03-30T19:50:40","slug":"java-killing-process-after-a-period-of-time-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2014\/03\/30\/java-killing-process-after-a-period-of-time-collection-of-common-programming-errors\/","title":{"rendered":"java killing process after a period of time-Collection of common programming errors"},"content":{"rendered":"<p>It will be a little tricky because once you terminate the process, its output is no longer available, so you have to grab the output before you kill it.<\/p>\n<pre><code>Thread.sleep(1000); \nInputStream in = proc.getInputStream();\nbyte[] data = new byte[in.available()];\nin.read(data);\nproc.destroy();\n<\/code><\/pre>\n<p>This is assuming that the process doesn&#8217;t close itself in the meantime. If it does, the InputStream will not be available for use, and you&#8217;ll wish you had been reading the data instead of twiddling your thumbs.<\/p>\n<p>You&#8217;ll definitely want to make this exception-safe &#8211; put the call to <code>proc.destroy<\/code> in a finally handler to ensure that the child process gets terminated.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>It will be a little tricky because once you terminate the process, its output is no longer available, so you have to grab the output before you kill it. Thread.sleep(1000); InputStream in = proc.getInputStream(); byte[] data = new byte[in.available()]; in.read(data); proc.destroy(); This is assuming that the process doesn&#8217;t close itself in the meantime. If it [&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-5219","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/5219","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=5219"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/5219\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=5219"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=5219"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=5219"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}