<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Java Daemon</title>
	<atom:link href="http://barelyenough.org/blog/2005/03/java-daemon/feed/" rel="self" type="application/rss+xml" />
	<link>http://barelyenough.org/blog/2005/03/java-daemon/</link>
	<description>… and there is much to be learned</description>
	<lastBuildDate>Sun, 06 May 2012 15:09:26 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
	<item>
		<title>By: Joao Thomazini Neto</title>
		<link>http://barelyenough.org/blog/2005/03/java-daemon/comment-page-2/#comment-85793</link>
		<dc:creator>Joao Thomazini Neto</dc:creator>
		<pubDate>Tue, 17 Jan 2012 22:46:55 +0000</pubDate>
		<guid isPermaLink="false">http://pezra.barelyenough.org/wordpress/?p=74#comment-85793</guid>
		<description>Amazing information. Right on target. Many thanks.</description>
		<content:encoded><![CDATA[<p>Amazing information. Right on target. Many thanks.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: VaderJM</title>
		<link>http://barelyenough.org/blog/2005/03/java-daemon/comment-page-2/#comment-85751</link>
		<dc:creator>VaderJM</dc:creator>
		<pubDate>Thu, 10 Nov 2011 17:48:09 +0000</pubDate>
		<guid isPermaLink="false">http://pezra.barelyenough.org/wordpress/?p=74#comment-85751</guid>
		<description>This was a fantastic post.  I was able to get a service running in only a couple days (saved me tons of time).  Thank you.</description>
		<content:encoded><![CDATA[<p>This was a fantastic post.  I was able to get a service running in only a couple days (saved me tons of time).  Thank you.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Pablo</title>
		<link>http://barelyenough.org/blog/2005/03/java-daemon/comment-page-2/#comment-85722</link>
		<dc:creator>Pablo</dc:creator>
		<pubDate>Fri, 26 Aug 2011 13:51:31 +0000</pubDate>
		<guid isPermaLink="false">http://pezra.barelyenough.org/wordpress/?p=74#comment-85722</guid>
		<description>The DaemonShutdownHook doesn&#039;t hold the app to finalize, you must not finalize the shutdown method till you end the main thread. Why? Because after the shutdown method the Signal continues with System.exit, that means that if you didn&#039;t end your tasks before that, you&#039;re going to leave lines without execution. My way to fix it was:

static public void shutdown()
{
   shutdownRequested = true;
while (!MainClass.endFlag){//put some wait if u want}
}


static public void main(String[] args)
{
    endFlag=false;
   Appender startupAppender = new ConsoleAppender(new SimpleLayout());
   try
   {
       logger.addAppender(startupAppender);
       // do sanity checks and startup actions
       daemonize();
       addDaemonShutdownHook();
   }
   catch (Throwable e)
   {
       logger.fatal(&quot;Startup failed.&quot;,e);
   }
   finally
   {
      logger.removeAppender(startupAppender);
   }

   while(!isShutdownRequested())
   {
      // wait for stimuli
      // process stimulus
   }

   // do shutdown actions
   //end thread shutdown hook
   endFlag=true;
}</description>
		<content:encoded><![CDATA[<p>The DaemonShutdownHook doesn&#8217;t hold the app to finalize, you must not finalize the shutdown method till you end the main thread. Why? Because after the shutdown method the Signal continues with System.exit, that means that if you didn&#8217;t end your tasks before that, you&#8217;re going to leave lines without execution. My way to fix it was:</p>
<p>static public void shutdown()<br />
{<br />
   shutdownRequested = true;<br />
while (!MainClass.endFlag){//put some wait if u want}<br />
}</p>
<p>static public void main(String[] args)<br />
{<br />
    endFlag=false;<br />
   Appender startupAppender = new ConsoleAppender(new SimpleLayout());<br />
   try<br />
   {<br />
       logger.addAppender(startupAppender);<br />
       // do sanity checks and startup actions<br />
       daemonize();<br />
       addDaemonShutdownHook();<br />
   }<br />
   catch (Throwable e)<br />
   {<br />
       logger.fatal(&#8220;Startup failed.&#8221;,e);<br />
   }<br />
   finally<br />
   {<br />
      logger.removeAppender(startupAppender);<br />
   }</p>
<p>   while(!isShutdownRequested())<br />
   {<br />
      // wait for stimuli<br />
      // process stimulus<br />
   }</p>
<p>   // do shutdown actions<br />
   //end thread shutdown hook<br />
   endFlag=true;<br />
}</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Eric</title>
		<link>http://barelyenough.org/blog/2005/03/java-daemon/comment-page-2/#comment-85716</link>
		<dc:creator>Eric</dc:creator>
		<pubDate>Wed, 17 Aug 2011 20:22:13 +0000</pubDate>
		<guid isPermaLink="false">http://pezra.barelyenough.org/wordpress/?p=74#comment-85716</guid>
		<description>I have a working Daemon my problem is when it is run from services (i.e. Server reboots) The Jar is running and responding to status checks but exec() passthrus to Linux do not return or get executed</description>
		<content:encoded><![CDATA[<p>I have a working Daemon my problem is when it is run from services (i.e. Server reboots) The Jar is running and responding to status checks but exec() passthrus to Linux do not return or get executed</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Vineet</title>
		<link>http://barelyenough.org/blog/2005/03/java-daemon/comment-page-2/#comment-85706</link>
		<dc:creator>Vineet</dc:creator>
		<pubDate>Fri, 24 Jun 2011 07:24:40 +0000</pubDate>
		<guid isPermaLink="false">http://pezra.barelyenough.org/wordpress/?p=74#comment-85706</guid>
		<description>Good article.

However, I am seeing the same problem that Jeff Shaver is facing. I am running on Iced Tea JVM on Linux and the shutdown hook does not get executed when I kill the application. 

Anyone else facing this problem?</description>
		<content:encoded><![CDATA[<p>Good article.</p>
<p>However, I am seeing the same problem that Jeff Shaver is facing. I am running on Iced Tea JVM on Linux and the shutdown hook does not get executed when I kill the application. </p>
<p>Anyone else facing this problem?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ron de Jong</title>
		<link>http://barelyenough.org/blog/2005/03/java-daemon/comment-page-2/#comment-85689</link>
		<dc:creator>Ron de Jong</dc:creator>
		<pubDate>Thu, 14 Apr 2011 09:46:19 +0000</pubDate>
		<guid isPermaLink="false">http://pezra.barelyenough.org/wordpress/?p=74#comment-85689</guid>
		<description>Hi Peter,

Very appreciated all in all, but you&#039;re completely ignoring the main java principle:

PLATFORM INDEPENDENCY !!!

Your solution needs to work on:
Microsoft OS&#039;s to!!! so forget about those shell solutions!!!</description>
		<content:encoded><![CDATA[<p>Hi Peter,</p>
<p>Very appreciated all in all, but you&#8217;re completely ignoring the main java principle:</p>
<p>PLATFORM INDEPENDENCY !!!</p>
<p>Your solution needs to work on:<br />
Microsoft OS&#8217;s to!!! so forget about those shell solutions!!!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Avi</title>
		<link>http://barelyenough.org/blog/2005/03/java-daemon/comment-page-2/#comment-85657</link>
		<dc:creator>Avi</dc:creator>
		<pubDate>Thu, 27 Jan 2011 17:31:44 +0000</pubDate>
		<guid isPermaLink="false">http://pezra.barelyenough.org/wordpress/?p=74#comment-85657</guid>
		<description>Thanks for this artical.  I have learned a lot.</description>
		<content:encoded><![CDATA[<p>Thanks for this artical.  I have learned a lot.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Scott the Werewolf</title>
		<link>http://barelyenough.org/blog/2005/03/java-daemon/comment-page-2/#comment-85262</link>
		<dc:creator>Scott the Werewolf</dc:creator>
		<pubDate>Sun, 15 Aug 2010 05:18:50 +0000</pubDate>
		<guid isPermaLink="false">http://pezra.barelyenough.org/wordpress/?p=74#comment-85262</guid>
		<description>&lt;p&gt;Sounds impressive, but what would you use this java program for? Sorry for asking what may be a silly question.... =P&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>Sounds impressive, but what would you use this java program for? Sorry for asking what may be a silly question&#8230;. =P</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jeff Shaver</title>
		<link>http://barelyenough.org/blog/2005/03/java-daemon/comment-page-2/#comment-83800</link>
		<dc:creator>Jeff Shaver</dc:creator>
		<pubDate>Thu, 03 Jun 2010 17:51:07 +0000</pubDate>
		<guid isPermaLink="false">http://pezra.barelyenough.org/wordpress/?p=74#comment-83800</guid>
		<description>&lt;p&gt;What is the solution in the case where the JVM ignores &#039;kill &#039; ?  TERM, HUP, INT, and QUIT are all ignored.  KILL, and USR1 do kill it, but the shutdown() code does not get run.&lt;/p&gt;

&lt;p&gt;Thanks for a very useful article.&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>What is the solution in the case where the JVM ignores &#8216;kill &#8216; ?  TERM, HUP, INT, and QUIT are all ignored.  KILL, and USR1 do kill it, but the shutdown() code does not get run.</p>
<p>Thanks for a very useful article.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jeremy Brooks</title>
		<link>http://barelyenough.org/blog/2005/03/java-daemon/comment-page-2/#comment-79885</link>
		<dc:creator>Jeremy Brooks</dc:creator>
		<pubDate>Tue, 19 Jan 2010 17:27:32 +0000</pubDate>
		<guid isPermaLink="false">http://pezra.barelyenough.org/wordpress/?p=74#comment-79885</guid>
		<description>&lt;p&gt;Sorry, forgot to include my solution for capturing stderr/stdout when needed:&lt;/p&gt;

&lt;p&gt;if (System.getProperty(&quot;detach&quot;).equals(&quot;false&quot;)) {
  // Log message about no detach or something
} else {
  System.in.close();
  System.out.close();
  System.err.close();
}&lt;/p&gt;

&lt;p&gt;Now if you are getting weird crashes and expect that you may have an out of memory error or something that is getting printed to stderr, just include the -Ddetach=false system property in your startup command. When you have captured the information you need, remove the system property, or set it to anything other than false, and your program will detach as expected.&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>Sorry, forgot to include my solution for capturing stderr/stdout when needed:</p>
<p>if (System.getProperty(&#8220;detach&#8221;).equals(&#8220;false&#8221;)) {<br />
  // Log message about no detach or something<br />
} else {<br />
  System.in.close();<br />
  System.out.close();<br />
  System.err.close();<br />
}</p>
<p>Now if you are getting weird crashes and expect that you may have an out of memory error or something that is getting printed to stderr, just include the -Ddetach=false system property in your startup command. When you have captured the information you need, remove the system property, or set it to anything other than false, and your program will detach as expected.</p>
]]></content:encoded>
	</item>
</channel>
</rss>

