<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	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/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>entroducing.com &#187; java</title>
	<atom:link href="http://www.entroducing.com/view/tag/java/feed" rel="self" type="application/rss+xml" />
	<link>http://www.entroducing.com</link>
	<description>to prove that i have too much time</description>
	<lastBuildDate>Sun, 15 May 2011 06:00:20 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.4</generator>
		<item>
		<title>Create new log file with log4j FileAppender when using Quartz Scheduler</title>
		<link>http://www.entroducing.com/view/create-new-log-file-with-log4j-fileappender-when-using-quartz-scheduler</link>
		<comments>http://www.entroducing.com/view/create-new-log-file-with-log4j-fileappender-when-using-quartz-scheduler#comments</comments>
		<pubDate>Tue, 02 Mar 2010 14:49:18 +0000</pubDate>
		<dc:creator>Benny</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[log4j]]></category>
		<category><![CDATA[quartz]]></category>

		<guid isPermaLink="false">http://www.entroducing.com/?p=177</guid>
		<description><![CDATA[Recently came across a problem whereby the quartz scheduler could not recreate a new log4j FileAppender log when the job is call again. Googled a bit and found out a couple of solutions such as using a custom log4j classes, which create a seperate thread when being called in quartz scheduler. I find that it [...]]]></description>
			<content:encoded><![CDATA[<p>Recently came across a problem whereby the quartz scheduler could not recreate a new log4j FileAppender log when the job is call again.</p>
<p>Googled a bit and found out a couple of solutions such as using a custom log4j classes, which create a seperate thread when being called in quartz scheduler.</p>
<p>I find that it is too complex and had try several ways to recreate the log file inside Quartz.</p>
<p>And finally came up with this one line of code.</p>
<p>Before I begin, let&#8217;s take a look at my log4j config.<br />
This log4j config will create a simple console system out logger and also a FileAppender logger.<br />
For my case, I want to re-create a new log file whenever this job is run.</p>
<pre class="brush: php">
log4j.rootLogger=INFO, stdout
log4j.additivity.stdout=false
log4j.additivity.joblog=false
log4j.appender.ROOT.layout.ConversionPattern=[%d] %t %c %-5p - %m%n

#console
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d %p - %m%n

#per job execution log
log4j.logger.com.yourcompany=INFO, joblog
log4j.appender.joblog=org.apache.log4j.FileAppender
log4j.appender.joblog.layout=org.apache.log4j.PatternLayout
log4j.appender.joblog.File=../jobtemp.log
log4j.appender.joblog.Append=false
log4j.appender.joblog.layout.ConversionPattern=%d %p - %m%n
</pre>
<p>and here&#8217;s the schedule job</p>
<pre class="brush: java">
public class ScheduleJob implements StatefulJob {

	private static Logger logger = Logger.getLogger(ScheduleJob.class);

	public void startJob() throws SchedulerException{
		Scheduler scheduler =
			StdSchedulerFactory.getDefaultScheduler();
		scheduler.start();
	}

	public void execute(JobExecutionContext context)
		throws JobExecutionException {

		//reset log4j config for FileAppender
		PropertyConfigurator.configure(&amp;quot;../conf/log4j.properties&amp;quot;);

		RunJobImmediately newJob  = new RunJobImmediately();
		newJob.performJob();

	}

	public static void main(String args[]){
    	try{
    		ScheduleJob scheduleJob = new ScheduleJob();
    		scheduleJob.startJob();

		}catch(Exception e){
			logger.error(e);
		}
	}
}
</pre>
<p>and finally the one line of code to recreate the log file.<br />
Apparently, this line will somehow &#8216;reload&#8217; the log4j  utitlies, which thus recreate the FileAppender logger to re-create the log file.</p>
<pre class="brush: java">
PropertyConfigurator.configure(&amp;quot;../conf/log4j.properties&amp;quot;);
</pre>
<p>Feel free to let me know if there is any performance issues or it is not working at your side.</p>
<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwww.entroducing.com%2Fview%2Fcreate-new-log-file-with-log4j-fileappender-when-using-quartz-scheduler&amp;layout=standard&amp;show_faces=true&amp;width=450&amp;action=like&amp;colorscheme=light&amp;height=80" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:450px; height:80px;" allowTransparency="true"></iframe>]]></content:encoded>
			<wfw:commentRss>http://www.entroducing.com/view/create-new-log-file-with-log4j-fileappender-when-using-quartz-scheduler/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Printing out active threads in java</title>
		<link>http://www.entroducing.com/view/printing-out-active-threads-in-java</link>
		<comments>http://www.entroducing.com/view/printing-out-active-threads-in-java#comments</comments>
		<pubDate>Sat, 20 Feb 2010 07:41:30 +0000</pubDate>
		<dc:creator>Benny</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[threads]]></category>

		<guid isPermaLink="false">http://www.entroducing.com/?p=157</guid>
		<description><![CDATA[Here&#8217;s the code snippets to display the number of running threads in your java program. It&#8217;s good to use it to track your resources. int activeCount = Thread.activeCount(); System.out.println(&#38;quot;total active = &#38;quot; + activeCount); Thread[] threads = new Thread[activeCount]; Thread.enumerate(threads); System.out.println(&#38;quot;before&#38;quot;); for (int j=0; j&#38;lt;threads.length; j++) { System.out.println(threads[j].toString()); } //run your classes Benny benny = new Benny(); [...]]]></description>
			<content:encoded><![CDATA[<p>Here&#8217;s the code snippets to display the number of running threads in your java program.</p>
<p>It&#8217;s good to use it to track your resources.</p>
<pre class="brush: java">
int activeCount = Thread.activeCount();
System.out.println(&amp;quot;total active = &amp;quot; + activeCount);
Thread[] threads = new Thread[activeCount];
Thread.enumerate(threads);

System.out.println(&amp;quot;before&amp;quot;);
for (int j=0; j&amp;lt;threads.length; j++) {
 System.out.println(threads[j].toString());
}

//run your classes
Benny benny = new Benny();

activeCount = Thread.activeCount();
System.out.println(&amp;quot;total active = &amp;quot; + activeCount);

threads = new Thread[activeCount];
System.out.println(&amp;quot;after&amp;quot;);
Thread.enumerate(threads);
for (int i=0; i&amp;lt;threads.length; i++) {
 System.out.println(threads[i].toString());
}
</pre>
<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwww.entroducing.com%2Fview%2Fprinting-out-active-threads-in-java&amp;layout=standard&amp;show_faces=true&amp;width=450&amp;action=like&amp;colorscheme=light&amp;height=80" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:450px; height:80px;" allowTransparency="true"></iframe>]]></content:encoded>
			<wfw:commentRss>http://www.entroducing.com/view/printing-out-active-threads-in-java/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Making a Struts Radio selected</title>
		<link>http://www.entroducing.com/view/making-a-struts-radio-selected</link>
		<comments>http://www.entroducing.com/view/making-a-struts-radio-selected#comments</comments>
		<pubDate>Sun, 17 Jan 2010 06:36:21 +0000</pubDate>
		<dc:creator>Benny</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[struts]]></category>

		<guid isPermaLink="false">http://www.entroducing.com/?p=147</guid>
		<description><![CDATA[By default, struts&#8217;s html radio tag do not allow you to make a radio to be selected as they have no &#8220;selected&#8221; property or something &#38;lt;html:radio property=&#38;quot;gender&#38;quot; value=&#38;quot;F&#38;quot; /&#38;gt;Male &#38;lt;html:radio property=&#38;quot;gender&#38;quot; value=&#38;quot;M&#38;quot;/&#38;gt;Female To make a radio button to be selected on load, set the value that you want to be selected in your action form [...]]]></description>
			<content:encoded><![CDATA[<p>By default, struts&#8217;s html radio tag do not allow you to make a radio to be selected as they have no &#8220;selected&#8221; property or something</p>
<pre class="brush: java">
&amp;lt;html:radio property=&amp;quot;gender&amp;quot; value=&amp;quot;F&amp;quot; /&amp;gt;Male
&amp;lt;html:radio property=&amp;quot;gender&amp;quot; value=&amp;quot;M&amp;quot;/&amp;gt;Female
</pre>
<p>To make a radio button to be selected on load, set the value that you want to be selected in your action form <strong>reset </strong>method</p>
<pre class="brush: java">

public void reset(ActionMapping mapping, HttpServletRequest request) {
            super.reset(mapping, request);
            gender= &amp;quot;F&amp;quot;;
      }
</pre>
<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwww.entroducing.com%2Fview%2Fmaking-a-struts-radio-selected&amp;layout=standard&amp;show_faces=true&amp;width=450&amp;action=like&amp;colorscheme=light&amp;height=80" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:450px; height:80px;" allowTransparency="true"></iframe>]]></content:encoded>
			<wfw:commentRss>http://www.entroducing.com/view/making-a-struts-radio-selected/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

