<?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/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Edgblog</title>
	<atom:link href="http://edgblog.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://edgblog.wordpress.com</link>
	<description>Java blog</description>
	<lastBuildDate>Sun, 25 Sep 2011 10:26:55 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='edgblog.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>Edgblog</title>
		<link>http://edgblog.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://edgblog.wordpress.com/osd.xml" title="Edgblog" />
	<atom:link rel='hub' href='http://edgblog.wordpress.com/?pushpress=hub'/>
		<item>
		<title>Thread.sleep: mark of the noob</title>
		<link>http://edgblog.wordpress.com/2010/11/18/thread-sleep-mark-of-the-noob/</link>
		<comments>http://edgblog.wordpress.com/2010/11/18/thread-sleep-mark-of-the-noob/#comments</comments>
		<pubDate>Thu, 18 Nov 2010 22:23:48 +0000</pubDate>
		<dc:creator>edgblog</dc:creator>
				<category><![CDATA[java]]></category>

		<guid isPermaLink="false">http://edgblog.wordpress.com/?p=383</guid>
		<description><![CDATA[&#8230;the post title is a bit harsh &#8211; but true in most cases. Too often Thread.sleep is used to make the main application thread pause when it needs to wait for resources to be initialized on a secondary thread, like so: while (resourceNotInitialized){ Thread.sleep (someArbitraryNumberOfMilliSeconds); } While this solution has the advantage of being easy [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=edgblog.wordpress.com&amp;blog=2278705&amp;post=383&amp;subd=edgblog&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>&#8230;the post title is a bit harsh &#8211; but true in most cases.</p>
<p>Too often Thread.sleep is used to make the main application thread pause when it needs to wait for resources to be initialized on a secondary thread, like so:</p>
<p><em>while (resourceNotInitialized){<br />
   Thread.sleep (someArbitraryNumberOfMilliSeconds);<br />
}</em></p>
<p>While this solution has the advantage of being easy to understand, it also has one drawback: it&#8217;s wrong. </p>
<p>Or more precisely the number of milliseconds the main thread must sleep for is most likely wrong:<br />
- either it&#8217;s too small and the main thread will repeatedly awake too early, hogging CPU resources in the process (buzy wait)<br />
- or it&#8217;s too large and the main thread will wake up long after all resources have been initialized, resulting in an application with sluggish behaviour (and irate users).</p>
<p>The proper way to handle this scenario is to use the wait and notify methods from the Object class.</p>
<p>- Decide on an instance (or class) on which both the main thread and secondary thread can synchronize<br />
- Main thread starts the secondary thread and acquires the monitor (enters synchronized block)<br />
- Main thread then waits, effectively releasing the monitor<br />
- When the secondary thread is done it acquires in turn the monitor and notifies the main thread.<br />
- Main thread wakes up and resumes it course </p>
<p>A bit more convoluted than Thread.sleep, granted, but much nicer and more importantly, bug-proof and latency-resistant <img src='http://s1.wp.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/edgblog.wordpress.com/383/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/edgblog.wordpress.com/383/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/edgblog.wordpress.com/383/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/edgblog.wordpress.com/383/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/edgblog.wordpress.com/383/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/edgblog.wordpress.com/383/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/edgblog.wordpress.com/383/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/edgblog.wordpress.com/383/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/edgblog.wordpress.com/383/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/edgblog.wordpress.com/383/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/edgblog.wordpress.com/383/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/edgblog.wordpress.com/383/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/edgblog.wordpress.com/383/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/edgblog.wordpress.com/383/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=edgblog.wordpress.com&amp;blog=2278705&amp;post=383&amp;subd=edgblog&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://edgblog.wordpress.com/2010/11/18/thread-sleep-mark-of-the-noob/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/bff91075a29ffac3ecdece5e19317f0d?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">edgblog</media:title>
		</media:content>
	</item>
		<item>
		<title>Top 10 Java interview questions</title>
		<link>http://edgblog.wordpress.com/2010/03/30/top-10-java-interview-questions/</link>
		<comments>http://edgblog.wordpress.com/2010/03/30/top-10-java-interview-questions/#comments</comments>
		<pubDate>Tue, 30 Mar 2010 21:31:31 +0000</pubDate>
		<dc:creator>edgblog</dc:creator>
				<category><![CDATA[java]]></category>

		<guid isPermaLink="false">http://edgblog.wordpress.com/?p=86</guid>
		<description><![CDATA[The 10 most frequently-asked Java interview questions, in my experience. Mostly used in phone interviews to &#8220;weed out&#8221; the weakest candidates. These questions are fairly simple so getting them wrong will raise a major red flag. For the same reason I wont bother printing the answers, unless somebody specifically asks for it in the comments. [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=edgblog.wordpress.com&amp;blog=2278705&amp;post=86&amp;subd=edgblog&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>
The 10 most frequently-asked Java interview questions, in my experience.<br />
Mostly used in phone interviews to &#8220;weed out&#8221; the weakest candidates.<br />
<br />
These questions are fairly simple so getting them wrong will raise a major red flag.<br />
For the same reason I wont bother printing the answers, unless somebody specifically asks for it in the comments.<br />
<br />
In no particular order:<br />
<br />
- How to prevent concurrent access to a method</p>
<p>- Meaning of the volatile keyword</p>
<p>- Difference String and StringBuffer</p>
<p>- Difference between ArrayList and Vector</p>
<p>- Relationship between equals and hashcode</p>
<p>- Difference between checked and unchecked exceptions</p>
<p>- Meaning of the final keyword</p>
<p>- Explain garbage collection, can it be forced</p>
<p>- Difference between an interface and a abstract class</p>
<p>- what&#8217;s a deadlock</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/edgblog.wordpress.com/86/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/edgblog.wordpress.com/86/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/edgblog.wordpress.com/86/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/edgblog.wordpress.com/86/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/edgblog.wordpress.com/86/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/edgblog.wordpress.com/86/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/edgblog.wordpress.com/86/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/edgblog.wordpress.com/86/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/edgblog.wordpress.com/86/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/edgblog.wordpress.com/86/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/edgblog.wordpress.com/86/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/edgblog.wordpress.com/86/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/edgblog.wordpress.com/86/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/edgblog.wordpress.com/86/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=edgblog.wordpress.com&amp;blog=2278705&amp;post=86&amp;subd=edgblog&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://edgblog.wordpress.com/2010/03/30/top-10-java-interview-questions/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/bff91075a29ffac3ecdece5e19317f0d?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">edgblog</media:title>
		</media:content>
	</item>
		<item>
		<title>Log4j code snippets</title>
		<link>http://edgblog.wordpress.com/2010/03/14/log4j-code-snippets/</link>
		<comments>http://edgblog.wordpress.com/2010/03/14/log4j-code-snippets/#comments</comments>
		<pubDate>Sun, 14 Mar 2010 18:57:36 +0000</pubDate>
		<dc:creator>edgblog</dc:creator>
				<category><![CDATA[java]]></category>

		<guid isPermaLink="false">http://edgblog.wordpress.com/?p=343</guid>
		<description><![CDATA[A few log4j-related code snippets that I tend to re-use from time to time&#8230; All pretty self-explanatory. There is a faq at http://logging.apache.org/log4j/ which already touches on the subjects below, but in a fairly light manner, and without the support of any code. 1- how to change the log level dynamically 2- add an appender [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=edgblog.wordpress.com&amp;blog=2278705&amp;post=343&amp;subd=edgblog&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>A few log4j-related code snippets that I tend to re-use from time to time&#8230; All pretty self-explanatory.</p>
<p>There is a faq at http://logging.apache.org/log4j/ which already touches on the subjects below,<br />
but in a fairly light manner, and without the support of any code.</p>
<p><strong><br />
1- how to change the log level dynamically</strong></p>
<pre class="brush: java;">

        Level debugLogLevel = Level.toLevel(&quot;DEBUG&quot;);
        Logger.getLogger(MyClass.class).setLevel(debugLogLevel);
</pre>
<p><BR></p>
<p><strong>2- add an appender at runtime</strong></p>
<pre class="brush: java;">
ConsoleAppender appender = new ConsoleAppender( new PatternLayout(&quot;%-5p [%t]: %m%n&quot;));
Logger.getRootLogger().addAppender(appender);
</pre>
<p><BR></p>
<p><strong>3- how to reload the log4j configuration file at runtime</strong></p>
<pre class="brush: java;">
String configDir =&quot;/path/to/config/directory&quot;;
LogManager.resetConfiguration();
String log4jConfigFile = configDir + java.io.File.separator +&quot;log4j.xml&quot;;
DOMConfigurator.configure(log4jConfigFile);
logger.info(&quot;log4j initialized from &quot; + log4jConfigFile);
</pre>
<p><BR><br />
<strong>4- how to direct the log output to different files.</strong></p>
<p>In the configuration below the log statements originating from the &#8220;com.firstpackage&#8221; package<br />
will be directed to FirstFile.log,  and the also to the console.<br />
Log statements from &#8220;com.secondpackage&#8221; will go to SecondFile.log, and to the console.</p>
<pre class="brush: xml;">

 &lt;appender name=&quot;FIRST_FILE&quot; class=&quot;org.apache.log4j.DailyRollingFileAppender&quot;&gt;
       &lt;param name=&quot;File&quot; value=&quot;FirstFile.log&quot;/&gt;
       &lt;layout class=&quot;org.apache.log4j.PatternLayout&quot;&gt;
       &lt;param name=&quot;ConversionPattern&quot; value=&quot;%d{HH:mm:ss,SSS} [%t] %-5p %c{1}: %m%n&quot;/&gt;
       &lt;/layout&gt;
    &lt;/appender&gt;

 &lt;appender name=&quot;SECOND_FILE&quot; class=&quot;org.apache.log4j.DailyRollingFileAppender&quot;&gt;
       &lt;param name=&quot;File&quot; value=&quot;SecondFile.log&quot;/&gt;
       &lt;layout class=&quot;org.apache.log4j.PatternLayout&quot;&gt;
       &lt;param name=&quot;ConversionPattern&quot; value=&quot;%d{HH:mm:ss,SSS} [%t] %-5p %c{1}: %m%n&quot;/&gt;
       &lt;/layout&gt;
    &lt;/appender&gt;

 &lt;appender name=&quot;CONSOLE_APPENDER&quot; class=&quot;org.apache.log4j.ConsoleAppender&quot;&gt;
        &lt;layout class=&quot;org.apache.log4j.PatternLayout&quot;&gt;
            &lt;param name=&quot;ConversionPattern&quot; value=&quot;%d{HH:mm:ss,SSS} [%t] %-5p %c{1}: %m%n&quot;/&gt;
        &lt;/layout&gt;
    &lt;/appender&gt;

&lt;appender name=&quot;ASYNC_APPENDER_1&quot; class=&quot;org.apache.log4j.AsyncAppender&quot;&gt;
        &lt;appender-ref ref=&quot;CONSOLE_APPENDER&quot;/&gt;
        &lt;appender-ref ref=&quot;FIRST_FILE&quot;/&gt;
    &lt;/appender&gt;

    &lt;appender name=&quot;ASYNC_APPENDER_2&quot; class=&quot;org.apache.log4j.AsyncAppender&quot;&gt;
        &lt;appender-ref ref=&quot;CONSOLE_APPENDER&quot;/&gt;
        &lt;appender-ref ref=&quot;SECOND_FILE&quot;/&gt;
    &lt;/appender&gt;

 &lt;logger name=&quot;com.firstpackage&quot; additivity=&quot;false&quot;&gt;
        &lt;level value=&quot;DEBUG&quot; /&gt;
        &lt;appender-ref ref=&quot;ASYNC_APPENDER_1&quot; /&gt;
    &lt;/logger&gt;

    &lt;logger name=&quot;com.secondpackage&quot; additivity=&quot;false&quot;&gt;
        &lt;level value=&quot;DEBUG&quot; /&gt;
        &lt;appender-ref ref=&quot;ASYNC_APPENDER_2&quot; /&gt;
    &lt;/logger&gt;
</pre>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/edgblog.wordpress.com/343/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/edgblog.wordpress.com/343/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/edgblog.wordpress.com/343/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/edgblog.wordpress.com/343/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/edgblog.wordpress.com/343/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/edgblog.wordpress.com/343/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/edgblog.wordpress.com/343/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/edgblog.wordpress.com/343/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/edgblog.wordpress.com/343/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/edgblog.wordpress.com/343/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/edgblog.wordpress.com/343/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/edgblog.wordpress.com/343/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/edgblog.wordpress.com/343/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/edgblog.wordpress.com/343/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=edgblog.wordpress.com&amp;blog=2278705&amp;post=343&amp;subd=edgblog&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://edgblog.wordpress.com/2010/03/14/log4j-code-snippets/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/bff91075a29ffac3ecdece5e19317f0d?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">edgblog</media:title>
		</media:content>
	</item>
		<item>
		<title>First steps with Awk</title>
		<link>http://edgblog.wordpress.com/2010/02/25/first-steps-with-awk/</link>
		<comments>http://edgblog.wordpress.com/2010/02/25/first-steps-with-awk/#comments</comments>
		<pubDate>Thu, 25 Feb 2010 22:01:41 +0000</pubDate>
		<dc:creator>edgblog</dc:creator>
				<category><![CDATA[linux]]></category>

		<guid isPermaLink="false">http://edgblog.wordpress.com/?p=316</guid>
		<description><![CDATA[Awk is a Unix programming language specifically dedicated to the processing of text files. While it&#8217;s been around for ages (it&#8217;s almost as old as Unix) it remains fairly unknown and/or unused compared to other utilities such as grep, vi, find&#8230; Strange really as it&#8217;s powerful and quite easy to use. Example case: looking up [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=edgblog.wordpress.com&amp;blog=2278705&amp;post=316&amp;subd=edgblog&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Awk is a Unix programming language specifically dedicated to the processing of text files.</p>
<p>While it&#8217;s been around for ages (it&#8217;s almost as old as Unix) it remains fairly unknown and/or unused compared to other utilities such as grep, vi, find&#8230; Strange really as it&#8217;s powerful and quite easy to use.</p>
<p>Example case: looking up and summarizing data in a log file.</p>
<p>Imagine the &#8220;usual&#8221; application log file of the form: <em>[Date] [Thread #] [Log level] [log message]</em></p>
<p>Say some of the lines logged in there account for the time spent on one given algorithm:<br />
<em>13:42:07,019 [Thread-1] DEBUG Calculation: time spent on <strong>algo</strong> #12 is <strong>831</strong> ms</em></p>
<p>It would be interesting to parse all the lines containing the word <em>algo</em> to extract 1) the total time spent on algo calculation 2) the average time spent across all calculations.</p>
<p>In Java,  coding such a parser from scratch would take about one full day for most developers  (if not more)<br />
- locate file, open and read , manage io exceptions<br />
- parse lines (manage parsing exceptions)<br />
- calculate results and print<br />
- create a build script</p>
<p>By comparison the equivalent script can be written with Awk in minutes.</p>
<p>proceeding step by step</p>
<p><strong>Step 1</strong>.<br />
to print to screen all lines containing the term <em>algo</em> in the file<em> myfile.log</em></p>
<p><em>awk &#8216;/algo/  {;print $0}&#8217;  myfile.log </em></p>
<p>Note: Awk divides each line in columns, where a column is a block of text separated by whitespaces.<br />
Eg. in the format above <em>[Date] [Thread] [Debug]</em>&#8230;  $0 will print the whole line, $1 will print the date, $2 the thread number ..etc&#8230;</p>
<p><strong>Step2</strong>.<br />
To sum the number of lines with the term <em>algo</em>:</p>
<p><em> awk &#8216;/algo/  {nb++} END {printf &#8220;%d&#8221;,nb}&#8217;  myfile.log</em></p>
<p>[here <em>nb</em> is a local variable declared on the fly and used as a line counter]</p>
<p><strong>Step3</strong>.<br />
To keep a running total of the time spent on algo calculations:</p>
<p><em> awk &#8216;/algo/  {total+=$9} END {printf &#8220;%d&#8221;,total}&#8217; myfile.log</em></p>
<p>[assuming the time spent on a calculation  is printed on the 9th column of the line]</p>
<p><strong>Step4</strong>.<br />
putting it all together &#8211; print the total time spent + average on each calculation:</p>
<p><em>awk &#8216;/algo/  {nb++;total+= $9} END {printf &#8220;%d %d&#8221;, total, total/nb}&#8217; myfile.log</em></p>
<p><BR><BR></p>
<p>The best way to learn more about Awk is to try it&#8230;.</p>
<p>- Awk should come as a standard with all linux distributions.</p>
<p>- On Windows it&#8217;s available via<a href="http://www.cygwin.com"> Cygwin.</a> An alternative implementation, gawk, (for Gnu Awk) can also be found <a href="http://gnuwin32.sourceforge.net/packages/gawk.htm">here</a>.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/edgblog.wordpress.com/316/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/edgblog.wordpress.com/316/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/edgblog.wordpress.com/316/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/edgblog.wordpress.com/316/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/edgblog.wordpress.com/316/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/edgblog.wordpress.com/316/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/edgblog.wordpress.com/316/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/edgblog.wordpress.com/316/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/edgblog.wordpress.com/316/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/edgblog.wordpress.com/316/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/edgblog.wordpress.com/316/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/edgblog.wordpress.com/316/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/edgblog.wordpress.com/316/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/edgblog.wordpress.com/316/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=edgblog.wordpress.com&amp;blog=2278705&amp;post=316&amp;subd=edgblog&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://edgblog.wordpress.com/2010/02/25/first-steps-with-awk/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/bff91075a29ffac3ecdece5e19317f0d?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">edgblog</media:title>
		</media:content>
	</item>
		<item>
		<title>How to copy a file in Java</title>
		<link>http://edgblog.wordpress.com/2010/02/20/how-to-copy-a-file-in-java/</link>
		<comments>http://edgblog.wordpress.com/2010/02/20/how-to-copy-a-file-in-java/#comments</comments>
		<pubDate>Sat, 20 Feb 2010 17:37:20 +0000</pubDate>
		<dc:creator>edgblog</dc:creator>
				<category><![CDATA[java]]></category>

		<guid isPermaLink="false">http://edgblog.wordpress.com/?p=290</guid>
		<description><![CDATA[Even the most basic of task &#8211; like copying a file &#8211; can be done in several different ways in Java&#8230; a testament to the richness of the platform (or its complexity !). Four possible ways to copy a file below, all error handling left aside. 1- the complicated way, manipulating io streams. 2- The [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=edgblog.wordpress.com&amp;blog=2278705&amp;post=290&amp;subd=edgblog&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Even the most basic of task &#8211; like copying a file &#8211; can be done in several different ways in Java&#8230;<br />
a testament to the richness of the platform (or its complexity !).</p>
<p>Four possible ways to copy a file below, all error handling left aside.</p>
<p>1- the complicated way, manipulating io streams. </p>
<pre class="brush: java;">
   import java.io.FileInputStream;
   import java.io.FileOutputStream;
   import java.io.InputStream;
   import java.io.OutputStream;
   ....

   String orig =&quot;file.xml&quot;;
   String dest = &quot;file.xml.bak&quot;;
   InputStream in = new FileInputStream(orig);
   OutputStream out = new FileOutputStream(dest);
   byte[] buf = new byte[1024];
   int len;
   while ((len = in.read(buf)) &gt; 0) {
      out.write(buf, 0, len);
   }
   in.close();
   out.close(); 
</pre>
<p>2- The ugly , non-portable way, using the operating system environment:</p>
<pre class="brush: java;">

   Runtime.getRuntime().exec(&quot;OS dependent file copy command here&quot;); 
</pre>
<p>3- The opensource  way, using the Apache Commons library.</p>
<pre class="brush: java;">

   import java.file.io;
   import org.apache.commons.io.FileUtils;
   ....
   String orig =&quot;file.xml&quot;;
   String dest = &quot;file.xml.bak&quot;;
   File fOrig = new File(orig);
   File fDest = new File(dest);
   FileUtils.copyFile(fOrig, fDest);
</pre>
<p>4- The novel way- using Java 7 and it&#8217;s revamped I/O api.</p>
<pre class="brush: java;">

    import java.io.File;
    import java.nio.file.Path;
    ...
    String orig =&quot;file.xml&quot;;
    String dest = &quot;file.xml.bak&quot;;
    File f = new File (orig);
    Path p = f.toPath();
    p.copyTo(new File (dest).toPath(), REPLACE_EXISTING, COPY_ATTRIBUTES);
</pre>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/edgblog.wordpress.com/290/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/edgblog.wordpress.com/290/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/edgblog.wordpress.com/290/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/edgblog.wordpress.com/290/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/edgblog.wordpress.com/290/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/edgblog.wordpress.com/290/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/edgblog.wordpress.com/290/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/edgblog.wordpress.com/290/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/edgblog.wordpress.com/290/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/edgblog.wordpress.com/290/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/edgblog.wordpress.com/290/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/edgblog.wordpress.com/290/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/edgblog.wordpress.com/290/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/edgblog.wordpress.com/290/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=edgblog.wordpress.com&amp;blog=2278705&amp;post=290&amp;subd=edgblog&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://edgblog.wordpress.com/2010/02/20/how-to-copy-a-file-in-java/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/bff91075a29ffac3ecdece5e19317f0d?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">edgblog</media:title>
		</media:content>
	</item>
		<item>
		<title>Dependency graph in Netbeans 6.8</title>
		<link>http://edgblog.wordpress.com/2010/01/10/dependency-graph-in-netbeans-6-8/</link>
		<comments>http://edgblog.wordpress.com/2010/01/10/dependency-graph-in-netbeans-6-8/#comments</comments>
		<pubDate>Sun, 10 Jan 2010 18:49:39 +0000</pubDate>
		<dc:creator>edgblog</dc:creator>
				<category><![CDATA[java]]></category>

		<guid isPermaLink="false">http://edgblog.wordpress.com/?p=268</guid>
		<description><![CDATA[It seems that I discover something new in Netbeans every day&#8230; The &#8220;Show dependency graph&#8221; associated with every Maven projects in Netbeans 6.8 had escaped me so far. This menu option (accessible by right-clicking on a Maven project in the &#8220;projects&#8221; window) generates a graph of all the projects&#8217; dependencies  (libraries declared in the pom [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=edgblog.wordpress.com&amp;blog=2278705&amp;post=268&amp;subd=edgblog&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>It seems that I discover something new in Netbeans every day&#8230; The &#8220;Show dependency graph&#8221; associated with every Maven projects in Netbeans 6.8 had escaped me so far.</p>
<p>This menu option (accessible by right-clicking on a Maven project in the &#8220;projects&#8221; window) generates a graph of all the projects&#8217; dependencies  (libraries declared in the pom and their <a href="http://maven.apache.org/guides/introduction/introduction-to-dependency-mechanism.html#Transitive_Dependencies">transitive dependencies</a>).</p>
<p>Example below of the dependency graph  of the libraries required by a project called, rather imaginatively, mavenproject1.</p>
<p><a href="http://edgblog.files.wordpress.com/2010/01/netbeans_dependency_graph.jpg"><img class="aligncenter size-full wp-image-271" title="Netbeans dependency graph" src="http://edgblog.files.wordpress.com/2010/01/netbeans_dependency_graph.jpg?w=1024&#038;h=593" alt="" width="1024" height="593" /></a></p>
<p>The graph will be rather hard to read for a large number of dependencies, but it&#8217;s nice to have nevertheless.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/edgblog.wordpress.com/268/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/edgblog.wordpress.com/268/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/edgblog.wordpress.com/268/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/edgblog.wordpress.com/268/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/edgblog.wordpress.com/268/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/edgblog.wordpress.com/268/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/edgblog.wordpress.com/268/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/edgblog.wordpress.com/268/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/edgblog.wordpress.com/268/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/edgblog.wordpress.com/268/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/edgblog.wordpress.com/268/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/edgblog.wordpress.com/268/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/edgblog.wordpress.com/268/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/edgblog.wordpress.com/268/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=edgblog.wordpress.com&amp;blog=2278705&amp;post=268&amp;subd=edgblog&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://edgblog.wordpress.com/2010/01/10/dependency-graph-in-netbeans-6-8/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/bff91075a29ffac3ecdece5e19317f0d?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">edgblog</media:title>
		</media:content>

		<media:content url="http://edgblog.files.wordpress.com/2010/01/netbeans_dependency_graph.jpg" medium="image">
			<media:title type="html">Netbeans dependency graph</media:title>
		</media:content>
	</item>
		<item>
		<title>Debugging classpath issues</title>
		<link>http://edgblog.wordpress.com/2010/01/09/debugging-classpath-issues/</link>
		<comments>http://edgblog.wordpress.com/2010/01/09/debugging-classpath-issues/#comments</comments>
		<pubDate>Sat, 09 Jan 2010 00:16:49 +0000</pubDate>
		<dc:creator>edgblog</dc:creator>
				<category><![CDATA[java]]></category>

		<guid isPermaLink="false">http://edgblog.wordpress.com/?p=275</guid>
		<description><![CDATA[There&#8217;s nothing more frustrating than wasting time figuring out why some resources (e.g. configuration files for log4j, hibernate&#8230;) are not loaded correctly from the classpath. The few lines of code below help narrow down these kind of issues. Knowing what&#8217;s the classpath at runtime and being able to test if it covers a specific file [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=edgblog.wordpress.com&amp;blog=2278705&amp;post=275&amp;subd=edgblog&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>There&#8217;s nothing more frustrating than wasting time figuring out why some resources (e.g. configuration files for log4j, hibernate&#8230;) are not loaded correctly from the classpath.</p>
<p>The few lines of code below help narrow down these kind of issues. Knowing what&#8217;s the classpath at runtime and being able to test if it covers a specific file is half the battle won already.</p>
<p><span style="font-family:sans-serif;"> 1- Print out name of all files on the classpath</span></p>
<pre class="brush: java;">
String classpath = java.lang.System.getProperty( &quot;java.class.path&quot; );
for (String path : classpath.split(System.getProperty(&quot;path.separator&quot;))){
   File f = new File (path);
   String resource = (f.isDirectory()?Arrays.asList( f.list()).toString():f.toString());
   System.out.println (resource);
}
</pre>
<p><span style="font-family:sans-serif;"> 2- Check wether a specific file is on the classpath</span></p>
<pre class="brush: java;">

String myResource = .... ;
InputStream is = getClass().getResourceAsStream(myResource);
System.out.println (myResource + &quot; is &quot; +  (is==null?&quot;not&quot;:&quot;&quot;) + &quot; on the classpath&quot;);
</pre>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/edgblog.wordpress.com/275/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/edgblog.wordpress.com/275/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/edgblog.wordpress.com/275/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/edgblog.wordpress.com/275/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/edgblog.wordpress.com/275/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/edgblog.wordpress.com/275/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/edgblog.wordpress.com/275/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/edgblog.wordpress.com/275/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/edgblog.wordpress.com/275/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/edgblog.wordpress.com/275/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/edgblog.wordpress.com/275/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/edgblog.wordpress.com/275/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/edgblog.wordpress.com/275/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/edgblog.wordpress.com/275/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=edgblog.wordpress.com&amp;blog=2278705&amp;post=275&amp;subd=edgblog&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://edgblog.wordpress.com/2010/01/09/debugging-classpath-issues/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/bff91075a29ffac3ecdece5e19317f0d?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">edgblog</media:title>
		</media:content>
	</item>
		<item>
		<title>Migrating Eclipse plugins</title>
		<link>http://edgblog.wordpress.com/2010/01/05/migrating-eclipse-plugins/</link>
		<comments>http://edgblog.wordpress.com/2010/01/05/migrating-eclipse-plugins/#comments</comments>
		<pubDate>Tue, 05 Jan 2010 22:05:07 +0000</pubDate>
		<dc:creator>edgblog</dc:creator>
				<category><![CDATA[java]]></category>

		<guid isPermaLink="false">http://edgblog.wordpress.com/?p=265</guid>
		<description><![CDATA[Developers can sometimes hold back from upgrading their Eclipse installation due to the perceived difficulty of migrating already installed plugins to the new setup. This process is actually fairly easy, as described below: [CAVEAT - being able to migrate a plugin from one Eclipse version to another doesnt necessarily mean this plugin will still work [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=edgblog.wordpress.com&amp;blog=2278705&amp;post=265&amp;subd=edgblog&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Developers can sometimes hold back from upgrading their Eclipse installation due to the perceived difficulty of migrating already installed plugins to the new setup.</p>
<p>This process is actually fairly easy, as described below:<br />
<strong>[CAVEAT - being able to migrate a plugin from one Eclipse version to another doesnt necessarily mean this plugin will still work with the newer version]</strong></p>
<p>1- Download the latest and greatest version of Eclipse, unpack and install.</p>
<p>2. Create a file called &#8220;.eclipseextension&#8221; at the root of the old Eclipse installation.<br />
On Windows the file explorer might not let you create a file with this name &#8211; the preferred way is then to open up a command prompt,<br />
navigate to the root of the previous install  and type &#8220;copy con .eclipseexension&#8221; to create the file, followed by &#8220;CTRL-F6&#8243; to save.</p>
<p>3. Edit this file to the content below:<br />
<em>id=org.eclipse.platform<br />
name=Eclipse Platform<br />
version=3.5.0 &#8212; version of the newest Eclipse installation</em></p>
<p>4. Open the new version of Eclipse, Select Help menu -&gt; Install new software.</p>
<p>5. Click the &#8220;Add&#8221; button on the right of the &#8220;work with&#8221; box, and pick the location of<br />
your previous Eclipse install (i.e directory where the .eclipseextension file is located)</p>
<p>6. Unselect &#8220;group items by category&#8221; on the bottom panel<br />
to see the plugins installed with the previous Eclipse.</p>
<p>7. Select which plugins to re-install.</p>
<p>8. Restart Eclipse.</p>
<p>9. Check that the plugins work correctly(!) in their respective contextual menus, views and perspectives.<br />
If something goes wrong: select Help menu -&gt; Install new software -&gt; work with all available sites,<br />
pick &#8220;what&#8217;s already installed&#8221; on the bottom panel and uninstall the faulty plugins.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/edgblog.wordpress.com/265/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/edgblog.wordpress.com/265/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/edgblog.wordpress.com/265/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/edgblog.wordpress.com/265/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/edgblog.wordpress.com/265/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/edgblog.wordpress.com/265/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/edgblog.wordpress.com/265/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/edgblog.wordpress.com/265/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/edgblog.wordpress.com/265/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/edgblog.wordpress.com/265/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/edgblog.wordpress.com/265/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/edgblog.wordpress.com/265/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/edgblog.wordpress.com/265/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/edgblog.wordpress.com/265/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=edgblog.wordpress.com&amp;blog=2278705&amp;post=265&amp;subd=edgblog&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://edgblog.wordpress.com/2010/01/05/migrating-eclipse-plugins/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/bff91075a29ffac3ecdece5e19317f0d?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">edgblog</media:title>
		</media:content>
	</item>
		<item>
		<title>(almost) painless profiling with TPTP 4.6.1 and Eclipse</title>
		<link>http://edgblog.wordpress.com/2009/11/30/almost-painless-profiling-with-tptp-4-6-1-and-eclipse/</link>
		<comments>http://edgblog.wordpress.com/2009/11/30/almost-painless-profiling-with-tptp-4-6-1-and-eclipse/#comments</comments>
		<pubDate>Mon, 30 Nov 2009 20:30:50 +0000</pubDate>
		<dc:creator>edgblog</dc:creator>
				<category><![CDATA[java]]></category>

		<guid isPermaLink="false">http://edgblog.wordpress.com/?p=246</guid>
		<description><![CDATA[The TPTP plugin for Eclipse in its versions 4.3, 4.4 and 4.5 was fairly bug prone &#8211; to the point of being barely usable. In particular it had a frustrating tendency to lock up the entire IDE&#8230;The latest version v.4.6.1  is more stable, even though setting it up still requires quite a lot of work&#8230; [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=edgblog.wordpress.com&amp;blog=2278705&amp;post=246&amp;subd=edgblog&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>The TPTP plugin for Eclipse in its versions 4.3, 4.4 and 4.5 was fairly bug prone &#8211; to the point of being barely usable. In particular it had a frustrating tendency to lock up the entire IDE&#8230;The latest version v.4.6.1  is more stable, even though setting it up still requires quite a lot of work&#8230; I only put up with it (just) because I prefer using Eclipse over Netbeans as my main development tool.</p>
<p>Summary of the steps involved below (tested with Eclipse 3.5, TPTP 4.6.1, running on Windows XP).</p>
<p>1.)<strong> </strong><a href="http://www.eclipse.org/tptp/home/downloads/updateManager.php"><strong>D</strong>ownload TPTP  4.6.1 from within the comfort of your Eclipse IDE.</a><br />
Replace 4.6.0 in the page linked above by 4.6.1&#8230; the documentation is not quite up to date :/<br />
Once the install is over and Eclipse is restarted a new &#8220;Profiling and logging&#8221; perspective should be available in the main menu.</p>
<p>2.) <a href="http://www.eclipse.org/tptp/home/downloads/"><strong>D</strong>ownload the agent controller separately</a><br />
In theory this step is not really needed, as TPTP now contains its own  Integrated Agent Controller (IAC).<br />
In practice the standalone agent is more stable than the IAC.</p>
<p>3.) <strong>U</strong>nzip the agent controller on your local drive.</p>
<p>4.) <strong>A</strong>dd the profiler DLLs to your path. From the command line:</p>
<p>Set TPTP_AC_HOME=&lt;path to your local agent controller installation&gt;<br />
set JAVA_PROFILER_HOME=%TPTP_AC_HOME%\plugins\org.eclipse.tptp.javaprofiler<br />
Set PATH=%JAVA_PROFILER_HOME%;%PATH%;%TPTP_AC_HOME%\bin</p>
<p>[more details on setting up the path <a href="http://www.eclipse.org/tptp/platform/documents/tutorials/jvmti/Java_Application_Profiling_using_TPTP-v2.0.html">here</a> , check out section 3.3]</p>
<p>5.) <strong>C</strong>reate a file called filters.txt (for example) where you&#8217;ll specify the classes which needs to be profiled.</p>
<p>Content of the file=<br />
<em>com.myclasses* * INCLUDE<br />
* * EXCLUDE</em></p>
<p>This will profile all the methods of all classes in the com.myclasses packages.<br />
Note that filtering is essential if you dont want to end up with hideously large profiling files.</p>
<p>6.) <strong>R</strong>un the application to be profiled<br />
Add the following to the Java command line used to run the app so that all execution details are collected:<br />
<em>-agentlib:JPIBootLoader=JPIAgent:server=standalone,filters=filters.txt;CGProf:execdetails=true;</em></p>
<p>If all goes well a file name called <em>trace.trcxml</em> (by default) will start collecting the profiling info from the current directory.</p>
<p>7.) <strong>O</strong>pen the profiling view in Eclipse and import the trace file generated<br />
(a popup menu will appear where you can select additional filters and specific statistics to be run on the trace file)<br />
Be prepared to wait if you didnt specify a broad enough set of filters in step 5)</p>
<p>8.) <strong>O</strong>nce import is finished right click on the profiling file and open it with the appropriate editor<br />
eg. use ExecutionStatistics and ExecutionFlow if profiling run with <em>execdetails=true</em></p>
<p><em><br />
</em></p>
<p><strong>Caveat:</strong> Profiling done that way doesnt give a realtime feedback on the behaviour of the app being profiled<br />
(the trace.trcxml file generated needs to be fed into Eclipse repeatedly for up to date results).</p>
<p>On the plus side this method works for all kind of processes, remote or local, libraries or main programs.</p>
<p>If all else fails there&#8217;s always the Netbeans&#8217;s profiler, which is  very good, and free, or Yourkit (<a href="http://www.yourkit.com">www.yourkit.com</a>),which is excellent(but not free&#8230;)  Another alternative is <a href="https://visualvm.dev.java.net/">VisualVm </a>, which offers both profiling and sampling capabilities.</p>
<p>All these tools work pretty much out of the box, in stark contract with TPTP.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/edgblog.wordpress.com/246/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/edgblog.wordpress.com/246/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/edgblog.wordpress.com/246/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/edgblog.wordpress.com/246/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/edgblog.wordpress.com/246/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/edgblog.wordpress.com/246/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/edgblog.wordpress.com/246/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/edgblog.wordpress.com/246/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/edgblog.wordpress.com/246/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/edgblog.wordpress.com/246/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/edgblog.wordpress.com/246/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/edgblog.wordpress.com/246/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/edgblog.wordpress.com/246/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/edgblog.wordpress.com/246/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=edgblog.wordpress.com&amp;blog=2278705&amp;post=246&amp;subd=edgblog&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://edgblog.wordpress.com/2009/11/30/almost-painless-profiling-with-tptp-4-6-1-and-eclipse/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/bff91075a29ffac3ecdece5e19317f0d?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">edgblog</media:title>
		</media:content>
	</item>
		<item>
		<title>Google Collections&#8217; computing map</title>
		<link>http://edgblog.wordpress.com/2009/11/10/google-collections-computing-map/</link>
		<comments>http://edgblog.wordpress.com/2009/11/10/google-collections-computing-map/#comments</comments>
		<pubDate>Tue, 10 Nov 2009 20:58:34 +0000</pubDate>
		<dc:creator>edgblog</dc:creator>
				<category><![CDATA[java]]></category>

		<guid isPermaLink="false">http://edgblog.wordpress.com/?p=225</guid>
		<description><![CDATA[&#8220;On demand computing&#8221;, as provided by Google Collections, turns a map into a computing map, which can be used as a basic cache for rare (but expensive) lookups. Although the javadoc for this functionality is a good start, it can be opaque at times, especially for developers not entirely accustomed with the functional style of [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=edgblog.wordpress.com&amp;blog=2278705&amp;post=225&amp;subd=edgblog&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>&#8220;On demand computing&#8221;, as provided by <a href="http://code.google.com/p/google-collections">Google Collections</a>, turns a map into a computing map, which can be used as a basic cache for rare (but expensive) lookups.</p>
<p>Although the <a href="http://code.google.com/p/google-collections/source/browse/trunk/gwt/com/google/common/collect/MapMaker.java?spec=svn108&amp;r=108">javadoc</a> for this functionality is a good start, it can be opaque at times, especially for developers not entirely accustomed with the functional style of programming prevalent in the library. </p>
<p>The code below puts a computing map into context.</p>
<p>1. Computing map declaration.</p>
<pre class="brush: java;">
//the 'usual' ConcurrentMap...
ConcurrentMap&lt;Key, Value&gt; computingMap =
// ... enhanced to support soft/weak keys/values, timed expiration and...
        .new MapMaker()
//...on-demand computation...
        .makeComputingMap(
//...passing into parameter an anonymous instance implementing the Function interface...
        new Function&lt;Key, Value&gt;() {
//...where the function transforming a key into a value is defined so that....
        public Value apply(Key key) {
//...it delegates to the a specialized, computationaly expensive function.
         return createExpensiveValue(key);
       } 
</pre>
<p>2. Computationaly expensive function used to generate a value from a key.</p>
<pre class="brush: java;">
  Value createExpensiveValue(Key key){
               Value computedValue = null;
                /*transform the input key into the computedValue here
                ...
                */
             return computedValue;
     }
</pre>
<p>3. Retrieving values from the map</p>
<pre class="brush: java;">
void retrieveValuesFromComputingMap() {
        Key k = new Key(...);
        //the map generates a value from the key and stores it.
        Value v =computingMap.get(k);
        //subsequent calls to retrieve the value associated with the key will fetch it directly from the map,
       // skipping any other computation
}
</pre>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/edgblog.wordpress.com/225/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/edgblog.wordpress.com/225/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/edgblog.wordpress.com/225/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/edgblog.wordpress.com/225/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/edgblog.wordpress.com/225/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/edgblog.wordpress.com/225/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/edgblog.wordpress.com/225/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/edgblog.wordpress.com/225/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/edgblog.wordpress.com/225/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/edgblog.wordpress.com/225/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/edgblog.wordpress.com/225/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/edgblog.wordpress.com/225/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/edgblog.wordpress.com/225/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/edgblog.wordpress.com/225/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=edgblog.wordpress.com&amp;blog=2278705&amp;post=225&amp;subd=edgblog&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://edgblog.wordpress.com/2009/11/10/google-collections-computing-map/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/bff91075a29ffac3ecdece5e19317f0d?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">edgblog</media:title>
		</media:content>
	</item>
	</channel>
</rss>
