<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss 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:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">

<channel>
	<title>Onkar Joshi's blog</title>
	
	<link>http://www.onkarjoshi.com/blog</link>
	<description>Tips and Tricks for the Practicing IT Professional</description>
	<lastBuildDate>Mon, 30 Jan 2012 22:54:04 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.5.1</generator>
		<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/onkarjoshi" /><feedburner:info uri="onkarjoshi" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><feedburner:emailServiceId>onkarjoshi</feedburner:emailServiceId><feedburner:feedburnerHostname>http://feedburner.google.com</feedburner:feedburnerHostname><item>
		<title>Heap dump of a running JVM with jmap</title>
		<link>http://feedproxy.google.com/~r/onkarjoshi/~3/OVEAwn9RPB8/</link>
		<comments>http://www.onkarjoshi.com/blog/247/heap-dump-of-a-running-jvm-with-jmap/#comments</comments>
		<pubDate>Mon, 30 Jan 2012 22:54:04 +0000</pubDate>
		<dc:creator>Onkar Joshi</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[JVM]]></category>

		<guid isPermaLink="false">http://www.onkarjoshi.com/blog/?p=247</guid>
		<description><![CDATA[You don&#8217;t have to wait for your JVM to die with an OutOfMemoryError to get the heap dump you get when you use the -XX:+HeapDumpOnOutOfMemoryError flag. Setting that flag is a good thing though &#8211; you get a dump after the heap is big and bloated just before the JVM dies making it easier to [...]<div class='yarpp-related-rss'>

Related posts:<ol>
<li><a href='http://www.onkarjoshi.com/blog/230/sending-a-sigbreak-signal-to-a-java-process-to-do-a-thread-dump-in-windows/' rel='bookmark' title='Sending a SIGBREAK signal to a Java process to do a thread dump in Windows'>Sending a SIGBREAK signal to a Java process to do a thread dump in Windows</a></li>
<li><a href='http://www.onkarjoshi.com/blog/226/crash-your-jvm-by-killing-the-garbage-collector/' rel='bookmark' title='Crash your JVM by killing the garbage collector!'>Crash your JVM by killing the garbage collector!</a></li>
<li><a href='http://www.onkarjoshi.com/blog/174/hotspot-jvm-client-server-vm-optimization/' rel='bookmark' title='HotSpot JVM &#8211; Client / Server VM optimization &#8211; 260ms vs 0ms!'>HotSpot JVM &#8211; Client / Server VM optimization &#8211; 260ms vs 0ms!</a></li>
<li><a href='http://www.onkarjoshi.com/blog/209/using-xss-to-adjust-java-default-thread-stack-size-to-save-memory-and-prevent-stackoverflowerror/' rel='bookmark' title='Using -Xss to adjust Java default thread stack size to save memory and prevent StackOverflowError'>Using -Xss to adjust Java default thread stack size to save memory and prevent StackOverflowError</a></li>
<li><a href='http://www.onkarjoshi.com/blog/219/volatile-array/' rel='bookmark' title='Atomic array classes and volatile arrays in the JVM'>Atomic array classes and volatile arrays in the JVM</a></li>
</ol>
</div>
]]></description>
				<content:encoded><![CDATA[<p style="text-align: justify;">You don&#8217;t have to wait for your JVM to die with an OutOfMemoryError to get the heap dump you get when you use the -XX:+HeapDumpOnOutOfMemoryError flag. Setting that flag is a good thing though &#8211; you get a dump after the heap is big and bloated just before the JVM dies making it easier to locate the problem are when analyzing the heap.</p>
<p>However, if you just want a dump of the current state of the heap &#8211; this is how you do it.</p>
<p style="font-family: Courier New,Courier,mono;"><strong><span style="font-size: large;">jps</span></strong></p>
<p>Similar to ps. But shows only Java processes. Very nice! Use this to identify your target JVM pid. You can of course use the Unix ps command or the Windows tasklist command or the graphical TaskManager.</p>
<p style="font-family: Courier New,Courier,mono;"><strong><span style="font-size: large;">jmap -dump:file=heap.bin 924</span></strong></p>
<p>That would dump the heap of the Java process with pid 924 into a file named heap.bin.</p>
<p><img class="aligncenter size-full wp-image-248" title="jvm.heap.dump" src="http://www.onkarjoshi.com/blog/wp-content/uploads/2012/01/jvm.heap_.dump_.png" alt="" width="459" height="146" /></p>
<p style="text-align: justify;">Simple enough, isn&#8217;t it? The tricky bit is to actually analyze a heap dump to extract information from all the data contained therein. I&#8217;ll write about analyzing heap dumps in a future post.</p>
<p>Got a quick tip with other useful ways to get heap dumps? Please leave a comment!</p>
<div class='yarpp-related-rss'>
<p>Related posts:<ol>
<li><a href='http://www.onkarjoshi.com/blog/230/sending-a-sigbreak-signal-to-a-java-process-to-do-a-thread-dump-in-windows/' rel='bookmark' title='Sending a SIGBREAK signal to a Java process to do a thread dump in Windows'>Sending a SIGBREAK signal to a Java process to do a thread dump in Windows</a></li>
<li><a href='http://www.onkarjoshi.com/blog/226/crash-your-jvm-by-killing-the-garbage-collector/' rel='bookmark' title='Crash your JVM by killing the garbage collector!'>Crash your JVM by killing the garbage collector!</a></li>
<li><a href='http://www.onkarjoshi.com/blog/174/hotspot-jvm-client-server-vm-optimization/' rel='bookmark' title='HotSpot JVM &#8211; Client / Server VM optimization &#8211; 260ms vs 0ms!'>HotSpot JVM &#8211; Client / Server VM optimization &#8211; 260ms vs 0ms!</a></li>
<li><a href='http://www.onkarjoshi.com/blog/209/using-xss-to-adjust-java-default-thread-stack-size-to-save-memory-and-prevent-stackoverflowerror/' rel='bookmark' title='Using -Xss to adjust Java default thread stack size to save memory and prevent StackOverflowError'>Using -Xss to adjust Java default thread stack size to save memory and prevent StackOverflowError</a></li>
<li><a href='http://www.onkarjoshi.com/blog/219/volatile-array/' rel='bookmark' title='Atomic array classes and volatile arrays in the JVM'>Atomic array classes and volatile arrays in the JVM</a></li>
</ol></p>
</div>
<img src="http://feeds.feedburner.com/~r/onkarjoshi/~4/OVEAwn9RPB8" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.onkarjoshi.com/blog/247/heap-dump-of-a-running-jvm-with-jmap/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		<feedburner:origLink>http://www.onkarjoshi.com/blog/247/heap-dump-of-a-running-jvm-with-jmap/</feedburner:origLink></item>
		<item>
		<title>Java – The 4 inner/nested class types</title>
		<link>http://feedproxy.google.com/~r/onkarjoshi/~3/xkjFoMU7pCs/</link>
		<comments>http://www.onkarjoshi.com/blog/246/java-the-4-innernested-class-types/#comments</comments>
		<pubDate>Thu, 12 Jan 2012 23:08:35 +0000</pubDate>
		<dc:creator>Onkar Joshi</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Java]]></category>

		<guid isPermaLink="false">http://www.onkarjoshi.com/blog/?p=246</guid>
		<description><![CDATA[If you are trying to clear your thoughts around just how many different types of inner/nested classes there are in Java, this should be a quick refresher. All but the first kind are known as inner classes. Static member classes &#8211; These will not hold on to a reference to the enclosing class. You do [...]<div class='yarpp-related-rss'>

Related posts:<ol>
<li><a href='http://www.onkarjoshi.com/blog/133/how-to-use-a-patch-jar-to-override-existing-java-class-files-temporarily/' rel='bookmark' title='How to use a patch jar to override existing Java class files temporarily'>How to use a patch jar to override existing Java class files temporarily</a></li>
<li><a href='http://www.onkarjoshi.com/blog/186/garbage-collection-and-reachability-strong-soft-weak-phantom-unreachable/' rel='bookmark' title='Garbage Collection, Reference types and Reachability &#8211; Strong, Soft, Weak, Phantom, Unreachable'>Garbage Collection, Reference types and Reachability &#8211; Strong, Soft, Weak, Phantom, Unreachable</a></li>
<li><a href='http://www.onkarjoshi.com/blog/92/compiling-cyclic-dependency-in-java/' rel='bookmark' title='Compiling cyclic dependency in Java'>Compiling cyclic dependency in Java</a></li>
<li><a href='http://www.onkarjoshi.com/blog/178/spring-transaction-advice-aop-proxy-vs-aspectj-weaving/' rel='bookmark' title='Spring Transaction advice : AOP proxy vs AspectJ weaving'>Spring Transaction advice : AOP proxy vs AspectJ weaving</a></li>
<li><a href='http://www.onkarjoshi.com/blog/244/double-braces-initialization-in-java/' rel='bookmark' title='Double braces initialization in Java'>Double braces initialization in Java</a></li>
</ol>
</div>
]]></description>
				<content:encoded><![CDATA[<p style="text-align: justify;">If you are trying to clear your thoughts around just how many different types of inner/nested classes there are in Java, this should be a quick refresher. All but the first kind are known as inner classes.</p>
<p style="text-align: justify;"><span style="font-size: large;">Static member classes</span> &#8211; These will not hold on to a reference to the enclosing class. You do not need a reference to the enclosing class to instantiate this. This one is not really an inner class.</p>
<p style="text-align: justify;"><span style="font-size: large;">Non static member classes</span> &#8211; These will hold on to a reference to the object of the enclosing class. Beware of leaks and concurrency issues. Always make it a static member class if you don&#8217;t use anything from the enclosing instance.</p>
<p style="text-align: justify;"><span style="font-size: large;">Anonymous classes</span> &#8211; Good for one off use cases. Can reduce code readability if they get too large. Can be a bit more difficult to unit test.</p>
<p style="text-align: justify;"><span style="font-size: large;">Local classes</span> &#8211; A class that is local to a method/block. Not used too often. Holds a reference to the enclosing instance.</p>
<div class='yarpp-related-rss'>
<p>Related posts:<ol>
<li><a href='http://www.onkarjoshi.com/blog/133/how-to-use-a-patch-jar-to-override-existing-java-class-files-temporarily/' rel='bookmark' title='How to use a patch jar to override existing Java class files temporarily'>How to use a patch jar to override existing Java class files temporarily</a></li>
<li><a href='http://www.onkarjoshi.com/blog/186/garbage-collection-and-reachability-strong-soft-weak-phantom-unreachable/' rel='bookmark' title='Garbage Collection, Reference types and Reachability &#8211; Strong, Soft, Weak, Phantom, Unreachable'>Garbage Collection, Reference types and Reachability &#8211; Strong, Soft, Weak, Phantom, Unreachable</a></li>
<li><a href='http://www.onkarjoshi.com/blog/92/compiling-cyclic-dependency-in-java/' rel='bookmark' title='Compiling cyclic dependency in Java'>Compiling cyclic dependency in Java</a></li>
<li><a href='http://www.onkarjoshi.com/blog/178/spring-transaction-advice-aop-proxy-vs-aspectj-weaving/' rel='bookmark' title='Spring Transaction advice : AOP proxy vs AspectJ weaving'>Spring Transaction advice : AOP proxy vs AspectJ weaving</a></li>
<li><a href='http://www.onkarjoshi.com/blog/244/double-braces-initialization-in-java/' rel='bookmark' title='Double braces initialization in Java'>Double braces initialization in Java</a></li>
</ol></p>
</div>
<img src="http://feeds.feedburner.com/~r/onkarjoshi/~4/xkjFoMU7pCs" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.onkarjoshi.com/blog/246/java-the-4-innernested-class-types/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.onkarjoshi.com/blog/246/java-the-4-innernested-class-types/</feedburner:origLink></item>
		<item>
		<title>Double braces initialization in Java</title>
		<link>http://feedproxy.google.com/~r/onkarjoshi/~3/JPXVzZDEwKk/</link>
		<comments>http://www.onkarjoshi.com/blog/244/double-braces-initialization-in-java/#comments</comments>
		<pubDate>Sun, 08 Jan 2012 19:12:40 +0000</pubDate>
		<dc:creator>Onkar Joshi</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Java]]></category>

		<guid isPermaLink="false">http://www.onkarjoshi.com/blog/?p=244</guid>
		<description><![CDATA[This little trick is not very well known and can look like completely new syntax to the uninitiated. But it is actually a form of something you use quite frequently &#8211; anonymous inner classes. // Normal list initialization List&#60;String&#62; days1 = new ArrayList&#60;String&#62;(); days1.add(&#34;Sun&#34;); days1.add(&#34;Mon&#34;); days1.add(&#34;Tue&#34;); // Double braces initialization. Compact! List&#60;String&#62; days2 = new [...]<div class='yarpp-related-rss'>

Related posts:<ol>
<li><a href='http://www.onkarjoshi.com/blog/104/sun-jdk-7-released/' rel='bookmark' title='Sun JDK 7 released'>Sun JDK 7 released</a></li>
</ol>
</div>
]]></description>
				<content:encoded><![CDATA[<p>This little trick is not very well known and can look like completely new syntax to the uninitiated.</p>
<p>But it is actually a form of something you use quite frequently &#8211; anonymous inner classes.</p>
<pre class="brush: java; gutter: true">		
		// Normal list initialization
		List&lt;String&gt; days1 = new ArrayList&lt;String&gt;();
		days1.add(&quot;Sun&quot;);
		days1.add(&quot;Mon&quot;);
		days1.add(&quot;Tue&quot;);

		// Double braces initialization. Compact!
		List&lt;String&gt; days2 = new ArrayList&lt;String&gt;() {{
			add(&quot;Sun&quot;);
			add(&quot;Mon&quot;);
			add(&quot;Tue&quot;);
		}};</pre>
<p>My suggestion is to NOT use it because it can cause serialization warnings and is just too unfamiliar for most Java developers. When in doubt, favour clarity!</p>
<div class='yarpp-related-rss'>
<p>Related posts:<ol>
<li><a href='http://www.onkarjoshi.com/blog/104/sun-jdk-7-released/' rel='bookmark' title='Sun JDK 7 released'>Sun JDK 7 released</a></li>
</ol></p>
</div>
<img src="http://feeds.feedburner.com/~r/onkarjoshi/~4/JPXVzZDEwKk" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.onkarjoshi.com/blog/244/double-braces-initialization-in-java/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		<feedburner:origLink>http://www.onkarjoshi.com/blog/244/double-braces-initialization-in-java/</feedburner:origLink></item>
		<item>
		<title>Find duplicate files</title>
		<link>http://feedproxy.google.com/~r/onkarjoshi/~3/RBZ5XqFsITA/</link>
		<comments>http://www.onkarjoshi.com/blog/241/find-duplicate-files/#comments</comments>
		<pubDate>Sun, 08 Jan 2012 12:28:10 +0000</pubDate>
		<dc:creator>Onkar Joshi</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[shell]]></category>
		<category><![CDATA[Unix]]></category>

		<guid isPermaLink="false">http://www.onkarjoshi.com/blog/?p=241</guid>
		<description><![CDATA[So you know you have a bunch of files all with similar content but different file names strewn all over a directory tree. How would you identify the repetitions so that you can work towards eliminating them? Here is some CLI magic that helps you do so (sourced from CommandLineFu). find -not -empty -type f [...]<div class='yarpp-related-rss'>

Related posts:<ol>
<li><a href='http://www.onkarjoshi.com/blog/197/use-binary-diff-tools-like-xdelta-bsdiff-bspatch-to-transfer-large-files/' rel='bookmark' title='Use binary diff tools like xdelta, bsdiff/bspatch to transfer large files'>Use binary diff tools like xdelta, bsdiff/bspatch to transfer large files</a></li>
<li><a href='http://www.onkarjoshi.com/blog/119/check-for-corruption-of-files-using-md5-checksum-via-md5sum-or-winmd5/' rel='bookmark' title='Check for corruption of files using md5 checksum'>Check for corruption of files using md5 checksum</a></li>
<li><a href='http://www.onkarjoshi.com/blog/133/how-to-use-a-patch-jar-to-override-existing-java-class-files-temporarily/' rel='bookmark' title='How to use a patch jar to override existing Java class files temporarily'>How to use a patch jar to override existing Java class files temporarily</a></li>
</ol>
</div>
]]></description>
				<content:encoded><![CDATA[<p>So you know you have a bunch of files all with similar content but different file names strewn all over a directory tree. How would you identify the repetitions so that you can work towards eliminating them?</p>
<p>Here is some CLI magic that helps you do so (sourced <a href="http://www.commandlinefu.com/commands/view/3555/find-duplicate-files-based-on-size-first-then-md5-hash">from CommandLineFu</a>).</p>
<p style="font-family: Courier New,Courier,mono;">find -not -empty -type f -printf &#8220;%s\n&#8221; | sort -rn | uniq -d | xargs -I{} -n1 find -type f -size {}c -print0 | xargs -0 md5sum | sort | uniq -w32 &#8211;all-repeated=separate</p>
<p>The first column is the md5 hash and the second is the full path. The rows are grouped by files with similar content and separated by a line per group.</p>
<p>Oh, so beautiful! Use effectively to eliminate code and test smell from your project!</p>
<div class='yarpp-related-rss'>
<p>Related posts:<ol>
<li><a href='http://www.onkarjoshi.com/blog/197/use-binary-diff-tools-like-xdelta-bsdiff-bspatch-to-transfer-large-files/' rel='bookmark' title='Use binary diff tools like xdelta, bsdiff/bspatch to transfer large files'>Use binary diff tools like xdelta, bsdiff/bspatch to transfer large files</a></li>
<li><a href='http://www.onkarjoshi.com/blog/119/check-for-corruption-of-files-using-md5-checksum-via-md5sum-or-winmd5/' rel='bookmark' title='Check for corruption of files using md5 checksum'>Check for corruption of files using md5 checksum</a></li>
<li><a href='http://www.onkarjoshi.com/blog/133/how-to-use-a-patch-jar-to-override-existing-java-class-files-temporarily/' rel='bookmark' title='How to use a patch jar to override existing Java class files temporarily'>How to use a patch jar to override existing Java class files temporarily</a></li>
</ol></p>
</div>
<img src="http://feeds.feedburner.com/~r/onkarjoshi/~4/RBZ5XqFsITA" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.onkarjoshi.com/blog/241/find-duplicate-files/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.onkarjoshi.com/blog/241/find-duplicate-files/</feedburner:origLink></item>
		<item>
		<title>Eclipse jsp jstl error – Cannot find the tag library descriptor for http://java.sun.com/jsp/jstl/core</title>
		<link>http://feedproxy.google.com/~r/onkarjoshi/~3/t1FOr3_g7UY/</link>
		<comments>http://www.onkarjoshi.com/blog/239/eclipse-jsp-jstl-error-cannot-find-the-tag-library-descriptor/#comments</comments>
		<pubDate>Sun, 08 Jan 2012 06:43:29 +0000</pubDate>
		<dc:creator>Onkar Joshi</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Eclipse]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[jsp]]></category>
		<category><![CDATA[Maven]]></category>

		<guid isPermaLink="false">http://www.onkarjoshi.com/blog/?p=239</guid>
		<description><![CDATA[You get that error for the missing tld when standard.jar and jstl.jar are not found. If you are using maven, adding the following should fix it. &#60;!&#8211; standard.jar &#8211;&#62; &#60;dependency&#62; &#60;groupId&#62;taglibs&#60;/groupId&#62; &#60;artifactId&#62;standard&#60;/artifactId&#62; &#60;version&#62;1.1.2&#60;/version&#62; &#60;/dependency&#62; &#60;!&#8211; JSTL &#8211;&#62; &#60;dependency&#62; &#60;groupId&#62;javax.servlet&#60;/groupId&#62; &#60;artifactId&#62;jstl&#60;/artifactId&#62; &#60;version&#62;1.1.2&#60;/version&#62; &#60;/dependency&#62; Try restarting Eclipse if the error doesn&#8217;t go away after adding this. Do [...]<div class='yarpp-related-rss'>

Related posts:<ol>
<li><a href='http://www.onkarjoshi.com/blog/234/maven-dependency-local-jar-file-from-an-external-third-party-to-be-installed-into-project-repository/' rel='bookmark' title='Maven dependency &#8211; Local jar file from an external third party to be installed into project repository'>Maven dependency &#8211; Local jar file from an external third party to be installed into project repository</a></li>
<li><a href='http://www.onkarjoshi.com/blog/84/configuring-eclipse-to-use-a-jdk-at-a-location-with-spaces-in-it/' rel='bookmark' title='Configuring Eclipse to use a JDK at a location with spaces in it'>Configuring Eclipse to use a JDK at a location with spaces in it</a></li>
<li><a href='http://www.onkarjoshi.com/blog/159/conditional-breakpoints-in-java-development-with-eclipse/' rel='bookmark' title='Conditional breakpoints in Java development with Eclipse'>Conditional breakpoints in Java development with Eclipse</a></li>
<li><a href='http://www.onkarjoshi.com/blog/133/how-to-use-a-patch-jar-to-override-existing-java-class-files-temporarily/' rel='bookmark' title='How to use a patch jar to override existing Java class files temporarily'>How to use a patch jar to override existing Java class files temporarily</a></li>
<li><a href='http://www.onkarjoshi.com/blog/92/compiling-cyclic-dependency-in-java/' rel='bookmark' title='Compiling cyclic dependency in Java'>Compiling cyclic dependency in Java</a></li>
</ol>
</div>
]]></description>
				<content:encoded><![CDATA[<p>You get that error for the missing tld when standard.jar and jstl.jar are not found. If you are using maven, adding the following should fix it.</p>
<p>&lt;!&#8211; standard.jar &#8211;&gt;<br />
&lt;dependency&gt;<br />
&lt;groupId&gt;taglibs&lt;/groupId&gt;<br />
&lt;artifactId&gt;standard&lt;/<wbr>artifactId&gt;<br />
&lt;version&gt;1.1.2&lt;/version&gt;<br />
&lt;/dependency&gt;</wbr></p>
<p>&lt;!&#8211; JSTL &#8211;&gt;<br />
&lt;dependency&gt;<br />
&lt;groupId&gt;javax.servlet&lt;/groupId&gt;<br />
&lt;artifactId&gt;jstl&lt;/artifactId&gt;<br />
&lt;version&gt;1.1.2&lt;/version&gt;<br />
&lt;/dependency&gt;</p>
<p>Try restarting Eclipse if the error doesn&#8217;t go away after adding this.</p>
<p>Do drop me a comment if this or something else works for you!<br />
<wbr></wbr></p>
<div class='yarpp-related-rss'>
<p>Related posts:<ol>
<li><a href='http://www.onkarjoshi.com/blog/234/maven-dependency-local-jar-file-from-an-external-third-party-to-be-installed-into-project-repository/' rel='bookmark' title='Maven dependency &#8211; Local jar file from an external third party to be installed into project repository'>Maven dependency &#8211; Local jar file from an external third party to be installed into project repository</a></li>
<li><a href='http://www.onkarjoshi.com/blog/84/configuring-eclipse-to-use-a-jdk-at-a-location-with-spaces-in-it/' rel='bookmark' title='Configuring Eclipse to use a JDK at a location with spaces in it'>Configuring Eclipse to use a JDK at a location with spaces in it</a></li>
<li><a href='http://www.onkarjoshi.com/blog/159/conditional-breakpoints-in-java-development-with-eclipse/' rel='bookmark' title='Conditional breakpoints in Java development with Eclipse'>Conditional breakpoints in Java development with Eclipse</a></li>
<li><a href='http://www.onkarjoshi.com/blog/133/how-to-use-a-patch-jar-to-override-existing-java-class-files-temporarily/' rel='bookmark' title='How to use a patch jar to override existing Java class files temporarily'>How to use a patch jar to override existing Java class files temporarily</a></li>
<li><a href='http://www.onkarjoshi.com/blog/92/compiling-cyclic-dependency-in-java/' rel='bookmark' title='Compiling cyclic dependency in Java'>Compiling cyclic dependency in Java</a></li>
</ol></p>
</div>
<img src="http://feeds.feedburner.com/~r/onkarjoshi/~4/t1FOr3_g7UY" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.onkarjoshi.com/blog/239/eclipse-jsp-jstl-error-cannot-find-the-tag-library-descriptor/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		<feedburner:origLink>http://www.onkarjoshi.com/blog/239/eclipse-jsp-jstl-error-cannot-find-the-tag-library-descriptor/</feedburner:origLink></item>
		<item>
		<title>Vi – Disable wrapping</title>
		<link>http://feedproxy.google.com/~r/onkarjoshi/~3/pWjqKc_DtCg/</link>
		<comments>http://www.onkarjoshi.com/blog/237/vi-disable-wrapping/#comments</comments>
		<pubDate>Sun, 08 Jan 2012 01:22:00 +0000</pubDate>
		<dc:creator>Onkar Joshi</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[shell]]></category>
		<category><![CDATA[Unix]]></category>
		<category><![CDATA[vi]]></category>

		<guid isPermaLink="false">http://www.onkarjoshi.com/blog/?p=237</guid>
		<description><![CDATA[So your neatly formatted csv file looks all ugly in vi because your screen isn&#8217;t wide enough? [Esc]:set nowrap[Enter] There, that will disable wrapping and your file will make sense once again.<div class='yarpp-related-rss yarpp-related-none'>

No related posts.
</div>
]]></description>
				<content:encoded><![CDATA[<p>So your neatly formatted csv file looks all ugly in vi because your screen isn&#8217;t wide enough?</p>
<p>[Esc]:set nowrap[Enter]</p>
<p>There, that will disable wrapping and your file will make sense once again.</p>
<div class='yarpp-related-rss yarpp-related-none'>
<p>No related posts.</p>
</div>
<img src="http://feeds.feedburner.com/~r/onkarjoshi/~4/pWjqKc_DtCg" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.onkarjoshi.com/blog/237/vi-disable-wrapping/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.onkarjoshi.com/blog/237/vi-disable-wrapping/</feedburner:origLink></item>
		<item>
		<title>MySql on a RAM disk for super fast performance with the innodb storage engine</title>
		<link>http://feedproxy.google.com/~r/onkarjoshi/~3/NhwUMGY0dtA/</link>
		<comments>http://www.onkarjoshi.com/blog/235/mysql-on-a-ram-disk-for-super-fast-performance-with-the-innodb-storage-engine/#comments</comments>
		<pubDate>Sat, 07 Jan 2012 19:55:40 +0000</pubDate>
		<dc:creator>Onkar Joshi</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[MySql]]></category>
		<category><![CDATA[Performance]]></category>

		<guid isPermaLink="false">http://www.onkarjoshi.com/blog/?p=235</guid>
		<description><![CDATA[In a development environment, having a super fast database can be immensely helpful. If you are not lucky enough to already have an SSD in your system, you need to make yourself a RAMDisk. I had a system with 6 gig of RAM. I allocated 500 meg for a RAM Disk. You can create one [...]<div class='yarpp-related-rss yarpp-related-none'>

No related posts.
</div>
]]></description>
				<content:encoded><![CDATA[<p style="text-align: justify;">In a development environment, having a super fast database can be immensely helpful. If you are not lucky enough to already have an SSD in your system, you need to make yourself a RAMDisk.</p>
<p style="text-align: justify;">I had a system with 6 gig of RAM. I allocated 500 meg for a RAM Disk. You can create one with one of the <a href="http://www.raymond.cc/blog/12-ram-disk-software-benchmarked-for-fastest-read-and-write-speed/" target="_blank">several RAMDisk programs</a> out there. There are few which are freeware as well.</p>
<p style="text-align: justify;">In MySql, you&#8217;ll need to edit your my.cnf to use data files located in a folder on the RAM Drive. Stop your DB, copy the existing DB files to the folder in the RAM Drive. The edited my.cnf should point to this folder. That&#8217;s all.</p>
<p style="text-align: justify;">Note that you could also use a different storage engine &#8211; but that changes how the database works with respect to transactions and probably other things so I wouldn&#8217;t recommend this.</p>
<p style="text-align: justify;">I managed to cut down DB build time from around 2 minutes to under 10 seconds!</p>
<p style="text-align: justify;">I was also able to reveal a ConcurrentModificationExceptio<wbr>n thanks to the DB/disk not being a bottleneck anymore when running some stress tests.</wbr></p>
<p style="text-align: justify;">Go, give it a try today!</p>
<div class='yarpp-related-rss yarpp-related-none'>
<p>No related posts.</p>
</div>
<img src="http://feeds.feedburner.com/~r/onkarjoshi/~4/NhwUMGY0dtA" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.onkarjoshi.com/blog/235/mysql-on-a-ram-disk-for-super-fast-performance-with-the-innodb-storage-engine/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		<feedburner:origLink>http://www.onkarjoshi.com/blog/235/mysql-on-a-ram-disk-for-super-fast-performance-with-the-innodb-storage-engine/</feedburner:origLink></item>
		<item>
		<title>Maven dependency – Local jar file from an external third party to be installed into project repository</title>
		<link>http://feedproxy.google.com/~r/onkarjoshi/~3/o4KcQIwbWZU/</link>
		<comments>http://www.onkarjoshi.com/blog/234/maven-dependency-local-jar-file-from-an-external-third-party-to-be-installed-into-project-repository/#comments</comments>
		<pubDate>Sat, 07 Jan 2012 13:50:50 +0000</pubDate>
		<dc:creator>Onkar Joshi</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Maven]]></category>

		<guid isPermaLink="false">http://www.onkarjoshi.com/blog/?p=234</guid>
		<description><![CDATA[Some time back, I was working on an application that involved payments processing. I worked with a payments company called DataCash. They made available a jar file with their API. Now the app I was working on used Maven for dependency management. Usually, if one needs an API to be included for use in the [...]<div class='yarpp-related-rss'>

Related posts:<ol>
<li><a href='http://www.onkarjoshi.com/blog/133/how-to-use-a-patch-jar-to-override-existing-java-class-files-temporarily/' rel='bookmark' title='How to use a patch jar to override existing Java class files temporarily'>How to use a patch jar to override existing Java class files temporarily</a></li>
<li><a href='http://www.onkarjoshi.com/blog/205/type-inference-generics-magic-for-initializing-collections-in-every-project/' rel='bookmark' title='Type inference &#8211; Generics magic for initializing collections in every project'>Type inference &#8211; Generics magic for initializing collections in every project</a></li>
<li><a href='http://www.onkarjoshi.com/blog/125/how-to-create-a-file-of-arbitrary-size-with-fsutil-in-windows-xp/' rel='bookmark' title='How to create a file of arbitrary size with fsutil in Windows XP'>How to create a file of arbitrary size with fsutil in Windows XP</a></li>
<li><a href='http://www.onkarjoshi.com/blog/126/which-library-to-use-for-ftp-sftp-ftps-file-transfer-in-java/' rel='bookmark' title='Which library to use for FTP, SFTP, FTPS file transfer in Java?'>Which library to use for FTP, SFTP, FTPS file transfer in Java?</a></li>
<li><a href='http://www.onkarjoshi.com/blog/112/wildcard-in-java-classpath/' rel='bookmark' title='Wildcard in Java classpath'>Wildcard in Java classpath</a></li>
</ol>
</div>
]]></description>
				<content:encoded><![CDATA[<p style="text-align: justify;">Some time back, I was working on an application that involved payments processing. I worked with a payments company called DataCash. They made available a jar file with their API. Now the app I was working on used Maven for dependency management. Usually, if one needs an API to be included for use in the app, one would just add it into the maven pom.xml file in an appropriate location in the dependencies or dependenciesManagement section. However, this api-jar was not something that was publicly acessible.</p>
<p style="text-align: justify;">Sure, you could drop the jar into your localRepository while you work on it initially. But when you commit your code, the project repository still won&#8217;t have it. So others on your team would get a missing dependency error.</p>
<p style="text-align: justify;">What you really need to do is to deploy the jar into your project repository. Here is what should work to do this -</p>
<p style="text-align: left;">mvn deploy:deploy-file -DgroupId=com.datacash -DartifactId=datacash-api -Dversion=2.1.1 -Dpackaging=jar -Dfile=DataCash-Java-2.1.1.jar -Durl=http://<wbr>yourteamdevserver:8081/artifactory/libs-snapshots -DrepositoryId=snapshots</wbr></p>
<p style="text-align: justify;">You can use any appropriate groupId and artifactId. Tools like Artifactory also have a web UI to install jars.</p>
<p>Do leave a comment if this or something else that you tried worked for you!<br />
<wbr></wbr></p>
<div class='yarpp-related-rss'>
<p>Related posts:<ol>
<li><a href='http://www.onkarjoshi.com/blog/133/how-to-use-a-patch-jar-to-override-existing-java-class-files-temporarily/' rel='bookmark' title='How to use a patch jar to override existing Java class files temporarily'>How to use a patch jar to override existing Java class files temporarily</a></li>
<li><a href='http://www.onkarjoshi.com/blog/205/type-inference-generics-magic-for-initializing-collections-in-every-project/' rel='bookmark' title='Type inference &#8211; Generics magic for initializing collections in every project'>Type inference &#8211; Generics magic for initializing collections in every project</a></li>
<li><a href='http://www.onkarjoshi.com/blog/125/how-to-create-a-file-of-arbitrary-size-with-fsutil-in-windows-xp/' rel='bookmark' title='How to create a file of arbitrary size with fsutil in Windows XP'>How to create a file of arbitrary size with fsutil in Windows XP</a></li>
<li><a href='http://www.onkarjoshi.com/blog/126/which-library-to-use-for-ftp-sftp-ftps-file-transfer-in-java/' rel='bookmark' title='Which library to use for FTP, SFTP, FTPS file transfer in Java?'>Which library to use for FTP, SFTP, FTPS file transfer in Java?</a></li>
<li><a href='http://www.onkarjoshi.com/blog/112/wildcard-in-java-classpath/' rel='bookmark' title='Wildcard in Java classpath'>Wildcard in Java classpath</a></li>
</ol></p>
</div>
<img src="http://feeds.feedburner.com/~r/onkarjoshi/~4/o4KcQIwbWZU" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.onkarjoshi.com/blog/234/maven-dependency-local-jar-file-from-an-external-third-party-to-be-installed-into-project-repository/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		<feedburner:origLink>http://www.onkarjoshi.com/blog/234/maven-dependency-local-jar-file-from-an-external-third-party-to-be-installed-into-project-repository/</feedburner:origLink></item>
		<item>
		<title>Time portion from your Date / DateTime / Timestamp field getting truncated when using the JDBC ResultSet?</title>
		<link>http://feedproxy.google.com/~r/onkarjoshi/~3/DPIZ6cmhWCs/</link>
		<comments>http://www.onkarjoshi.com/blog/232/time-portion-from-your-date-datetime-timestamp-field-getting-truncated-when-using-the-jdbc-resultset/#comments</comments>
		<pubDate>Thu, 26 May 2011 18:30:53 +0000</pubDate>
		<dc:creator>Onkar Joshi</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Java]]></category>

		<guid isPermaLink="false">http://www.onkarjoshi.com/blog/?p=232</guid>
		<description><![CDATA[Problem &#8211; You see that from Date-Time value you are saving into your database, the time part is getting truncated at some point. What on earth is happening? You may notice that if you look at the field in your database, you do see the time being persisted. So infact, it is something you are [...]<div class='yarpp-related-rss'>

Related posts:<ol>
<li><a href='http://www.onkarjoshi.com/blog/89/shaadi-waste-of-time-infolinks-ad/' rel='bookmark' title='Shaadi.com is a waste of time'>Shaadi.com is a waste of time</a></li>
</ol>
</div>
]]></description>
				<content:encoded><![CDATA[<p style="text-align: justify;">Problem &#8211; You see that from Date-Time value you are  saving into your database, the time part is getting truncated at some point. What on  earth is happening?</p>
<p style="text-align: justify;">You may notice that if you look at the field  in your database, you do see the time being persisted. So infact, it is  something you are doing wrong when retrieving the field from the DB.</p>
<p style="text-align: justify;">The reason why this problem occurs is in part because of poor API design.</p>
<pre>/*
* What do you think this code does?
*/
Date date = resultSet.getDate("my_date_field");</pre>
<p style="text-align: justify;">What  doesn&#8217;t strike most developers right away is that resultSet.getDate  returns a java.sql.Date. And that java.sql.Date extends java.util.Date!</p>
<p style="text-align: justify;">By  definition, a java.sql.Date has only Date &#8211; no time! But it is  assignable to a java.util.Date which is the norm in typical application  code. That&#8217;s where your time part probably gets eaten up due to an  incorrect getter for the JDBC resultSet.</p>
<p style="text-align: justify;">Similarly, java.sql.Time  is returned by resultSet.getTime. It can be assigned to a  java.sql.Date. In this case, it is the date part that tends to  mysteriously disappear.</p>
<p>If you want to do this right -</p>
<ul>
<li style="text-align: justify;">Make sure you know what your DB uses for the column &#8211; a TIMESTAMP field or a DATETIME field or a DATE field.</li>
<li style="text-align: justify;">Use  the right getter from the ResultSet class &#8211; Date, Time and Timestamp  are all compatible with java.util.Date but only Timestamp contains the  date as well as the time.</li>
<li style="text-align: justify;">Use the correct setter when saving data to your DB as well.</li>
</ul>
<p style="text-align: justify;">While we are on the topic of dealing with Date and Time in Java, have you considered ditching the primitive Java Date / Calendar API and adopting <a href="http://joda-time.sourceforge.net/" target="_blank">Joda-Time</a> instead? If you are at an early stage in your project, that is something you definitely need to look at.</p>
<div class='yarpp-related-rss'>
<p>Related posts:<ol>
<li><a href='http://www.onkarjoshi.com/blog/89/shaadi-waste-of-time-infolinks-ad/' rel='bookmark' title='Shaadi.com is a waste of time'>Shaadi.com is a waste of time</a></li>
</ol></p>
</div>
<img src="http://feeds.feedburner.com/~r/onkarjoshi/~4/DPIZ6cmhWCs" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.onkarjoshi.com/blog/232/time-portion-from-your-date-datetime-timestamp-field-getting-truncated-when-using-the-jdbc-resultset/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		<feedburner:origLink>http://www.onkarjoshi.com/blog/232/time-portion-from-your-date-datetime-timestamp-field-getting-truncated-when-using-the-jdbc-resultset/</feedburner:origLink></item>
		<item>
		<title>Sending a SIGBREAK signal to a Java process to do a thread dump in Windows</title>
		<link>http://feedproxy.google.com/~r/onkarjoshi/~3/yazaoJNess4/</link>
		<comments>http://www.onkarjoshi.com/blog/230/sending-a-sigbreak-signal-to-a-java-process-to-do-a-thread-dump-in-windows/#comments</comments>
		<pubDate>Thu, 26 May 2011 17:33:54 +0000</pubDate>
		<dc:creator>Onkar Joshi</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Debugging]]></category>
		<category><![CDATA[Java]]></category>

		<guid isPermaLink="false">http://www.onkarjoshi.com/blog/?p=230</guid>
		<description><![CDATA[In Linux / Unix if you want a Java process to do a thread dump, you can do a kill -3 &#60;pid&#62;. In Windows, doing the equivalent requires sending a Ctrl+Break to the input console which results in a SIGBREAK being sent to the process. But what if you do not have an input console? [...]<div class='yarpp-related-rss'>

Related posts:<ol>
<li><a href='http://www.onkarjoshi.com/blog/247/heap-dump-of-a-running-jvm-with-jmap/' rel='bookmark' title='Heap dump of a running JVM with jmap'>Heap dump of a running JVM with jmap</a></li>
<li><a href='http://www.onkarjoshi.com/blog/156/mcafee-anti-virus-mcshield-exe-process-eats-100-cpu-too-often/' rel='bookmark' title='McAfee anti virus mcshield.exe process eats 100% CPU too often'>McAfee anti virus mcshield.exe process eats 100% CPU too often</a></li>
<li><a href='http://www.onkarjoshi.com/blog/166/identifying-a-thread-with-high-cpu-usage-in-a-java-app/' rel='bookmark' title='Identifying a thread with high CPU usage in a Java app'>Identifying a thread with high CPU usage in a Java app</a></li>
<li><a href='http://www.onkarjoshi.com/blog/121/kaspersky-ate-my-jconsole/' rel='bookmark' title='Kaspersky ate my jconsole!'>Kaspersky ate my jconsole!</a></li>
<li><a href='http://www.onkarjoshi.com/blog/209/using-xss-to-adjust-java-default-thread-stack-size-to-save-memory-and-prevent-stackoverflowerror/' rel='bookmark' title='Using -Xss to adjust Java default thread stack size to save memory and prevent StackOverflowError'>Using -Xss to adjust Java default thread stack size to save memory and prevent StackOverflowError</a></li>
</ol>
</div>
]]></description>
				<content:encoded><![CDATA[<p style="text-align: justify;">In Linux / Unix if you want a Java process to do a thread dump, you can do a kill -3 &lt;pid&gt;.</p>
<p style="text-align: justify;">In  Windows, doing the equivalent requires sending a Ctrl+Break to the  input console which results in a SIGBREAK being sent to the process. But  what if you do not have an input console? A process started with  javaw.exe like what Eclipse does has no input console where you can type in the Ctrl+Break.</p>
<p style="text-align: justify;">So, if you have a running java process without an input console, how do you make it do a thread dump?</p>
<p style="text-align: justify;">The answer is simple &#8211; use a utility called SendSignal. Very cleverly written stuff. The author&#8217;s description of<a href="http://www.latenighthacking.com/projects/2003/sendSignal/"> how he wrote that</a> and some other utilities as part of his Windows programming interests is a nice read.</p>
<p style="text-align: justify;">So, download SendSignal and keep it handy as part of your developer arsenal.</p>
<p style="text-align: justify;"><em>SendSignal.exe &lt;pid&gt;</em> will send a ctrl+break to the process. This will cause a Java process to do a stack dump to stdout.</p>
<p style="text-align: justify;">There are other ways too. Those are for another post. <img src='http://www.onkarjoshi.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<div class='yarpp-related-rss'>
<p>Related posts:<ol>
<li><a href='http://www.onkarjoshi.com/blog/247/heap-dump-of-a-running-jvm-with-jmap/' rel='bookmark' title='Heap dump of a running JVM with jmap'>Heap dump of a running JVM with jmap</a></li>
<li><a href='http://www.onkarjoshi.com/blog/156/mcafee-anti-virus-mcshield-exe-process-eats-100-cpu-too-often/' rel='bookmark' title='McAfee anti virus mcshield.exe process eats 100% CPU too often'>McAfee anti virus mcshield.exe process eats 100% CPU too often</a></li>
<li><a href='http://www.onkarjoshi.com/blog/166/identifying-a-thread-with-high-cpu-usage-in-a-java-app/' rel='bookmark' title='Identifying a thread with high CPU usage in a Java app'>Identifying a thread with high CPU usage in a Java app</a></li>
<li><a href='http://www.onkarjoshi.com/blog/121/kaspersky-ate-my-jconsole/' rel='bookmark' title='Kaspersky ate my jconsole!'>Kaspersky ate my jconsole!</a></li>
<li><a href='http://www.onkarjoshi.com/blog/209/using-xss-to-adjust-java-default-thread-stack-size-to-save-memory-and-prevent-stackoverflowerror/' rel='bookmark' title='Using -Xss to adjust Java default thread stack size to save memory and prevent StackOverflowError'>Using -Xss to adjust Java default thread stack size to save memory and prevent StackOverflowError</a></li>
</ol></p>
</div>
<img src="http://feeds.feedburner.com/~r/onkarjoshi/~4/yazaoJNess4" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.onkarjoshi.com/blog/230/sending-a-sigbreak-signal-to-a-java-process-to-do-a-thread-dump-in-windows/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		<feedburner:origLink>http://www.onkarjoshi.com/blog/230/sending-a-sigbreak-signal-to-a-java-process-to-do-a-thread-dump-in-windows/</feedburner:origLink></item>
		<item>
		<title>Java NullPointerException Ninja – 10 facts you need to know to avoid problems with null</title>
		<link>http://feedproxy.google.com/~r/onkarjoshi/~3/8xxQsKuMAmA/</link>
		<comments>http://www.onkarjoshi.com/blog/228/java-nullpointerexception-ninja-10-facts-you-need-to-know-to-avoid-problems-with-null/#comments</comments>
		<pubDate>Tue, 24 May 2011 21:25:25 +0000</pubDate>
		<dc:creator>Onkar Joshi</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Java]]></category>

		<guid isPermaLink="false">http://www.onkarjoshi.com/blog/?p=228</guid>
		<description><![CDATA[1.The instanceof operator is NPE safe. So, instanceof null always returns false. It does not cause a NullPointerException. You can eliminate messy conditional code if you remember this fact. // Unncessary code if (data != null &#38;&#38; data instanceof InterestingData) { } // Less code. Better! if (data instanceof InterestingData) { } 2. A null [...]<div class='yarpp-related-rss yarpp-related-none'>

No related posts.
</div>
]]></description>
				<content:encoded><![CDATA[<p><span style="font-size: xx-large;">1.</span>The instanceof operator is NPE safe. So, instanceof null always returns false. It does not cause a NullPointerException. You can eliminate messy conditional code if you remember this fact.</p>
<pre>// Unncessary code
if (data != null &amp;&amp; data instanceof InterestingData) {

}

// Less code. Better!
if (data instanceof InterestingData) {

}</pre>
<p><span style="font-size: xx-large;">2.</span> A null can be cast to anything without causing a NullPointerException.</p>
<pre>// Not so good...
if (someReference == null) {
	return null;
}
else {
	return (SpecificReference) genericReference;
}

// Better.
return (SpecificReference) genericReference;</pre>
<p><span style="font-size: xx-large;">3.</span> Autoboxing / Unboxing can cause a NullPointerException on lines that can leave you confounded. This generally happens when a Long (a wrapper type) is passed or received as an argument for a long (a primitive type) parameter. So watch out for these when trying to figure out a stack trace that does not seem to make sense.</p>
<p><span style="font-size: xx-large;">4.</span> a &lt; b &#8211; This can result in a surprising NPE! This happens when wrapper types are being compared and one of them happens to be a null.</p>
<p><span style="font-size: xx-large;">5.</span> The equals() method should not be returning true when a null is passed to it. &#8211; The general contract of the equals method states that if null is passed to equals, false should be returned. Makes sure you do this in your code. It is easy to miss and cause a NPE instead.</p>
<p><span style="font-size: xx-large;">6.</span> While chained statements are nice to look at in the code, they are not NPE friendly. A single statement spead over several lines will give you the line number of the first line in the stacktrace regardless of where it occurs.</p>
<p><span style="font-size: xx-large;">7.</span> A reference to &#8220;this&#8221; can never be null. While it should be obvious, I have seen code that does a null check on this. Ack!</p>
<p><span style="font-size: xx-large;">8. </span>An awesome tip to avoid NPE is to return empty strings or empty collections rather than a null. Do this consistently across your app. You will note that a bucket load of null checks become unneeded if you do so.</p>
<p><span style="font-size: xx-large;">9.</span> You should put constraint checks at the beginning of your method so that the rest of your code does not have to deal with that possibility. So if someone passes in a null, things will break (IllegalArgumentException perhaps?) early in the stack rather than in some deeper location where the root problem will be difficult to identify. Aiming for fail fast behaviour is a good choice in most situations.</p>
<p>Or consider allowing a null pointer exception to happen if a null is passed in rather than check for a null and then doing nothing and returning. This is akin to swallowing an exception.</p>
<p><span style="font-size: xx-large;">10. </span>The next time someone says Java does not have pointers, ask them what causes a Null<span style="background-color: #ffff99; color: #ff0000;">Pointer</span>Exception. Watch their facial expression change as they protest.</p>
<p>Ok, ok. I know, Java references and C++ pointers are different animals. Yes, I know about arithmetic on pointers from C / C++. Oh yes, I know about the Unsafe class from Sun Java too. <img src='http://www.onkarjoshi.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p style="text-align: center;"><em><span style="font-size: medium;">Go ahead, Null Ninja! Apply these tips and push that cyclomatic complexity down, down, down!</span></em></p>
<div class='yarpp-related-rss yarpp-related-none'>
<p>No related posts.</p>
</div>
<img src="http://feeds.feedburner.com/~r/onkarjoshi/~4/8xxQsKuMAmA" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.onkarjoshi.com/blog/228/java-nullpointerexception-ninja-10-facts-you-need-to-know-to-avoid-problems-with-null/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		<feedburner:origLink>http://www.onkarjoshi.com/blog/228/java-nullpointerexception-ninja-10-facts-you-need-to-know-to-avoid-problems-with-null/</feedburner:origLink></item>
		<item>
		<title>Crash your JVM by killing the garbage collector!</title>
		<link>http://feedproxy.google.com/~r/onkarjoshi/~3/Pc-IO7SpeoQ/</link>
		<comments>http://www.onkarjoshi.com/blog/226/crash-your-jvm-by-killing-the-garbage-collector/#comments</comments>
		<pubDate>Tue, 24 May 2011 16:03:47 +0000</pubDate>
		<dc:creator>Onkar Joshi</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[JVM]]></category>

		<guid isPermaLink="false">http://www.onkarjoshi.com/blog/?p=226</guid>
		<description><![CDATA[My HotSpot 1.6.0_21 JVM crashes if the following code is run on it. And by &#8220;crashes&#8221;, I mean that the JVM crashes and leaves an hs_err_pid####.log file with the thread dump from the JVM itself &#8211; there is no exception from the application code. class Crash { public static void main(String[] args) { Object[] link [...]<div class='yarpp-related-rss'>

Related posts:<ol>
<li><a href='http://www.onkarjoshi.com/blog/209/using-xss-to-adjust-java-default-thread-stack-size-to-save-memory-and-prevent-stackoverflowerror/' rel='bookmark' title='Using -Xss to adjust Java default thread stack size to save memory and prevent StackOverflowError'>Using -Xss to adjust Java default thread stack size to save memory and prevent StackOverflowError</a></li>
<li><a href='http://www.onkarjoshi.com/blog/84/configuring-eclipse-to-use-a-jdk-at-a-location-with-spaces-in-it/' rel='bookmark' title='Configuring Eclipse to use a JDK at a location with spaces in it'>Configuring Eclipse to use a JDK at a location with spaces in it</a></li>
<li><a href='http://www.onkarjoshi.com/blog/247/heap-dump-of-a-running-jvm-with-jmap/' rel='bookmark' title='Heap dump of a running JVM with jmap'>Heap dump of a running JVM with jmap</a></li>
<li><a href='http://www.onkarjoshi.com/blog/186/garbage-collection-and-reachability-strong-soft-weak-phantom-unreachable/' rel='bookmark' title='Garbage Collection, Reference types and Reachability &#8211; Strong, Soft, Weak, Phantom, Unreachable'>Garbage Collection, Reference types and Reachability &#8211; Strong, Soft, Weak, Phantom, Unreachable</a></li>
<li><a href='http://www.onkarjoshi.com/blog/174/hotspot-jvm-client-server-vm-optimization/' rel='bookmark' title='HotSpot JVM &#8211; Client / Server VM optimization &#8211; 260ms vs 0ms!'>HotSpot JVM &#8211; Client / Server VM optimization &#8211; 260ms vs 0ms!</a></li>
</ol>
</div>
]]></description>
				<content:encoded><![CDATA[<p style="text-align: justify;">My HotSpot 1.6.0_21 JVM crashes if the following code is run on it. And  by &#8220;crashes&#8221;, I mean that the JVM crashes and leaves an  hs_err_pid####.log file with the thread dump from the JVM itself &#8211; there  is no exception from the application code.</p>
<pre>class Crash {

	public static void main(String[] args) {

		Object[] link = null;

		while (true) {
			link = new Object[] { link };
		}

	}
}</pre>
<p style="text-align: justify;">What has happened here is that the deep chain of objects we have  allocated here causes a StackOverflow on what appears to be a recursive  call in the garbage collector.</p>
<p style="text-align: justify;">Usually such errors happen because  of misbehaving drivers. Perhaps your app uses a finger print scannner  or a printer or a scanner? Any JNI code going wrong causes this.</p>
<p style="text-align: justify;">A common pattern when dealing with native code in Java is to avoid  doing the calls in the main process of your application. Instead, have a  different process that does the dirty work via JNI and communicate with  that process via some mechanism &#8211; perhaps sockets. So if something goes  wrong in JNI, only that process with gets killed rather than the  entire app. Remember, with JNI exceptions, you get a dead JVM rather  than an exception. This is because there is no telling what a  misbehaving piece of native code may have done to the memory within a  process.</p>
<p style="text-align: justify;">My hs_err_pid####.log file -</p>
<pre>#
# A fatal error has been detected by the Java Runtime Environment:
#
#  EXCEPTION_STACK_OVERFLOW (0xc00000fd) at pc=0x6d8b99f0, pid=3780, tid=2232
#
# JRE version: 6.0_21-b07
# Java VM: Java HotSpot(TM) Client VM (17.0-b17 mixed mode, sharing windows-x86 )
# Problematic frame:
# V  [jvm.dll+0x99f0]
#
# If you would like to submit a bug report, please visit:
#   http://java.sun.com/webapps/bugreport/crash.jsp
#

---------------  T H R E A D  ---------------

Current thread (0x02b09c00):  VMThread [stack: 0x02bf0000,0x02c40000] [id=2232]

siginfo: ExceptionCode=0xc00000fd, ExceptionInformation=0x00000001 0x02bf2ffc 

Registers:
EAX=0x22e62fc4, EBX=0x22e62fc0, ECX=0x371bb3a0, EDX=0x00000001
ESP=0x02bf3000, EBP=0x02bf3014, ESI=0x22e62fc0, EDI=0x22e62fbc
EIP=0x6d8b99f0, EFLAGS=0x00010246

Top of Stack: (sp=0x02bf3000)
0x02bf3000:   6da2d162 22e62fc4 22e62fbc 22e62fc0
0x02bf3010:   22e62fc0 02bf302c 6da2d1de 22e62fc0
0x02bf3020:   22e62fac 22e62fb0 22e62fb0 02bf3044
0x02bf3030:   6da2d1de 00000003 22e62f9c 22e62fa0
0x02bf3040:   22e62fa0 02bf305c 6da2d1de 00000003
0x02bf3050:   22e62f8c 22e62f90 22e62f90 02bf3074
0x02bf3060:   6da2d1de 00000003 22e62f7c 22e62f80
0x02bf3070:   22e62f80 02bf308c 6da2d1de 00000003 

Instructions: (pc=0x6d8b99f0)
0x6d8b99e0:   5d c2 08 00 cc cc cc cc cc cc cc cc cc cc cc cc
0x6d8b99f0:   55 8b ec 8b 45 08 56 8b 30 85 f6 74 40 8b 0e 83 

Stack: [0x02bf0000,0x02c40000],  sp=0x02bf3000,  free space=c02bf2b74k
Native frames: (J=compiled Java code, j=interpreted, Vv=VM code, C=native code)
V  [jvm.dll+0x99f0]
V  [jvm.dll+0x17d1de]
V  [jvm.dll+0x17d1de]
V  [jvm.dll+0x17d1de]
V  [jvm.dll+0x17d1de]
V  [jvm.dll+0x17d1de]
V  [jvm.dll+0x17d1de]
V  [jvm.dll+0x17d1de]
V  [jvm.dll+0x17d1de]
V  [jvm.dll+0x17d1de]
V  [jvm.dll+0x17d1de]
V  [jvm.dll+0x17d1de]
V  [jvm.dll+0x17d1de]
V  [jvm.dll+0x17d1de]
V  [jvm.dll+0x17d1de]
V  [jvm.dll+0x17d1de]
V  [jvm.dll+0x17d1de]
V  [jvm.dll+0x17d1de]
V  [jvm.dll+0x17d1de]
V  [jvm.dll+0x17d1de]
V  [jvm.dll+0x17d1de]
V  [jvm.dll+0x17d1de]
V  [jvm.dll+0x17d1de]
V  [jvm.dll+0x17d1de]
V  [jvm.dll+0x17d1de]
V  [jvm.dll+0x17d1de]
V  [jvm.dll+0x17d1de]
V  [jvm.dll+0x17d1de]
V  [jvm.dll+0x17d1de]
V  [jvm.dll+0x17d1de]
V  [jvm.dll+0x17d1de]
V  [jvm.dll+0x17d1de]
V  [jvm.dll+0x17d1de]
V  [jvm.dll+0x17d1de]
V  [jvm.dll+0x17d1de]
V  [jvm.dll+0x17d1de]
V  [jvm.dll+0x17d1de]
V  [jvm.dll+0x17d1de]
V  [jvm.dll+0x17d1de]
V  [jvm.dll+0x17d1de]
V  [jvm.dll+0x17d1de]
V  [jvm.dll+0x17d1de]
V  [jvm.dll+0x17d1de]
V  [jvm.dll+0x17d1de]
V  [jvm.dll+0x17d1de]
V  [jvm.dll+0x17d1de]
V  [jvm.dll+0x17d1de]
V  [jvm.dll+0x17d1de]
V  [jvm.dll+0x17d1de]
V  [jvm.dll+0x17d1de]
V  [jvm.dll+0x17d1de]
V  [jvm.dll+0x17d1de]
V  [jvm.dll+0x17d1de]
V  [jvm.dll+0x17d1de]
V  [jvm.dll+0x17d1de]
V  [jvm.dll+0x17d1de]
V  [jvm.dll+0x17d1de]
V  [jvm.dll+0x17d1de]
V  [jvm.dll+0x17d1de]
V  [jvm.dll+0x17d1de]
V  [jvm.dll+0x17d1de]
V  [jvm.dll+0x17d1de]
V  [jvm.dll+0x17d1de]
V  [jvm.dll+0x17d1de]
V  [jvm.dll+0x17d1de]
V  [jvm.dll+0x17d1de]
V  [jvm.dll+0x17d1de]
V  [jvm.dll+0x17d1de]
V  [jvm.dll+0x17d1de]
V  [jvm.dll+0x17d1de]
V  [jvm.dll+0x17d1de]
V  [jvm.dll+0x17d1de]
V  [jvm.dll+0x17d1de]
V  [jvm.dll+0x17d1de]
V  [jvm.dll+0x17d1de]
V  [jvm.dll+0x17d1de]
V  [jvm.dll+0x17d1de]
V  [jvm.dll+0x17d1de]
V  [jvm.dll+0x17d1de]
V  [jvm.dll+0x17d1de]
V  [jvm.dll+0x17d1de]
V  [jvm.dll+0x17d1de]
V  [jvm.dll+0x17d1de]
V  [jvm.dll+0x17d1de]
V  [jvm.dll+0x17d1de]
V  [jvm.dll+0x17d1de]
V  [jvm.dll+0x17d1de]
V  [jvm.dll+0x17d1de]
V  [jvm.dll+0x17d1de]
V  [jvm.dll+0x17d1de]
V  [jvm.dll+0x17d1de]
V  [jvm.dll+0x17d1de]
V  [jvm.dll+0x17d1de]
V  [jvm.dll+0x17d1de]
V  [jvm.dll+0x17d1de]
V  [jvm.dll+0x17d1de]
V  [jvm.dll+0x17d1de]
V  [jvm.dll+0x17d1de]
V  [jvm.dll+0x17d1de]
V  [jvm.dll+0x17d1de]
......

JavaThread 0x002b6400 (nid = 2948) was being processed
Java frames: (J=compiled Java code, j=interpreted, Vv=VM code)
v  ~RuntimeStub::new_object_array Runtime1 stub
J  Crash.main([Ljava/lang/String;)V
v  ~StubRoutines::call_stub
VM_Operation (0x0095fa14): GenCollectForAllocation, mode: safepoint, requested by thread 0x002b6400

---------------  P R O C E S S  ---------------

Java Threads: ( =&gt; current thread )
  0x02b25000 JavaThread "Low Memory Detector" daemon [_thread_blocked, id=5292, stack(0x02dd0000,0x02e20000)]
  0x02b16400 JavaThread "CompilerThread0" daemon [_thread_blocked, id=4848, stack(0x02d80000,0x02dd0000)]
  0x02b14c00 JavaThread "Attach Listener" daemon [_thread_blocked, id=5384, stack(0x02d30000,0x02d80000)]
  0x02b13800 JavaThread "Signal Dispatcher" daemon [_thread_blocked, id=528, stack(0x02ce0000,0x02d30000)]
  0x02b0fc00 JavaThread "Finalizer" daemon [_thread_blocked, id=324, stack(0x02c90000,0x02ce0000)]
  0x02b0b400 JavaThread "Reference Handler" daemon [_thread_blocked, id=5940, stack(0x02c40000,0x02c90000)]
  0x002b6400 JavaThread "main" [_thread_blocked, id=2948, stack(0x00910000,0x00960000)]

Other Threads:
=&gt;0x02b09c00 VMThread [stack: 0x02bf0000,0x02c40000] [id=2232]
  0x02b38800 WatcherThread [stack: 0x02e20000,0x02e70000] [id=4228]

VM state:at safepoint (normal execution)

VM Mutex/Monitor currently owned by a thread:  ([mutex/lock_event])
[0x002b55f0] Threads_lock - owner thread: 0x02b09c00
[0x002b5a00] Heap_lock - owner thread: 0x002b6400

Heap
 def new generation   total 4736K, used 512K [0x22990000, 0x22eb0000, 0x27c30000)
  eden space 4224K,   0% used [0x22990000, 0x22990000, 0x22db0000)
  from space 512K, 100% used [0x22e30000, 0x22eb0000, 0x22eb0000)
  to   space 512K,   0% used [0x22db0000, 0x22db0000, 0x22e30000)
 tenured generation   total 12160K, used 12091K [0x27c30000, 0x28810000, 0x32190000)
   the space 12160K,  99% used [0x27c30000, 0x287fed48, 0x287fee00, 0x28810000)
 compacting perm gen  total 12288K, used 25K [0x32190000, 0x32d90000, 0x36190000)
   the space 12288K,   0% used [0x32190000, 0x32196528, 0x32196600, 0x32d90000)
    ro space 10240K,  54% used [0x36190000, 0x3670c0f0, 0x3670c200, 0x36b90000)
    rw space 12288K,  55% used [0x36b90000, 0x3722fb80, 0x3722fc00, 0x37790000)

Dynamic libraries:
0x00400000 - 0x00424000 	E:\Java\jdk1.6.0_21\bin\java.exe
0x7c900000 - 0x7c9b2000 	D:\WINDOWS\system32\ntdll.dll
0x7c800000 - 0x7c8f6000 	D:\WINDOWS\system32\kernel32.dll
0x77dd0000 - 0x77e6b000 	D:\WINDOWS\system32\ADVAPI32.dll
0x77e70000 - 0x77f03000 	D:\WINDOWS\system32\RPCRT4.dll
0x77fe0000 - 0x77ff1000 	D:\WINDOWS\system32\Secur32.dll
0x7c340000 - 0x7c396000 	E:\Java\jdk1.6.0_21\jre\bin\msvcr71.dll
0x6d8b0000 - 0x6db57000 	E:\Java\jdk1.6.0_21\jre\bin\client\jvm.dll
0x7e410000 - 0x7e4a1000 	D:\WINDOWS\system32\USER32.dll
0x77f10000 - 0x77f59000 	D:\WINDOWS\system32\GDI32.dll
0x76b40000 - 0x76b6d000 	D:\WINDOWS\system32\WINMM.dll
0x76390000 - 0x763ad000 	D:\WINDOWS\system32\IMM32.DLL
0x6d860000 - 0x6d86c000 	E:\Java\jdk1.6.0_21\jre\bin\verify.dll
0x6d3e0000 - 0x6d3ff000 	E:\Java\jdk1.6.0_21\jre\bin\java.dll
0x6d340000 - 0x6d348000 	E:\Java\jdk1.6.0_21\jre\bin\hpi.dll
0x76bf0000 - 0x76bfb000 	D:\WINDOWS\system32\PSAPI.DLL
0x6d8a0000 - 0x6d8af000 	E:\Java\jdk1.6.0_21\jre\bin\zip.dll

VM Arguments:
java_command: Crash
Launcher Type: SUN_STANDARD

Environment Variables:
JAVA_HOME=E:\Java\jdk1.6.0_21
CLASSPATH=.;E:\Java\jre6\lib\ext\QTJava.zip
PATH=E:\Java\jdk1.6.0_21\bin;D:\WINDOWS\SYSTEM32;D:\WINDOWS;D:\WINDOWS\SYSTEM32\WBEM
USERNAME=Onkar Joshi
OS=Windows_NT
PROCESSOR_IDENTIFIER=x86 Family 6 Model 10 Stepping 0, AuthenticAMD

---------------  S Y S T E M  ---------------

OS: Windows XP Build 2600 Service Pack 3

CPU:total 1 (1 cores per cpu, 1 threads per core) family 6 model 10 stepping 0, cmov, cx8, fxsr, mmx, sse, mmxext, 3dnow, 3dnowext

Memory: 4k page, physical 1015152k(349348k free), swap 1974304k(600992k free)

vm_info: Java HotSpot(TM) Client VM (17.0-b17) for windows-x86 JRE (1.6.0_21-b07), built on Jul 17 2010 01:10:15 by "java_re" with MS VC++ 7.1 (VS2003)

time: Mon Mar 07 02:40:13 2011
elapsed time: 0 seconds</pre>
<div class='yarpp-related-rss'>
<p>Related posts:<ol>
<li><a href='http://www.onkarjoshi.com/blog/209/using-xss-to-adjust-java-default-thread-stack-size-to-save-memory-and-prevent-stackoverflowerror/' rel='bookmark' title='Using -Xss to adjust Java default thread stack size to save memory and prevent StackOverflowError'>Using -Xss to adjust Java default thread stack size to save memory and prevent StackOverflowError</a></li>
<li><a href='http://www.onkarjoshi.com/blog/84/configuring-eclipse-to-use-a-jdk-at-a-location-with-spaces-in-it/' rel='bookmark' title='Configuring Eclipse to use a JDK at a location with spaces in it'>Configuring Eclipse to use a JDK at a location with spaces in it</a></li>
<li><a href='http://www.onkarjoshi.com/blog/247/heap-dump-of-a-running-jvm-with-jmap/' rel='bookmark' title='Heap dump of a running JVM with jmap'>Heap dump of a running JVM with jmap</a></li>
<li><a href='http://www.onkarjoshi.com/blog/186/garbage-collection-and-reachability-strong-soft-weak-phantom-unreachable/' rel='bookmark' title='Garbage Collection, Reference types and Reachability &#8211; Strong, Soft, Weak, Phantom, Unreachable'>Garbage Collection, Reference types and Reachability &#8211; Strong, Soft, Weak, Phantom, Unreachable</a></li>
<li><a href='http://www.onkarjoshi.com/blog/174/hotspot-jvm-client-server-vm-optimization/' rel='bookmark' title='HotSpot JVM &#8211; Client / Server VM optimization &#8211; 260ms vs 0ms!'>HotSpot JVM &#8211; Client / Server VM optimization &#8211; 260ms vs 0ms!</a></li>
</ol></p>
</div>
<img src="http://feeds.feedburner.com/~r/onkarjoshi/~4/Pc-IO7SpeoQ" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.onkarjoshi.com/blog/226/crash-your-jvm-by-killing-the-garbage-collector/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.onkarjoshi.com/blog/226/crash-your-jvm-by-killing-the-garbage-collector/</feedburner:origLink></item>
		<item>
		<title>How to suspend VM on startup when remote debugging your Java app</title>
		<link>http://feedproxy.google.com/~r/onkarjoshi/~3/QYYh4411u50/</link>
		<comments>http://www.onkarjoshi.com/blog/224/how-to-suspend-vm-on-startup-when-remote-debugging-your-java-app/#comments</comments>
		<pubDate>Mon, 23 May 2011 14:01:24 +0000</pubDate>
		<dc:creator>Onkar Joshi</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Java]]></category>

		<guid isPermaLink="false">http://www.onkarjoshi.com/blog/?p=224</guid>
		<description><![CDATA[You want to do a remote debugging session on code that runs in the initial few seconds of your app being launched. A problem that you can run into when attempting to do this is that since the code runs right in the beginning, the JVM may rush past it before you have had a [...]<div class='yarpp-related-rss'>

Related posts:<ol>
<li><a href='http://www.onkarjoshi.com/blog/163/debug-with-step-filters-in-eclipse/' rel='bookmark' title='Debug with Step Filters in Eclipse'>Debug with Step Filters in Eclipse</a></li>
<li><a href='http://www.onkarjoshi.com/blog/166/identifying-a-thread-with-high-cpu-usage-in-a-java-app/' rel='bookmark' title='Identifying a thread with high CPU usage in a Java app'>Identifying a thread with high CPU usage in a Java app</a></li>
<li><a href='http://www.onkarjoshi.com/blog/159/conditional-breakpoints-in-java-development-with-eclipse/' rel='bookmark' title='Conditional breakpoints in Java development with Eclipse'>Conditional breakpoints in Java development with Eclipse</a></li>
<li><a href='http://www.onkarjoshi.com/blog/209/using-xss-to-adjust-java-default-thread-stack-size-to-save-memory-and-prevent-stackoverflowerror/' rel='bookmark' title='Using -Xss to adjust Java default thread stack size to save memory and prevent StackOverflowError'>Using -Xss to adjust Java default thread stack size to save memory and prevent StackOverflowError</a></li>
<li><a href='http://www.onkarjoshi.com/blog/222/assigning-a-reference-to-itself-in-java-has-no-effect-right-wrong/' rel='bookmark' title='Assigning a reference to itself in Java has no effect, right? &#8211; WRONG!'>Assigning a reference to itself in Java has no effect, right? &#8211; WRONG!</a></li>
</ol>
</div>
]]></description>
				<content:encoded><![CDATA[<p style="text-align: justify;">You want to do a remote debugging session on code that runs in the initial few seconds of your app being launched.</p>
<p style="text-align: justify;">A problem that you can run into when attempting to do this is that since  the code runs right in the beginning, the JVM may rush past it before  you have had a chance to attach a debugger via Eclipse and set your  break points.</p>
<p style="text-align: justify;">The solution is to setup your JVM/debugging config so that it is set to suspend at startup.</p>
<p style="text-align: justify;">A  typical way to setup remote debugging is to use the following JVM  argument in the code used to launch your application so that a debugger  can later attach itself to port 8000.</p>
<p style="text-align: justify;">-Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=8000</p>
<p style="text-align: justify;">Infact this is what Eclipse does when you launch an app in debug mode  rather than normal mode. It adds this line in the JVM arguments used  when launching your application.</p>
<p style="text-align: justify;">Note the <em>suspend=n</em>. If that is set to <em>y</em>, the JVM will suspend on startup. It will wait for a debugger to attach to it and release it before it will proceed.</p>
<p style="text-align: justify;">So using the suspend flag, our problem is solved. Happy debugging!</p>
<div class='yarpp-related-rss'>
<p>Related posts:<ol>
<li><a href='http://www.onkarjoshi.com/blog/163/debug-with-step-filters-in-eclipse/' rel='bookmark' title='Debug with Step Filters in Eclipse'>Debug with Step Filters in Eclipse</a></li>
<li><a href='http://www.onkarjoshi.com/blog/166/identifying-a-thread-with-high-cpu-usage-in-a-java-app/' rel='bookmark' title='Identifying a thread with high CPU usage in a Java app'>Identifying a thread with high CPU usage in a Java app</a></li>
<li><a href='http://www.onkarjoshi.com/blog/159/conditional-breakpoints-in-java-development-with-eclipse/' rel='bookmark' title='Conditional breakpoints in Java development with Eclipse'>Conditional breakpoints in Java development with Eclipse</a></li>
<li><a href='http://www.onkarjoshi.com/blog/209/using-xss-to-adjust-java-default-thread-stack-size-to-save-memory-and-prevent-stackoverflowerror/' rel='bookmark' title='Using -Xss to adjust Java default thread stack size to save memory and prevent StackOverflowError'>Using -Xss to adjust Java default thread stack size to save memory and prevent StackOverflowError</a></li>
<li><a href='http://www.onkarjoshi.com/blog/222/assigning-a-reference-to-itself-in-java-has-no-effect-right-wrong/' rel='bookmark' title='Assigning a reference to itself in Java has no effect, right? &#8211; WRONG!'>Assigning a reference to itself in Java has no effect, right? &#8211; WRONG!</a></li>
</ol></p>
</div>
<img src="http://feeds.feedburner.com/~r/onkarjoshi/~4/QYYh4411u50" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.onkarjoshi.com/blog/224/how-to-suspend-vm-on-startup-when-remote-debugging-your-java-app/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		<feedburner:origLink>http://www.onkarjoshi.com/blog/224/how-to-suspend-vm-on-startup-when-remote-debugging-your-java-app/</feedburner:origLink></item>
		<item>
		<title>Assigning a reference to itself in Java has no effect, right? – WRONG!</title>
		<link>http://feedproxy.google.com/~r/onkarjoshi/~3/zYi6GbDo3GQ/</link>
		<comments>http://www.onkarjoshi.com/blog/222/assigning-a-reference-to-itself-in-java-has-no-effect-right-wrong/#comments</comments>
		<pubDate>Sun, 22 May 2011 13:46:22 +0000</pubDate>
		<dc:creator>Onkar Joshi</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Concurrency]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[JMM]]></category>
		<category><![CDATA[JVM]]></category>

		<guid isPermaLink="false">http://www.onkarjoshi.com/blog/?p=222</guid>
		<description><![CDATA[You see this piece of code in your beloved code base&#8230;. referenceToSomethingImportant = referenceToSomethingImportant; You immediately delete it since assigning a variable to itself will never do any thing. Of course the compiler or the JIT machinery is always going to optimize it away anyway. Right? Wrong. Oh yes, there might be another thread you [...]<div class='yarpp-related-rss'>

Related posts:<ol>
<li><a href='http://www.onkarjoshi.com/blog/219/volatile-array/' rel='bookmark' title='Atomic array classes and volatile arrays in the JVM'>Atomic array classes and volatile arrays in the JVM</a></li>
<li><a href='http://www.onkarjoshi.com/blog/186/garbage-collection-and-reachability-strong-soft-weak-phantom-unreachable/' rel='bookmark' title='Garbage Collection, Reference types and Reachability &#8211; Strong, Soft, Weak, Phantom, Unreachable'>Garbage Collection, Reference types and Reachability &#8211; Strong, Soft, Weak, Phantom, Unreachable</a></li>
<li><a href='http://www.onkarjoshi.com/blog/170/threads-concurrency-fix-concurrent-modification-exception-on-arraylist-with-copyonwritearraylist/' rel='bookmark' title='Fix ConcurrentModificationException on ArrayList with CopyOnWriteArrayList'>Fix ConcurrentModificationException on ArrayList with CopyOnWriteArrayList</a></li>
</ol>
</div>
]]></description>
				<content:encoded><![CDATA[<p style="text-align: justify;">You see this piece of code in your beloved code base&#8230;.</p>
<p><em>referenceToSomethingImportant = referenceToSomethingImportant;</em></p>
<p>You immediately delete it since assigning a variable to itself will  never do any thing. Of course the compiler or the JIT machinery is  always going to optimize it away anyway. Right?</p>
<p>Wrong.</p>
<p style="text-align: justify;">Oh yes, there might be another thread you exclaim. But then doing  something that has no effect will still have no effect when multiple  threads are doing it, eh? Then what?</p>
<p style="text-align: justify;">You are neglecting to consider the fact that read-write-assignment can  do something other then memory operations to store data. Visibilty.  That&#8217;s the key.</p>
<p style="text-align: justify;">If &#8220;value&#8221; were declared to be volatile, the JVM now cannot optimize  away everything from that line that you decided to remove. Because  besides the data, there is now a memfence / mfence / membar / barrier /  whatever-for-your-architecture instruction that is also being inserted  as part of that bit of code when it is translated to assembly language  for your machine.</p>
<p style="text-align: justify;">This is to make the happens before guarantees associated with volatile  reads and writes work correctly. Specifically, a happens before at that  pont was caused by the volatile read / write. That caused changes up to  that point by the thread to be flushed out of what could have been  buffered in the SRAM (static RAM) on a specific core in the CPU causing  it to be visible to other the reads.</p>
<p style="text-align: justify;">There are situations where piggybacking the flush of such changes caused  by operations on volatile variables can help in squeezing out the last  bits of performance in concurrent code by avoiding synchronization which has the overhead of locking besides providing the same visibility guarantees as volatile does.</p>
<p style="text-align: justify;">Highly unrecommended for anyone but authors of concurrency libraries!</p>
<div class='yarpp-related-rss'>
<p>Related posts:<ol>
<li><a href='http://www.onkarjoshi.com/blog/219/volatile-array/' rel='bookmark' title='Atomic array classes and volatile arrays in the JVM'>Atomic array classes and volatile arrays in the JVM</a></li>
<li><a href='http://www.onkarjoshi.com/blog/186/garbage-collection-and-reachability-strong-soft-weak-phantom-unreachable/' rel='bookmark' title='Garbage Collection, Reference types and Reachability &#8211; Strong, Soft, Weak, Phantom, Unreachable'>Garbage Collection, Reference types and Reachability &#8211; Strong, Soft, Weak, Phantom, Unreachable</a></li>
<li><a href='http://www.onkarjoshi.com/blog/170/threads-concurrency-fix-concurrent-modification-exception-on-arraylist-with-copyonwritearraylist/' rel='bookmark' title='Fix ConcurrentModificationException on ArrayList with CopyOnWriteArrayList'>Fix ConcurrentModificationException on ArrayList with CopyOnWriteArrayList</a></li>
</ol></p>
</div>
<img src="http://feeds.feedburner.com/~r/onkarjoshi/~4/zYi6GbDo3GQ" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.onkarjoshi.com/blog/222/assigning-a-reference-to-itself-in-java-has-no-effect-right-wrong/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		<feedburner:origLink>http://www.onkarjoshi.com/blog/222/assigning-a-reference-to-itself-in-java-has-no-effect-right-wrong/</feedburner:origLink></item>
		<item>
		<title>Atomic array classes and volatile arrays in the JVM</title>
		<link>http://feedproxy.google.com/~r/onkarjoshi/~3/ruxoM7_9CD8/</link>
		<comments>http://www.onkarjoshi.com/blog/219/volatile-array/#comments</comments>
		<pubDate>Mon, 18 Apr 2011 21:43:46 +0000</pubDate>
		<dc:creator>Onkar Joshi</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Java Memory Model]]></category>
		<category><![CDATA[JLS]]></category>
		<category><![CDATA[JMM]]></category>
		<category><![CDATA[JVM]]></category>

		<guid isPermaLink="false">http://www.onkarjoshi.com/blog/?p=219</guid>
		<description><![CDATA[Declaring an array volatile does not do what many think it does! The common, simplistic understanding of the volatile keyword in Java is that if a variable is being modified by multiple threads, it should be marked volatile so that changes can be seen by other threads. (There is more to it that I&#8217;ll leave [...]<div class='yarpp-related-rss'>

Related posts:<ol>
<li><a href='http://www.onkarjoshi.com/blog/222/assigning-a-reference-to-itself-in-java-has-no-effect-right-wrong/' rel='bookmark' title='Assigning a reference to itself in Java has no effect, right? &#8211; WRONG!'>Assigning a reference to itself in Java has no effect, right? &#8211; WRONG!</a></li>
<li><a href='http://www.onkarjoshi.com/blog/226/crash-your-jvm-by-killing-the-garbage-collector/' rel='bookmark' title='Crash your JVM by killing the garbage collector!'>Crash your JVM by killing the garbage collector!</a></li>
<li><a href='http://www.onkarjoshi.com/blog/174/hotspot-jvm-client-server-vm-optimization/' rel='bookmark' title='HotSpot JVM &#8211; Client / Server VM optimization &#8211; 260ms vs 0ms!'>HotSpot JVM &#8211; Client / Server VM optimization &#8211; 260ms vs 0ms!</a></li>
<li><a href='http://www.onkarjoshi.com/blog/247/heap-dump-of-a-running-jvm-with-jmap/' rel='bookmark' title='Heap dump of a running JVM with jmap'>Heap dump of a running JVM with jmap</a></li>
<li><a href='http://www.onkarjoshi.com/blog/170/threads-concurrency-fix-concurrent-modification-exception-on-arraylist-with-copyonwritearraylist/' rel='bookmark' title='Fix ConcurrentModificationException on ArrayList with CopyOnWriteArrayList'>Fix ConcurrentModificationException on ArrayList with CopyOnWriteArrayList</a></li>
</ol>
</div>
]]></description>
				<content:encoded><![CDATA[<p style="text-align: justify;">Declaring an array volatile does not do what many think it does!</p>
<p style="text-align: justify;">The  common, simplistic understanding of the volatile keyword in Java is  that if a variable is being modified by multiple threads, it should be  marked volatile so that changes can be seen by other threads. (There is more to it that I&#8217;ll leave for a future post.)</p>
<p style="text-align: justify;">If you had something like a shared boolean primitive marked  volatile, this would work fine. However, when an array is marked  volatile, it is only the array reference that is marked volatile! The  contents of array itself do not inherit the memory visibility semantics  of the volatile keyword at all.</p>
<p style="text-align: justify;">So what you have is not an array of volatile primitives. Instead, you have a volatile array of non-volatile primitives.</p>
<p style="text-align: justify;">This means that even if you declare an array to be volatile,  modifying the contents of  that array does not guarantee that those  modifications will be seen by a different thread reading the contents of  the array. However, if you update the reference to point to a new array  object &#8211; this new array will correctly be seen by threads reading the  reference. (No JVM guarantee about seeing changes to the contents of the  new array though!)</p>
<p style="text-align: justify;">So what is the correct way to share contents of a mutable array with  multiple threads? Use the Atomic*Array classes in the  java.util.concurrent.atomic package.</p>
<p style="text-align: justify;">AtomicLongArray, AtomicIntegerArray, AtomicReferenceArray&lt;V&gt; are your friends.</p>
<p style="text-align: justify;">&#8220;No AtomicFloatArray and AtomicDoubleArray!&#8221;, you exclaim. Well,  recall that a float is 32 bits and so is an integer. A double is 64 bits  and so is a long. Use the Double.doubleToLongBits and  Float.floatToIntBits methods to your advantage. Simple, isn&#8217;t it?</p>
<p style="text-align: justify;">An alternative way to get volatile semantics for an array of  primitives is to wrap the primitive with a wrapper that declares the  primitive volatile. Accessing the volatile field from the array of  wrappers will give you the desired volatile semantics.</p>
<p style="text-align: justify;">What about an array of AtomicReference&lt;V&gt; variables?  (AtomicReference&lt;V&gt;[] array;) &#8211; Yes, this is going to work too.  But you should probably use AtomicReferenceArray&lt;V&gt; instead. It  uses less memory which can be significant if you have millions of values  in the array.</p>
<p style="text-align: justify;">There is more to volatile &#8211; but that&#8217;s for another post.</p>
<div class='yarpp-related-rss'>
<p>Related posts:<ol>
<li><a href='http://www.onkarjoshi.com/blog/222/assigning-a-reference-to-itself-in-java-has-no-effect-right-wrong/' rel='bookmark' title='Assigning a reference to itself in Java has no effect, right? &#8211; WRONG!'>Assigning a reference to itself in Java has no effect, right? &#8211; WRONG!</a></li>
<li><a href='http://www.onkarjoshi.com/blog/226/crash-your-jvm-by-killing-the-garbage-collector/' rel='bookmark' title='Crash your JVM by killing the garbage collector!'>Crash your JVM by killing the garbage collector!</a></li>
<li><a href='http://www.onkarjoshi.com/blog/174/hotspot-jvm-client-server-vm-optimization/' rel='bookmark' title='HotSpot JVM &#8211; Client / Server VM optimization &#8211; 260ms vs 0ms!'>HotSpot JVM &#8211; Client / Server VM optimization &#8211; 260ms vs 0ms!</a></li>
<li><a href='http://www.onkarjoshi.com/blog/247/heap-dump-of-a-running-jvm-with-jmap/' rel='bookmark' title='Heap dump of a running JVM with jmap'>Heap dump of a running JVM with jmap</a></li>
<li><a href='http://www.onkarjoshi.com/blog/170/threads-concurrency-fix-concurrent-modification-exception-on-arraylist-with-copyonwritearraylist/' rel='bookmark' title='Fix ConcurrentModificationException on ArrayList with CopyOnWriteArrayList'>Fix ConcurrentModificationException on ArrayList with CopyOnWriteArrayList</a></li>
</ol></p>
</div>
<img src="http://feeds.feedburner.com/~r/onkarjoshi/~4/ruxoM7_9CD8" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.onkarjoshi.com/blog/219/volatile-array/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.onkarjoshi.com/blog/219/volatile-array/</feedburner:origLink></item>
		<item>
		<title>How to optimize your travel site – NOT!</title>
		<link>http://feedproxy.google.com/~r/onkarjoshi/~3/A9iyH1O0EFc/</link>
		<comments>http://www.onkarjoshi.com/blog/217/how-to-optimize-your-travel-site-not/#comments</comments>
		<pubDate>Sun, 06 Mar 2011 09:45:47 +0000</pubDate>
		<dc:creator>Onkar Joshi</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[bug]]></category>
		<category><![CDATA[Web]]></category>

		<guid isPermaLink="false">http://www.onkarjoshi.com/blog/?p=217</guid>
		<description><![CDATA[I recently booked tickets from a certain travel site. As soon as my booking was done, I received an SMS with details about my booking. I also noticed that a pop-up window had been launched on my system. And that window had an interesting URL. http://someSMSGateway.com/blah/foo.php?username=abc&#38;pass=pqr&#38;mobile=9890123456&#38;message=theMessageIGotAsAnSMS &#8211; So, the brilliant programmers for that site decided [...]<div class='yarpp-related-rss'>

Related posts:<ol>
<li><a href='http://www.onkarjoshi.com/blog/130/add-site-owner-verification-code-for-a-free-wordpress-com-blog/' rel='bookmark' title='Add site owner verification code for a free WordPress.com blog'>Add site owner verification code for a free WordPress.com blog</a></li>
</ol>
</div>
]]></description>
				<content:encoded><![CDATA[<p style="text-align: justify;">I recently booked tickets from a certain travel site. As soon as my booking was done, I received an SMS with details about my booking.</p>
<p style="text-align: justify;">I also noticed that a pop-up window had been launched on my system. And that window had an interesting URL.</p>
<p style="text-align: justify;">http://someSMSGateway.com/blah/foo.php?<strong>username=abc</strong>&amp;<strong>pass=pqr</strong>&amp;mobile=9890123456&amp;message=theMessageIGotAsAnSMS &#8211; <em>So, the brilliant programmers for that site decided to send their username, password for the SMS gateway to my browser and launched a request to send the SMS from my system via JavaScript!</em></p>
<p style="text-align: justify;">Heh. I copied that off. Pasted it into my browser again, I got the SMS on my mobile again. Modified the message a bit. Got the modified message.</p>
<p style="text-align: justify;">It is difficult to imagine what they thought when they decided to do this. Maybe some confusion over what happens on the server side and what happens at the client in PHP pages when using JavaScript? Or maybe someone decided to &#8220;optimize&#8221; things by offloading the task of sending messages to the client side. The URL itself was not easily visible when I used Internet Explorer rather than Firefox. Perhaps they didn&#8217;t even test in Firefox &#8211; never realizing that their account info with the SMS gateway was so clearly visible to their users.</p>
<p style="text-align: justify;">I suppose it won&#8217;t be long before they go crying to the cops saying, &#8220;Hackers used our username, password to send out a million spam messages.&#8221;</p>
<div class='yarpp-related-rss'>
<p>Related posts:<ol>
<li><a href='http://www.onkarjoshi.com/blog/130/add-site-owner-verification-code-for-a-free-wordpress-com-blog/' rel='bookmark' title='Add site owner verification code for a free WordPress.com blog'>Add site owner verification code for a free WordPress.com blog</a></li>
</ol></p>
</div>
<img src="http://feeds.feedburner.com/~r/onkarjoshi/~4/A9iyH1O0EFc" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.onkarjoshi.com/blog/217/how-to-optimize-your-travel-site-not/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		<feedburner:origLink>http://www.onkarjoshi.com/blog/217/how-to-optimize-your-travel-site-not/</feedburner:origLink></item>
		<item>
		<title>6 things to remember about saving memory with the String.intern method</title>
		<link>http://feedproxy.google.com/~r/onkarjoshi/~3/my7OcrlpSRM/</link>
		<comments>http://www.onkarjoshi.com/blog/213/6-things-to-remember-about-saving-memory-with-the-string-intern-method/#comments</comments>
		<pubDate>Fri, 18 Feb 2011 05:00:05 +0000</pubDate>
		<dc:creator>Onkar Joshi</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Java]]></category>

		<guid isPermaLink="false">http://www.onkarjoshi.com/blog/?p=213</guid>
		<description><![CDATA[Imagine that you have a flat file in csv format. And it has a 100 million rows from which you are about to read data to store and process in your app. The data is in the format (orderId, storeIdentifier, amountDue). What optimization can you do here? Note that the storeIdentifier is going to be [...]<div class='yarpp-related-rss'>

Related posts:<ol>
<li><a href='http://www.onkarjoshi.com/blog/209/using-xss-to-adjust-java-default-thread-stack-size-to-save-memory-and-prevent-stackoverflowerror/' rel='bookmark' title='Using -Xss to adjust Java default thread stack size to save memory and prevent StackOverflowError'>Using -Xss to adjust Java default thread stack size to save memory and prevent StackOverflowError</a></li>
</ol>
</div>
]]></description>
				<content:encoded><![CDATA[<p style="text-align: justify;">Imagine that you have a flat file in csv format. And it has a 100 million rows from which you are about to read data to store and process in your app.</p>
<p style="text-align: justify;">The data is in the format (orderId, storeIdentifier, amountDue).</p>
<p style="text-align: justify;">What optimization can you do here?</p>
<p style="text-align: justify;">Note that the storeIdentifier is going to be repeated a lot. Every time you read a record and split it into a string and possibly store it into an in-memory data structure, you will be creating a new String object. So 100 million String objects will be created for the storeIdentifier. But you know that there are only (say) 100 stores in all! So there is a massive amount of wasted memory.</p>
<p style="text-align: justify;">What you can do here is &#8211; Right after you have read the storeIdentifier string, do this -</p>
<p style="text-align: justify;">storeIdentifier = storeIdentifier.intern();</p>
<p style="text-align: justify;">That would put the store identifier into the String pool and keep the number of String instances with the same data minimal by returning the String from the pool once it has been put into it by the first invocation for the string.</p>
<p style="text-align: justify;"><strong>Nuggets of wisdom</strong></p>
<ol>
<li> Use intern() only if you really need to use it. And only if you know the extra instances are going to be a problem. And only if you really understand how it works.</li>
<li> Older JVMs had a problem collecting interned strings. Newer JVMs handle this fine. Don&#8217;t worry about leaks due to a growing pool. If other references are gone, interned strings will be collected by the GC.</li>
<li> Interned strings go into the PermGen Space area of memory in some JVMs. This is not part of the normal heap. If you send too many strings here, an OutOfMemoryError will hit you even though your heap may have several GB available.</li>
<li> Interned strings can be compared with == rather than .equals(). This is a bit faster. But it is rarely worth the brittle code.</li>
<li> Calling String.intern() can be a performance hit. It takes CPU cycles to maintain the pool and do the comparisons. Are you sure you are saving enough memory to make it worth the CPU? Measure. Don&#8217;t guess.</li>
<li> Use String.intern() only if the set of possible Strings that will be interned has a bound tight enough such that the set of different strings is much smaller than the total number of strings that will be read.</li>
</ol>
<div class='yarpp-related-rss'>
<p>Related posts:<ol>
<li><a href='http://www.onkarjoshi.com/blog/209/using-xss-to-adjust-java-default-thread-stack-size-to-save-memory-and-prevent-stackoverflowerror/' rel='bookmark' title='Using -Xss to adjust Java default thread stack size to save memory and prevent StackOverflowError'>Using -Xss to adjust Java default thread stack size to save memory and prevent StackOverflowError</a></li>
</ol></p>
</div>
<img src="http://feeds.feedburner.com/~r/onkarjoshi/~4/my7OcrlpSRM" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.onkarjoshi.com/blog/213/6-things-to-remember-about-saving-memory-with-the-string-intern-method/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		<feedburner:origLink>http://www.onkarjoshi.com/blog/213/6-things-to-remember-about-saving-memory-with-the-string-intern-method/</feedburner:origLink></item>
		<item>
		<title>Using -Xss to adjust Java default thread stack size to save memory and prevent StackOverflowError</title>
		<link>http://feedproxy.google.com/~r/onkarjoshi/~3/v20P1-d_E_o/</link>
		<comments>http://www.onkarjoshi.com/blog/209/using-xss-to-adjust-java-default-thread-stack-size-to-save-memory-and-prevent-stackoverflowerror/#comments</comments>
		<pubDate>Thu, 17 Feb 2011 11:49:21 +0000</pubDate>
		<dc:creator>Onkar Joshi</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[JVM]]></category>

		<guid isPermaLink="false">http://www.onkarjoshi.com/blog/?p=209</guid>
		<description><![CDATA[Every thread created in a Java program has its own stack space. The stack space used is not allocated from the heap. Infact if you look at the OS report on the memory used by your JVM, you may notice that it is more than what -Xmx parameter specifies. This is because, beside other things, [...]<div class='yarpp-related-rss'>

Related posts:<ol>
<li><a href='http://www.onkarjoshi.com/blog/230/sending-a-sigbreak-signal-to-a-java-process-to-do-a-thread-dump-in-windows/' rel='bookmark' title='Sending a SIGBREAK signal to a Java process to do a thread dump in Windows'>Sending a SIGBREAK signal to a Java process to do a thread dump in Windows</a></li>
<li><a href='http://www.onkarjoshi.com/blog/213/6-things-to-remember-about-saving-memory-with-the-string-intern-method/' rel='bookmark' title='6 things to remember about saving memory with the String.intern method'>6 things to remember about saving memory with the String.intern method</a></li>
<li><a href='http://www.onkarjoshi.com/blog/166/identifying-a-thread-with-high-cpu-usage-in-a-java-app/' rel='bookmark' title='Identifying a thread with high CPU usage in a Java app'>Identifying a thread with high CPU usage in a Java app</a></li>
<li><a href='http://www.onkarjoshi.com/blog/226/crash-your-jvm-by-killing-the-garbage-collector/' rel='bookmark' title='Crash your JVM by killing the garbage collector!'>Crash your JVM by killing the garbage collector!</a></li>
<li><a href='http://www.onkarjoshi.com/blog/199/virtual-machine-error-is-parent-of-out-of-memory-error-and-stack-overflow-error/' rel='bookmark' title='VirtualMachineError is parent of OutOfMemoryError and StackOverflowError'>VirtualMachineError is parent of OutOfMemoryError and StackOverflowError</a></li>
</ol>
</div>
]]></description>
				<content:encoded><![CDATA[<p style="text-align: justify;">Every thread created in a Java program has its own stack space. The stack space used is not allocated from the heap. Infact if you look at the OS report on the memory used by your JVM, you may notice that it is more than what -Xmx parameter specifies. This is because, beside other things, memory is used for the thread stacks too. And this memory is not included in the heap specified by the -Xms and -Xmx switches.</p>
<p style="text-align: justify;">The thread stack is used to push stacks frames in nested method calls. If the nesting is so deep that the thread runs out of space, the thread dies with a StackOverflowError.</p>
<p style="text-align: justify;">The default thread stack size varies with JVM, OS and environment variables. A typical value is 512k. It is generally larger for 64bit JVMs because references are 8 bytes rather than 4 bytes in size. This means that if your app uses 150 threads, 75MB will be used for thread stacks. In some environments the defaults stack may be as large as 2MB. With a large number of threads, this can consume a significant amount of memory which could otherwise be used by your application or OS.</p>
<p style="text-align: justify;">In most applications, 128k happens to be enough for the stack. What you really need to do is adjust and observe. If you don&#8217;t see your app running out of stack space, use the -Xss JVM parameter to specify a smaller stack (-Xss128k).</p>
<p style="text-align: justify;">Note that it is entirely possible that your OS rounds up values for stack size specified by your -Xss parameter. Watch out for that.</p>
<p style="text-align: justify;">Using the program below, you can see how stack space is used up by methods with varying number of arguments. You&#8217;ll get the StackOverflowError with fewer nested method calls for a smaller stack. You could try adjusting the number of arguments and even the type of arguments for different behaviour.</p>
<p>By adjusting the stack size, and keeping the code the same, you can see the JVM dying at different points in the recursive call.</p>
<p><img class="size-full wp-image-210" title="java-xss" src="http://www.onkarjoshi.com/blog/wp-content/uploads/2011/02/java-xss.png" alt="" width="481" height="216" /></p>
<div class='yarpp-related-rss'>
<p>Related posts:<ol>
<li><a href='http://www.onkarjoshi.com/blog/230/sending-a-sigbreak-signal-to-a-java-process-to-do-a-thread-dump-in-windows/' rel='bookmark' title='Sending a SIGBREAK signal to a Java process to do a thread dump in Windows'>Sending a SIGBREAK signal to a Java process to do a thread dump in Windows</a></li>
<li><a href='http://www.onkarjoshi.com/blog/213/6-things-to-remember-about-saving-memory-with-the-string-intern-method/' rel='bookmark' title='6 things to remember about saving memory with the String.intern method'>6 things to remember about saving memory with the String.intern method</a></li>
<li><a href='http://www.onkarjoshi.com/blog/166/identifying-a-thread-with-high-cpu-usage-in-a-java-app/' rel='bookmark' title='Identifying a thread with high CPU usage in a Java app'>Identifying a thread with high CPU usage in a Java app</a></li>
<li><a href='http://www.onkarjoshi.com/blog/226/crash-your-jvm-by-killing-the-garbage-collector/' rel='bookmark' title='Crash your JVM by killing the garbage collector!'>Crash your JVM by killing the garbage collector!</a></li>
<li><a href='http://www.onkarjoshi.com/blog/199/virtual-machine-error-is-parent-of-out-of-memory-error-and-stack-overflow-error/' rel='bookmark' title='VirtualMachineError is parent of OutOfMemoryError and StackOverflowError'>VirtualMachineError is parent of OutOfMemoryError and StackOverflowError</a></li>
</ol></p>
</div>
<img src="http://feeds.feedburner.com/~r/onkarjoshi/~4/v20P1-d_E_o" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.onkarjoshi.com/blog/209/using-xss-to-adjust-java-default-thread-stack-size-to-save-memory-and-prevent-stackoverflowerror/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		<feedburner:origLink>http://www.onkarjoshi.com/blog/209/using-xss-to-adjust-java-default-thread-stack-size-to-save-memory-and-prevent-stackoverflowerror/</feedburner:origLink></item>
		<item>
		<title>Type inference – Generics magic for initializing collections in every project</title>
		<link>http://feedproxy.google.com/~r/onkarjoshi/~3/jeWCtKSSJ1s/</link>
		<comments>http://www.onkarjoshi.com/blog/205/type-inference-generics-magic-for-initializing-collections-in-every-project/#comments</comments>
		<pubDate>Wed, 16 Feb 2011 08:26:22 +0000</pubDate>
		<dc:creator>Onkar Joshi</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Java]]></category>

		<guid isPermaLink="false">http://www.onkarjoshi.com/blog/?p=205</guid>
		<description><![CDATA[The usual syntax for initializing collections in Java is long and boring. The JDK has a type inference feature that makes the task easier. Such methods should probably have been provided with the JDK in the first place. You can add such methods to a Util class in your application for each type of collection [...]<div class='yarpp-related-rss'>

Related posts:<ol>
<li><a href='http://www.onkarjoshi.com/blog/201/concurrenthashset-in-java-from-concurrenthashmap/' rel='bookmark' title='ConcurrentHashSet in Java from ConcurrentHashMap'>ConcurrentHashSet in Java from ConcurrentHashMap</a></li>
<li><a href='http://www.onkarjoshi.com/blog/104/sun-jdk-7-released/' rel='bookmark' title='Sun JDK 7 released'>Sun JDK 7 released</a></li>
<li><a href='http://www.onkarjoshi.com/blog/234/maven-dependency-local-jar-file-from-an-external-third-party-to-be-installed-into-project-repository/' rel='bookmark' title='Maven dependency &#8211; Local jar file from an external third party to be installed into project repository'>Maven dependency &#8211; Local jar file from an external third party to be installed into project repository</a></li>
<li><a href='http://www.onkarjoshi.com/blog/188/hibernateexception-a-collection-with-cascade-all-delete-orphan-was-no-longer-referenced-by-the-owning-entity-instance/' rel='bookmark' title='HibernateException &#8211; A collection with cascade=&#8221;all-delete-orphan&#8221; was no longer referenced by the owning entity instance'>HibernateException &#8211; A collection with cascade=&#8221;all-delete-orphan&#8221; was no longer referenced by the owning entity instance</a></li>
<li><a href='http://www.onkarjoshi.com/blog/166/identifying-a-thread-with-high-cpu-usage-in-a-java-app/' rel='bookmark' title='Identifying a thread with high CPU usage in a Java app'>Identifying a thread with high CPU usage in a Java app</a></li>
</ol>
</div>
]]></description>
				<content:encoded><![CDATA[<p>The usual syntax for initializing collections in Java is long and boring. The JDK has a type inference feature that makes the task easier.</p>
<p>Such methods should probably have been provided with the JDK in the first place. You can add such methods to a Util class in your application for each type of collection that you wish to use and save your self the pain of generic collection initialization throughout your code base.<br />
<br/><br />
<img class="size-full wp-image-206" title="generics-usual" src="http://www.onkarjoshi.com/blog/wp-content/uploads/2011/02/generics-usual.png" alt="" width="621" height="60" /><br />
<br/><br />
<img class="size-full wp-image-207" title="generics-awesome" src="http://www.onkarjoshi.com/blog/wp-content/uploads/2011/02/generics-awesome.png" alt="" width="497" height="58" /><br />
<br/></p>
<p>
The methods in the Util class below use the type inference feature in the JDK to infer the appropriate type at compile time.<br/><br />
<img class="size-full wp-image-208" title="generics-util" src="http://www.onkarjoshi.com/blog/wp-content/uploads/2011/02/generics-util.png" alt="" width="382" height="181" /></p>
<p/>
Nice, eh? Go ahead and use it in your code!</p>
<div class='yarpp-related-rss'>
<p>Related posts:<ol>
<li><a href='http://www.onkarjoshi.com/blog/201/concurrenthashset-in-java-from-concurrenthashmap/' rel='bookmark' title='ConcurrentHashSet in Java from ConcurrentHashMap'>ConcurrentHashSet in Java from ConcurrentHashMap</a></li>
<li><a href='http://www.onkarjoshi.com/blog/104/sun-jdk-7-released/' rel='bookmark' title='Sun JDK 7 released'>Sun JDK 7 released</a></li>
<li><a href='http://www.onkarjoshi.com/blog/234/maven-dependency-local-jar-file-from-an-external-third-party-to-be-installed-into-project-repository/' rel='bookmark' title='Maven dependency &#8211; Local jar file from an external third party to be installed into project repository'>Maven dependency &#8211; Local jar file from an external third party to be installed into project repository</a></li>
<li><a href='http://www.onkarjoshi.com/blog/188/hibernateexception-a-collection-with-cascade-all-delete-orphan-was-no-longer-referenced-by-the-owning-entity-instance/' rel='bookmark' title='HibernateException &#8211; A collection with cascade=&#8221;all-delete-orphan&#8221; was no longer referenced by the owning entity instance'>HibernateException &#8211; A collection with cascade=&#8221;all-delete-orphan&#8221; was no longer referenced by the owning entity instance</a></li>
<li><a href='http://www.onkarjoshi.com/blog/166/identifying-a-thread-with-high-cpu-usage-in-a-java-app/' rel='bookmark' title='Identifying a thread with high CPU usage in a Java app'>Identifying a thread with high CPU usage in a Java app</a></li>
</ol></p>
</div>
<img src="http://feeds.feedburner.com/~r/onkarjoshi/~4/jeWCtKSSJ1s" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.onkarjoshi.com/blog/205/type-inference-generics-magic-for-initializing-collections-in-every-project/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		<feedburner:origLink>http://www.onkarjoshi.com/blog/205/type-inference-generics-magic-for-initializing-collections-in-every-project/</feedburner:origLink></item>
		<item>
		<title>There is a difference between free space and usable space!</title>
		<link>http://feedproxy.google.com/~r/onkarjoshi/~3/ZK7z0gjnXW4/</link>
		<comments>http://www.onkarjoshi.com/blog/203/difference-between-free-space-and-usable-space/#comments</comments>
		<pubDate>Tue, 15 Feb 2011 08:21:43 +0000</pubDate>
		<dc:creator>Onkar Joshi</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Java]]></category>

		<guid isPermaLink="false">http://www.onkarjoshi.com/blog/?p=203</guid>
		<description><![CDATA[You are working on Java code that involves checking if there is enough disk space available to your Java app to complete some task. You look at the File class for ways to do this. You notice the getFreeSpace() method. And you use it to do your checks for the disk space. Voops! That may [...]<div class='yarpp-related-rss'>

Related posts:<ol>
<li><a href='http://www.onkarjoshi.com/blog/209/using-xss-to-adjust-java-default-thread-stack-size-to-save-memory-and-prevent-stackoverflowerror/' rel='bookmark' title='Using -Xss to adjust Java default thread stack size to save memory and prevent StackOverflowError'>Using -Xss to adjust Java default thread stack size to save memory and prevent StackOverflowError</a></li>
<li><a href='http://www.onkarjoshi.com/blog/228/java-nullpointerexception-ninja-10-facts-you-need-to-know-to-avoid-problems-with-null/' rel='bookmark' title='Java NullPointerException Ninja &#8211; 10 facts you need to know to avoid problems with null'>Java NullPointerException Ninja &#8211; 10 facts you need to know to avoid problems with null</a></li>
</ol>
</div>
]]></description>
				<content:encoded><![CDATA[<p style="text-align: justify;">You are working on Java code that involves checking if there is  enough disk space available to your Java app to complete some task.</p>
<p>You look at the <strong>File </strong>class for ways to do this. You notice the  <strong>getFreeSpace()</strong> method. And you use it to do your checks for the disk  space.</p>
<p>Voops! That may work. But it may not. Depends on your operating system and environment configuration.</p>
<p>You should actually be using the <strong>getUsableSpace() </strong>method. This method  does a few additional checks, where possible, about write permissions  and quota available to the user. Also, on some systems a certain percentage of  total disk space is reserved for admin/root users. This can make your  checks for space pass incorrectly if you happen to use the  <strong>getFreeSpace()</strong> method. And you won&#8217;t even find out until it starts  affecting your app in a different environment on your prod boxes.</p>
<p>Now that you&#8217;ve read this, don&#8217;t make that mistake. Use the <strong>getUsableSpace()</strong> method. And send your  colleagues a link to this article to make sure they know to do so too. <img src='http://www.onkarjoshi.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<div class='yarpp-related-rss'>
<p>Related posts:<ol>
<li><a href='http://www.onkarjoshi.com/blog/209/using-xss-to-adjust-java-default-thread-stack-size-to-save-memory-and-prevent-stackoverflowerror/' rel='bookmark' title='Using -Xss to adjust Java default thread stack size to save memory and prevent StackOverflowError'>Using -Xss to adjust Java default thread stack size to save memory and prevent StackOverflowError</a></li>
<li><a href='http://www.onkarjoshi.com/blog/228/java-nullpointerexception-ninja-10-facts-you-need-to-know-to-avoid-problems-with-null/' rel='bookmark' title='Java NullPointerException Ninja &#8211; 10 facts you need to know to avoid problems with null'>Java NullPointerException Ninja &#8211; 10 facts you need to know to avoid problems with null</a></li>
</ol></p>
</div>
<img src="http://feeds.feedburner.com/~r/onkarjoshi/~4/ZK7z0gjnXW4" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.onkarjoshi.com/blog/203/difference-between-free-space-and-usable-space/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.onkarjoshi.com/blog/203/difference-between-free-space-and-usable-space/</feedburner:origLink></item>
		<item>
		<title>ConcurrentHashSet in Java from ConcurrentHashMap</title>
		<link>http://feedproxy.google.com/~r/onkarjoshi/~3/9f-qm9m1at4/</link>
		<comments>http://www.onkarjoshi.com/blog/201/concurrenthashset-in-java-from-concurrenthashmap/#comments</comments>
		<pubDate>Sun, 13 Feb 2011 21:49:12 +0000</pubDate>
		<dc:creator>Onkar Joshi</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Concurrency]]></category>
		<category><![CDATA[Java]]></category>

		<guid isPermaLink="false">http://www.onkarjoshi.com/blog/?p=201</guid>
		<description><![CDATA[Problem While you do have a ConcurrentHashMap class in Java, there is no ConcurrentHashSet. Solution You can easily get a ConcurrentHashSet with the following code - Collections.newSetFromMap(new ConcurrentHashMap&#60;Object,Boolean&#62;()) Notes A Set lends itself to implementation via a Map if you think about it. So can actually just use a Map. But that may not fit [...]<div class='yarpp-related-rss yarpp-related-none'>

No related posts.
</div>
]]></description>
				<content:encoded><![CDATA[<p><strong>Problem</strong><br />
While you do have a ConcurrentHashMap class in Java, there is no ConcurrentHashSet.</p>
<p><strong>Solution</strong><br />
You can easily get a ConcurrentHashSet with the following code -<br />
<span style="color: #000080;"><br />
<em>Collections.newSetFromMap(new ConcurrentHashMap&lt;Object,Boolean&gt;())</em></span></p>
<p><strong>Notes</strong></p>
<ul>
<li>A Set lends itself to implementation via a Map if you think about  it. So can actually just use a Map. But that may not fit in well with  the context of your use.</li>
<li> The HashSet class internally uses a HashMap.</li>
<li>The ConcurrentHashSet obtained via the method inherits pretty much all the concurrency features of the underlying collection.</li>
<li>See <a href="http://download.oracle.com/javase/6/docs/api/java/util/Collections.html#newSetFromMap%28java.util.Map%29" target="_blank">api-docs for newSetFromMap</a></li>
</ul>
<div class='yarpp-related-rss yarpp-related-none'>
<p>No related posts.</p>
</div>
<img src="http://feeds.feedburner.com/~r/onkarjoshi/~4/9f-qm9m1at4" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.onkarjoshi.com/blog/201/concurrenthashset-in-java-from-concurrenthashmap/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		<feedburner:origLink>http://www.onkarjoshi.com/blog/201/concurrenthashset-in-java-from-concurrenthashmap/</feedburner:origLink></item>
		<item>
		<title>VirtualMachineError is parent of OutOfMemoryError and StackOverflowError</title>
		<link>http://feedproxy.google.com/~r/onkarjoshi/~3/e5h6P5-kT4U/</link>
		<comments>http://www.onkarjoshi.com/blog/199/virtual-machine-error-is-parent-of-out-of-memory-error-and-stack-overflow-error/#comments</comments>
		<pubDate>Sat, 12 Feb 2011 21:24:12 +0000</pubDate>
		<dc:creator>Onkar Joshi</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[JVM]]></category>

		<guid isPermaLink="false">http://www.onkarjoshi.com/blog/?p=199</guid>
		<description><![CDATA[Today I noticed that the infamous OutOfMemoryError and StackOverflowError classes are not directly descended from the Error class. Rather, they descend from VirtualMachineError &#8211; &#8220;Thrown to indicate that the Java Virtual Machine is broken or has run out of resources necessary for it to continue operating.&#8221; Nothing terribly useful. But good to know nonetheless for [...]<div class='yarpp-related-rss'>

Related posts:<ol>
<li><a href='http://www.onkarjoshi.com/blog/209/using-xss-to-adjust-java-default-thread-stack-size-to-save-memory-and-prevent-stackoverflowerror/' rel='bookmark' title='Using -Xss to adjust Java default thread stack size to save memory and prevent StackOverflowError'>Using -Xss to adjust Java default thread stack size to save memory and prevent StackOverflowError</a></li>
<li><a href='http://www.onkarjoshi.com/blog/73/googling-sun-developer-network-leads-to-microsoft-visual-studio-ad/' rel='bookmark' title='Googling Sun Developer Network leads to Microsoft Visual Studio ad'>Googling Sun Developer Network leads to Microsoft Visual Studio ad</a></li>
</ol>
</div>
]]></description>
				<content:encoded><![CDATA[<p>Today I noticed that the infamous OutOfMemoryError and  StackOverflowError classes are not directly descended from the Error  class.</p>
<p>Rather, they descend from VirtualMachineError &#8211; &#8220;<em>Thrown to indicate that the Java Virtual Machine is broken or has   run out of resources necessary for it to continue operating.</em>&#8221;</p>
<p>Nothing terribly useful. But good to know nonetheless for a Java developer.</p>
<div class='yarpp-related-rss'>
<p>Related posts:<ol>
<li><a href='http://www.onkarjoshi.com/blog/209/using-xss-to-adjust-java-default-thread-stack-size-to-save-memory-and-prevent-stackoverflowerror/' rel='bookmark' title='Using -Xss to adjust Java default thread stack size to save memory and prevent StackOverflowError'>Using -Xss to adjust Java default thread stack size to save memory and prevent StackOverflowError</a></li>
<li><a href='http://www.onkarjoshi.com/blog/73/googling-sun-developer-network-leads-to-microsoft-visual-studio-ad/' rel='bookmark' title='Googling Sun Developer Network leads to Microsoft Visual Studio ad'>Googling Sun Developer Network leads to Microsoft Visual Studio ad</a></li>
</ol></p>
</div>
<img src="http://feeds.feedburner.com/~r/onkarjoshi/~4/e5h6P5-kT4U" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.onkarjoshi.com/blog/199/virtual-machine-error-is-parent-of-out-of-memory-error-and-stack-overflow-error/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.onkarjoshi.com/blog/199/virtual-machine-error-is-parent-of-out-of-memory-error-and-stack-overflow-error/</feedburner:origLink></item>
		<item>
		<title>Use binary diff tools like xdelta, bsdiff/bspatch to transfer large files</title>
		<link>http://feedproxy.google.com/~r/onkarjoshi/~3/tkyjG0a4ME8/</link>
		<comments>http://www.onkarjoshi.com/blog/197/use-binary-diff-tools-like-xdelta-bsdiff-bspatch-to-transfer-large-files/#comments</comments>
		<pubDate>Fri, 24 Sep 2010 02:53:49 +0000</pubDate>
		<dc:creator>Onkar Joshi</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[tools]]></category>
		<category><![CDATA[Unix]]></category>
		<category><![CDATA[util]]></category>

		<guid isPermaLink="false">http://www.onkarjoshi.com/blog/?p=197</guid>
		<description><![CDATA[What do you do if you have to frequently transfer large files over a slow connection as part of your work? Perhaps new builds produced by your corporate build server need to be deployed at a different location for the QA team? I have seen such scenarios causing huge amounts of wasted time for multiple [...]<div class='yarpp-related-rss'>

Related posts:<ol>
<li><a href='http://www.onkarjoshi.com/blog/126/which-library-to-use-for-ftp-sftp-ftps-file-transfer-in-java/' rel='bookmark' title='Which library to use for FTP, SFTP, FTPS file transfer in Java?'>Which library to use for FTP, SFTP, FTPS file transfer in Java?</a></li>
<li><a href='http://www.onkarjoshi.com/blog/119/check-for-corruption-of-files-using-md5-checksum-via-md5sum-or-winmd5/' rel='bookmark' title='Check for corruption of files using md5 checksum'>Check for corruption of files using md5 checksum</a></li>
<li><a href='http://www.onkarjoshi.com/blog/123/how-to-create-a-file-of-arbitrary-size-with-shell-script-commands/' rel='bookmark' title='How to create a file of arbitrary size with shell script commands'>How to create a file of arbitrary size with shell script commands</a></li>
<li><a href='http://www.onkarjoshi.com/blog/241/find-duplicate-files/' rel='bookmark' title='Find duplicate files'>Find duplicate files</a></li>
</ol>
</div>
]]></description>
				<content:encoded><![CDATA[<p style="text-align: justify;">What do you do if you have to frequently transfer large files over a  slow connection as part of your work? Perhaps new builds produced by  your corporate build server need to be deployed at a different location  for the QA team? I have seen such scenarios causing huge amounts of  wasted time for multiple teams that I have worked with. How do we fix  this?</p>
<p style="text-align: justify;">Transfer only the difference!</p>
<p style="text-align: justify;">In almost all cases, the files that are changed between builds are very few.</p>
<p style="text-align: justify;">In one of the cases where my team encountered this, they used to  transfer 25MB EAR files over a very slow network to be deployed in a  different location &#8211; this took them around 20 minutes each time. By transferring only the changes, we were able to bring  down the data that needed to be transferred to only 1MB or so. That was a  massive productivity boost for the team.</p>
<p style="text-align: justify;">In another case, my team transferred build artifacts around 1 GB in  size. After a few tests, I found that the difference generated for these  between subsequent builds was only 50MB or so!</p>
<p style="text-align: justify;">In more practical terms: Say an &#8220;oldFile&#8221; is available at both locations  and &#8220;newFile&#8221; is available at one of them. You generate the &#8220;patchFile&#8221;  where both newFile and oldFile are present. You transfer patchFile to  where you have just oldfile. Apply patchFile to the oldFile. The newFile  is now available to you here too!</p>
<p style="text-align: justify;">You can compress the patch file too. Unless your tool already does so (a  flag perhaps?), you should probably do so unless your patches are small  enough anyway.</p>
<p style="text-align: justify;">There are multiple utils available to this. They are generally referred  to as binary diff or byte level differencing tools and use some very  clever algorithms to do what they do.</p>
<p style="text-align: justify;"><strong>xdelta </strong>- I used this one. Produced smaller patches for me. Free!</p>
<p style="text-align: justify;"><strong>bsdiff </strong>/ <strong>bspatch </strong>- Part of Unix/Linux type systems. Standard commands which are always available. Free!</p>
<p style="text-align: justify;"><strong>RTPatch </strong>- Enterprise features. Costs moolah.</p>
<p style="text-align: justify;">Go ahead, save a bunch of time for your team today!</p>
<div class='yarpp-related-rss'>
<p>Related posts:<ol>
<li><a href='http://www.onkarjoshi.com/blog/126/which-library-to-use-for-ftp-sftp-ftps-file-transfer-in-java/' rel='bookmark' title='Which library to use for FTP, SFTP, FTPS file transfer in Java?'>Which library to use for FTP, SFTP, FTPS file transfer in Java?</a></li>
<li><a href='http://www.onkarjoshi.com/blog/119/check-for-corruption-of-files-using-md5-checksum-via-md5sum-or-winmd5/' rel='bookmark' title='Check for corruption of files using md5 checksum'>Check for corruption of files using md5 checksum</a></li>
<li><a href='http://www.onkarjoshi.com/blog/123/how-to-create-a-file-of-arbitrary-size-with-shell-script-commands/' rel='bookmark' title='How to create a file of arbitrary size with shell script commands'>How to create a file of arbitrary size with shell script commands</a></li>
<li><a href='http://www.onkarjoshi.com/blog/241/find-duplicate-files/' rel='bookmark' title='Find duplicate files'>Find duplicate files</a></li>
</ol></p>
</div>
<img src="http://feeds.feedburner.com/~r/onkarjoshi/~4/tkyjG0a4ME8" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.onkarjoshi.com/blog/197/use-binary-diff-tools-like-xdelta-bsdiff-bspatch-to-transfer-large-files/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		<feedburner:origLink>http://www.onkarjoshi.com/blog/197/use-binary-diff-tools-like-xdelta-bsdiff-bspatch-to-transfer-large-files/</feedburner:origLink></item>
		<item>
		<title>Eclipse tip: Add a short cut key to Skip All Breakpoints</title>
		<link>http://feedproxy.google.com/~r/onkarjoshi/~3/aAw0z6LMdg4/</link>
		<comments>http://www.onkarjoshi.com/blog/194/eclipse-tip-add-a-short-cut-key-to-skip-all-breakpoints/#comments</comments>
		<pubDate>Wed, 22 Sep 2010 03:00:38 +0000</pubDate>
		<dc:creator>Onkar Joshi</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Eclipse]]></category>
		<category><![CDATA[Java]]></category>

		<guid isPermaLink="false">http://www.onkarjoshi.com/blog/?p=194</guid>
		<description><![CDATA[Eclipse doesn&#8217;t have a short cut key bound by default to the &#8216;Skip all breakpoints&#8217; functionality. Here is how you can set one. While you are at it, you probably want to define a few more shortcuts to functionality you use frequently. In Eclipse, go to Window &#62; Preferences &#62; Type in &#8216;Keys&#8217; in the [...]<div class='yarpp-related-rss'>

Related posts:<ol>
<li><a href='http://www.onkarjoshi.com/blog/159/conditional-breakpoints-in-java-development-with-eclipse/' rel='bookmark' title='Conditional breakpoints in Java development with Eclipse'>Conditional breakpoints in Java development with Eclipse</a></li>
<li><a href='http://www.onkarjoshi.com/blog/84/configuring-eclipse-to-use-a-jdk-at-a-location-with-spaces-in-it/' rel='bookmark' title='Configuring Eclipse to use a JDK at a location with spaces in it'>Configuring Eclipse to use a JDK at a location with spaces in it</a></li>
<li><a href='http://www.onkarjoshi.com/blog/163/debug-with-step-filters-in-eclipse/' rel='bookmark' title='Debug with Step Filters in Eclipse'>Debug with Step Filters in Eclipse</a></li>
<li><a href='http://www.onkarjoshi.com/blog/130/add-site-owner-verification-code-for-a-free-wordpress-com-blog/' rel='bookmark' title='Add site owner verification code for a free WordPress.com blog'>Add site owner verification code for a free WordPress.com blog</a></li>
<li><a href='http://www.onkarjoshi.com/blog/73/googling-sun-developer-network-leads-to-microsoft-visual-studio-ad/' rel='bookmark' title='Googling Sun Developer Network leads to Microsoft Visual Studio ad'>Googling Sun Developer Network leads to Microsoft Visual Studio ad</a></li>
</ol>
</div>
]]></description>
				<content:encoded><![CDATA[<p style="text-align: justify;">Eclipse doesn&#8217;t have a short cut key bound by default to the &#8216;Skip all breakpoints&#8217; functionality.</p>
<p style="text-align: justify;">Here is how you can set one. While you are at it, you probably  want to define a few more shortcuts to functionality you use frequently.</p>
<p style="text-align: justify;">In Eclipse, go to <strong>Window </strong>&gt; <strong>Preferences </strong>&gt; <em>Type in &#8216;Keys&#8217; in the  search box</em> &gt; Select &#8216;<strong>Keys</strong>&#8216; to get the screen to edit the command  bindings.</p>
<p style="text-align: justify;">Search for the &#8216;Skip All Breakpoints&#8217; command. Add your preferred shortcut at the Binding field. I use <em>Ctrl+Alt+B</em>.</p>
<p style="text-align: justify;">If you toggle that bit of functionality as often as I do, you know this is gonna save you a bunch of time.</p>
<p style="text-align: justify;">Any non-default bindings you use all the time? Lemme know!<a href="http://www.onkarjoshi.com/blog/wp-content/uploads/2010/09/skip-all-breakpoints-shortcut-key.png"><br />
</a></p>
<div class='yarpp-related-rss'>
<p>Related posts:<ol>
<li><a href='http://www.onkarjoshi.com/blog/159/conditional-breakpoints-in-java-development-with-eclipse/' rel='bookmark' title='Conditional breakpoints in Java development with Eclipse'>Conditional breakpoints in Java development with Eclipse</a></li>
<li><a href='http://www.onkarjoshi.com/blog/84/configuring-eclipse-to-use-a-jdk-at-a-location-with-spaces-in-it/' rel='bookmark' title='Configuring Eclipse to use a JDK at a location with spaces in it'>Configuring Eclipse to use a JDK at a location with spaces in it</a></li>
<li><a href='http://www.onkarjoshi.com/blog/163/debug-with-step-filters-in-eclipse/' rel='bookmark' title='Debug with Step Filters in Eclipse'>Debug with Step Filters in Eclipse</a></li>
<li><a href='http://www.onkarjoshi.com/blog/130/add-site-owner-verification-code-for-a-free-wordpress-com-blog/' rel='bookmark' title='Add site owner verification code for a free WordPress.com blog'>Add site owner verification code for a free WordPress.com blog</a></li>
<li><a href='http://www.onkarjoshi.com/blog/73/googling-sun-developer-network-leads-to-microsoft-visual-studio-ad/' rel='bookmark' title='Googling Sun Developer Network leads to Microsoft Visual Studio ad'>Googling Sun Developer Network leads to Microsoft Visual Studio ad</a></li>
</ol></p>
</div>
<img src="http://feeds.feedburner.com/~r/onkarjoshi/~4/aAw0z6LMdg4" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.onkarjoshi.com/blog/194/eclipse-tip-add-a-short-cut-key-to-skip-all-breakpoints/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		<feedburner:origLink>http://www.onkarjoshi.com/blog/194/eclipse-tip-add-a-short-cut-key-to-skip-all-breakpoints/</feedburner:origLink></item>
		<item>
		<title>/dev/random vs /dev/urandom</title>
		<link>http://feedproxy.google.com/~r/onkarjoshi/~3/xCf5yDPq4Xg/</link>
		<comments>http://www.onkarjoshi.com/blog/191/device-dev-random-vs-urandom/#comments</comments>
		<pubDate>Tue, 21 Sep 2010 02:49:28 +0000</pubDate>
		<dc:creator>Onkar Joshi</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Random]]></category>
		<category><![CDATA[RNG]]></category>
		<category><![CDATA[Unix]]></category>

		<guid isPermaLink="false">http://www.onkarjoshi.com/blog/?p=191</guid>
		<description><![CDATA[If you want random data in a Linux/Unix type OS, the standard way to do so is to use /dev/random or /dev/urandom. These devices are special files. They can be read like normal files and the read data is generated via multiple sources of entropy in the system which provide the randomness. /dev/random will block [...]<div class='yarpp-related-rss'>

Related posts:<ol>
<li><a href='http://www.onkarjoshi.com/blog/123/how-to-create-a-file-of-arbitrary-size-with-shell-script-commands/' rel='bookmark' title='How to create a file of arbitrary size with shell script commands'>How to create a file of arbitrary size with shell script commands</a></li>
<li><a href='http://www.onkarjoshi.com/blog/77/how-to-split-a-file-process-the-pieces-in-multiple-threads-and-combine-results-using-a-shell-script/' rel='bookmark' title='How to split a file, process the pieces in multiple threads and combine results using a shell script'>How to split a file, process the pieces in multiple threads and combine results using a shell script</a></li>
</ol>
</div>
]]></description>
				<content:encoded><![CDATA[<p style="text-align: justify;">If you want random data in a Linux/Unix type OS, the standard way to do  so is to use /dev/random or /dev/urandom. These devices are special  files. They can be read like normal files and the read data is generated  via multiple sources of entropy in the system which provide the  randomness.</p>
<p style="text-align: justify;">/dev/random will block after the entropy pool is exhausted. It will  remain blocked until additional data has been collected from the sources  of entropy that are available. This can slow down random data  generation.</p>
<p style="text-align: justify;">/dev/urandom will not block. Instead it will reuse the internal pool to produce more pseudo-random bits.</p>
<p>/dev/urandom is best used when:</p>
<ul>
<li>You just want a large file with random data for some kind of testing.</li>
<li>You are using the dd command to wipe data off a disk by replacing it with random data.</li>
<li>Almost everywhere else where you don&#8217;t have a really good reason to use /dev/random instead.</li>
</ul>
<p>/dev/random is likely to be the better choice when:</p>
<ul>
<li>Randomness is critical to the security of cryptography in your application &#8211; one-time pads, key generation.</li>
</ul>
<div class='yarpp-related-rss'>
<p>Related posts:<ol>
<li><a href='http://www.onkarjoshi.com/blog/123/how-to-create-a-file-of-arbitrary-size-with-shell-script-commands/' rel='bookmark' title='How to create a file of arbitrary size with shell script commands'>How to create a file of arbitrary size with shell script commands</a></li>
<li><a href='http://www.onkarjoshi.com/blog/77/how-to-split-a-file-process-the-pieces-in-multiple-threads-and-combine-results-using-a-shell-script/' rel='bookmark' title='How to split a file, process the pieces in multiple threads and combine results using a shell script'>How to split a file, process the pieces in multiple threads and combine results using a shell script</a></li>
</ol></p>
</div>
<img src="http://feeds.feedburner.com/~r/onkarjoshi/~4/xCf5yDPq4Xg" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.onkarjoshi.com/blog/191/device-dev-random-vs-urandom/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.onkarjoshi.com/blog/191/device-dev-random-vs-urandom/</feedburner:origLink></item>
		<item>
		<title>HibernateException – A collection with cascade=”all-delete-orphan” was no longer referenced by the owning entity instance</title>
		<link>http://feedproxy.google.com/~r/onkarjoshi/~3/RRTL3z-ETu8/</link>
		<comments>http://www.onkarjoshi.com/blog/188/hibernateexception-a-collection-with-cascade-all-delete-orphan-was-no-longer-referenced-by-the-owning-entity-instance/#comments</comments>
		<pubDate>Mon, 20 Sep 2010 02:30:56 +0000</pubDate>
		<dc:creator>Onkar Joshi</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Hibernate]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[JPA]]></category>
		<category><![CDATA[ORM]]></category>

		<guid isPermaLink="false">http://www.onkarjoshi.com/blog/?p=188</guid>
		<description><![CDATA[The logged exception org.hibernate.HibernateException &#8211; &#8220;A collection with cascade=&#8221;all-delete-orphan&#8221; was no longer referenced by the owning entity instance: com.onkarjoshi.hibernate.test.Person.children&#8221; Your likely problem Looks like you have a Parent entity and a Child entity. The Parent has a collection of Child entities with cascade=&#8221;all-delete-orphan&#8221;. You are setting a new collection via the setter thus leaving the [...]<div class='yarpp-related-rss'>

Related posts:<ol>
<li><a href='http://www.onkarjoshi.com/blog/186/garbage-collection-and-reachability-strong-soft-weak-phantom-unreachable/' rel='bookmark' title='Garbage Collection, Reference types and Reachability &#8211; Strong, Soft, Weak, Phantom, Unreachable'>Garbage Collection, Reference types and Reachability &#8211; Strong, Soft, Weak, Phantom, Unreachable</a></li>
</ol>
</div>
]]></description>
				<content:encoded><![CDATA[<p style="text-align: justify;"><strong><span style="font-size: medium;">The logged exception</span></strong></p>
<p>org.hibernate.HibernateException &#8211; &#8220;A collection with  cascade=&#8221;all-delete-orphan&#8221; was no longer referenced by the owning  entity instance: com.onkarjoshi.hibernate.test.Person.children&#8221;<br />
<strong><br />
<span style="font-size: medium;">Your likely problem</span></strong></p>
<p>Looks like you have a Parent entity and a Child entity. The Parent has a collection of Child entities with cascade=&#8221;all-delete-orphan&#8221;.</p>
<p style="text-align: justify;">You are setting a new collection via the setter thus leaving the original collection unreferenced by the Parent entity. This doesn&#8217;t fly well with Hibernate and leaves it confused about what to do.</p>
<p style="text-align: justify;">parent.setChilden(new HashSet&lt;Child&gt;()); // This won&#8217;t work. Could be an ArrayList too.</p>
<p style="text-align: justify;">parent.getChildren().clear(); // There, fixed that!</p>
<p style="text-align: justify;">So generally speaking, <em>just clear out the old collection, rather than dereferencing it and creating a new one</em>.</p>
<div class='yarpp-related-rss'>
<p>Related posts:<ol>
<li><a href='http://www.onkarjoshi.com/blog/186/garbage-collection-and-reachability-strong-soft-weak-phantom-unreachable/' rel='bookmark' title='Garbage Collection, Reference types and Reachability &#8211; Strong, Soft, Weak, Phantom, Unreachable'>Garbage Collection, Reference types and Reachability &#8211; Strong, Soft, Weak, Phantom, Unreachable</a></li>
</ol></p>
</div>
<img src="http://feeds.feedburner.com/~r/onkarjoshi/~4/RRTL3z-ETu8" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.onkarjoshi.com/blog/188/hibernateexception-a-collection-with-cascade-all-delete-orphan-was-no-longer-referenced-by-the-owning-entity-instance/feed/</wfw:commentRss>
		<slash:comments>22</slash:comments>
		<feedburner:origLink>http://www.onkarjoshi.com/blog/188/hibernateexception-a-collection-with-cascade-all-delete-orphan-was-no-longer-referenced-by-the-owning-entity-instance/</feedburner:origLink></item>
		<item>
		<title>Garbage Collection, Reference types and Reachability – Strong, Soft, Weak, Phantom, Unreachable</title>
		<link>http://feedproxy.google.com/~r/onkarjoshi/~3/I1lgg2ZzthY/</link>
		<comments>http://www.onkarjoshi.com/blog/186/garbage-collection-and-reachability-strong-soft-weak-phantom-unreachable/#comments</comments>
		<pubDate>Sat, 18 Sep 2010 20:21:56 +0000</pubDate>
		<dc:creator>Onkar Joshi</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Garbage Collector]]></category>
		<category><![CDATA[GC]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[JVM]]></category>

		<guid isPermaLink="false">http://www.onkarjoshi.com/blog/?p=186</guid>
		<description><![CDATA[The Java Virtual Machine has 5 different levels of reachability for an object. Strongly reachable An object is strongly reachable if it can be reached by some thread without traversing any reference objects. A newly-created object is strongly reachable by the thread that created it. This is the reference you know about and use all [...]<div class='yarpp-related-rss'>

Related posts:<ol>
<li><a href='http://www.onkarjoshi.com/blog/246/java-the-4-innernested-class-types/' rel='bookmark' title='Java &#8211; The 4 inner/nested class types'>Java &#8211; The 4 inner/nested class types</a></li>
<li><a href='http://www.onkarjoshi.com/blog/226/crash-your-jvm-by-killing-the-garbage-collector/' rel='bookmark' title='Crash your JVM by killing the garbage collector!'>Crash your JVM by killing the garbage collector!</a></li>
<li><a href='http://www.onkarjoshi.com/blog/222/assigning-a-reference-to-itself-in-java-has-no-effect-right-wrong/' rel='bookmark' title='Assigning a reference to itself in Java has no effect, right? &#8211; WRONG!'>Assigning a reference to itself in Java has no effect, right? &#8211; WRONG!</a></li>
<li><a href='http://www.onkarjoshi.com/blog/219/volatile-array/' rel='bookmark' title='Atomic array classes and volatile arrays in the JVM'>Atomic array classes and volatile arrays in the JVM</a></li>
<li><a href='http://www.onkarjoshi.com/blog/188/hibernateexception-a-collection-with-cascade-all-delete-orphan-was-no-longer-referenced-by-the-owning-entity-instance/' rel='bookmark' title='HibernateException &#8211; A collection with cascade=&#8221;all-delete-orphan&#8221; was no longer referenced by the owning entity instance'>HibernateException &#8211; A collection with cascade=&#8221;all-delete-orphan&#8221; was no longer referenced by the owning entity instance</a></li>
</ol>
</div>
]]></description>
				<content:encoded><![CDATA[<p style="text-align: justify;">The Java Virtual Machine has 5 different levels of reachability for an object.</p>
<p><strong><span style="font-size: medium;">Strongly reachable</span></strong></p>
<ul>
<li style="text-align: justify;">An object is <em>strongly reachable</em> if it can be reached by some thread without traversing any reference objects.  A newly-created object is strongly reachable by the thread that created it.</li>
</ul>
<p style="text-align: justify;">This is the reference you know about and use all the time. Any  object that is reachable by a strong reference (from a live thread)  will not be collected by the GC.</p>
<p><strong><span style="font-size: medium;">Softly reachable</span></strong></p>
<ul>
<li style="text-align: justify;">An object is <em>softly reachable</em> if it is not strongly reachable but can be reached by traversing a soft reference.</li>
</ul>
<p style="text-align: justify;">The garbage collector will collect softly reachable objects only if it  actually requires more memory. Before it does a GC it is guaranteed to  collect softly reachable objects.</p>
<p style="text-align: justify;">So it is possible to write code on the lines of &#8211; &#8220;<em>Hey, I do want  this data to be kept in memory. But in case the JVM starts running out  of memory, go ahead and collect it and null out the referent. I&#8217;ll  handle it in my code.</em>&#8221; The exact algorithm that is used to determine  whether a SoftReference should be cleared out is JVM vendor dependent.  It tends to be a function of how often and how long ago the reference  was last used to reach the referent.</p>
<p style="text-align: justify;">The semantics of a SoftReference make it possible to make a memory sensitive cache. The gotcha  is that the exact behaviour will be JVM dependent. And as with anything  else related to garbage collector behaviour, guarantees are few and are  vendor dependent. For higher reliability (and many more features) most  people tend to use something like Ehcache rather than roll out their own  caching logic using SoftReference unless they have a very simple use  case. Used in the right situation, they certainly can result in some  elegant, simple code.</p>
<p><strong><span style="font-size: medium;">Weakly reachable</span></strong></p>
<ul>
<li style="text-align: justify;">An object is <em>weakly reachable</em> if it is neither strongly nor softly reachable but can be reached by traversing a weak reference.  When the weak references to a weakly-reachable object are cleared, the object becomes eligible for finalization.</li>
</ul>
<p style="text-align: justify;">In a nut-shell, a weak reference  will not prevent its referent from being collected by the garbage  collector. The most common use case of a WeakReference is via a  WeakHashMap. It is an easy way to associate data with an object bound to  the lifetime of the object. The bound data will stay in the map only  while the key is not weakly reachable due to the key being strongly  reachable because of reachability via a reference elsewhere in the  application. Once all other references in the application are gone, the  key becomes weakly reachable and is gone from the map without the user  needing to explicitly remove the entry. An elegant way to prevent memory  leaks in some cases!</p>
<p><strong><span style="font-size: medium;">Phantom reachable</span></strong></p>
<ul>
<li style="text-align: justify;">An object is <em>phantom reachable</em> if it is neither strongly, softly, nor weakly reachable, it has been finalized, and some phantom reference refers to it.</li>
</ul>
<p style="text-align: justify;">The referent of a PhantomReference can never be retrieved. The  get() method on this reference always returns null! So what is the use?</p>
<p style="text-align: justify;">All  Reference types allow specifying a ReferenceQueue in the constructor.  The semantics of how and when a PhantomReference is enqueued makes it  possible to do finalization in a better, less fragile way. More on that  in a future blog post perhaps.</p>
<p><strong><span style="font-size: medium;">Unreachable</span></strong></p>
<ul>
<li style="text-align: justify;">An object is <em>unreachable</em>, and therefore eligible for reclamation, when it is not reachable in any of the above ways.</li>
</ul>
<p><em>See also: <a href="http://download.oracle.com/javase/6/docs/api/java/lang/ref/package-summary.html">Package java.lang.ref</a></em></p>
<div class='yarpp-related-rss'>
<p>Related posts:<ol>
<li><a href='http://www.onkarjoshi.com/blog/246/java-the-4-innernested-class-types/' rel='bookmark' title='Java &#8211; The 4 inner/nested class types'>Java &#8211; The 4 inner/nested class types</a></li>
<li><a href='http://www.onkarjoshi.com/blog/226/crash-your-jvm-by-killing-the-garbage-collector/' rel='bookmark' title='Crash your JVM by killing the garbage collector!'>Crash your JVM by killing the garbage collector!</a></li>
<li><a href='http://www.onkarjoshi.com/blog/222/assigning-a-reference-to-itself-in-java-has-no-effect-right-wrong/' rel='bookmark' title='Assigning a reference to itself in Java has no effect, right? &#8211; WRONG!'>Assigning a reference to itself in Java has no effect, right? &#8211; WRONG!</a></li>
<li><a href='http://www.onkarjoshi.com/blog/219/volatile-array/' rel='bookmark' title='Atomic array classes and volatile arrays in the JVM'>Atomic array classes and volatile arrays in the JVM</a></li>
<li><a href='http://www.onkarjoshi.com/blog/188/hibernateexception-a-collection-with-cascade-all-delete-orphan-was-no-longer-referenced-by-the-owning-entity-instance/' rel='bookmark' title='HibernateException &#8211; A collection with cascade=&#8221;all-delete-orphan&#8221; was no longer referenced by the owning entity instance'>HibernateException &#8211; A collection with cascade=&#8221;all-delete-orphan&#8221; was no longer referenced by the owning entity instance</a></li>
</ol></p>
</div>
<img src="http://feeds.feedburner.com/~r/onkarjoshi/~4/I1lgg2ZzthY" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.onkarjoshi.com/blog/186/garbage-collection-and-reachability-strong-soft-weak-phantom-unreachable/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		<feedburner:origLink>http://www.onkarjoshi.com/blog/186/garbage-collection-and-reachability-strong-soft-weak-phantom-unreachable/</feedburner:origLink></item>
		<item>
		<title>Blocked thread with Read Write Lock due to writer starvation</title>
		<link>http://feedproxy.google.com/~r/onkarjoshi/~3/T-jg9yesu34/</link>
		<comments>http://www.onkarjoshi.com/blog/183/blocked-thread-with-readwritelock-due-to-writer-starvation/#comments</comments>
		<pubDate>Sun, 05 Sep 2010 07:51:50 +0000</pubDate>
		<dc:creator>Onkar Joshi</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Concurrency]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Lock]]></category>
		<category><![CDATA[Threads]]></category>

		<guid isPermaLink="false">http://www.onkarjoshi.com/blog/?p=183</guid>
		<description><![CDATA[Here is an interesting and simple example of how you can end up with a locked thread in your application and what you can do to avoid it. Task A &#8211; Starts at t = 0. Takes a read lock. Runs for 3 seconds. Scheduled to run every 5 seconds. Task B &#8211; Starts at [...]<div class='yarpp-related-rss'>

Related posts:<ol>
<li><a href='http://www.onkarjoshi.com/blog/76/java-synchronization-benchmark/' rel='bookmark' title='Java Synchronization Benchmark'>Java Synchronization Benchmark</a></li>
<li><a href='http://www.onkarjoshi.com/blog/222/assigning-a-reference-to-itself-in-java-has-no-effect-right-wrong/' rel='bookmark' title='Assigning a reference to itself in Java has no effect, right? &#8211; WRONG!'>Assigning a reference to itself in Java has no effect, right? &#8211; WRONG!</a></li>
<li><a href='http://www.onkarjoshi.com/blog/203/difference-between-free-space-and-usable-space/' rel='bookmark' title='There is a difference between free space and usable space!'>There is a difference between free space and usable space!</a></li>
<li><a href='http://www.onkarjoshi.com/blog/230/sending-a-sigbreak-signal-to-a-java-process-to-do-a-thread-dump-in-windows/' rel='bookmark' title='Sending a SIGBREAK signal to a Java process to do a thread dump in Windows'>Sending a SIGBREAK signal to a Java process to do a thread dump in Windows</a></li>
</ol>
</div>
]]></description>
				<content:encoded><![CDATA[<p style="text-align: justify;">Here is an interesting and simple example of how you can end up with a  locked thread in your application and what you can do to avoid it.</p>
<p style="text-align: justify;">Task A &#8211; Starts at t = 0. Takes a read lock. Runs for 3 seconds. Scheduled to run every 5 seconds.</p>
<p style="text-align: justify;">Task B &#8211; Starts at t = 2. Takes a read lock. Runs for 3 seconds. Scheduled to run every 5 seconds.</p>
<p><tt>t -&gt;<br />
AAAXXAAAXXAAAXXAAAXXAAAXX...<br />
XXBBBXXBBBXXBBBXXBBBXXBBB...</tt></p>
<p style="text-align: justify;">Task C &#8211; Starts at t = 10 (or rather tries to start at any time after t = 0) . Tries to take a write lock. Can never get it!</p>
<p style="text-align: justify;">With  the scheduling above, either A or B always have the read lock. A write  lock can be acquired only if there are no read locks given out. So if  Task C starts later and tries to get the write lock (which it gets only  when no read locks have been granted) then Task C will get stuck for  eternity.</p>
<p style="text-align: justify;">One may think that this situation is rare. But it is not. With the  common scenario of many readers and few or rare writers, it can happen  quite often. While the lock throughput may be high, there are no  guarantees about fairness.</p>
<p style="text-align: justify;">To counter this situation, we introduce the concept of a fairness  policy in granting locks. Depending on fairness, a thread requesting a  read lock may block if a writer thread is already waiting for a write  lock. <em>This means that a read lock will not be granted even if no write lock has currently been granted! </em>This is known as a write biased read write lock. The pitfall is that the fairness overhead can reduce throughput drastically for a highly concurrent application.</p>
<p style="text-align: justify;">The recommendation is to use truly concurrent data structures like  ConcurrentHashMap or ConcurrentLinkedQueue if possible rather than going  for the cheap (in terms of development time) protection of your data  structures via a ReadWriteLock. If it is a custom data structure, the  RWL can certainly be an easy way of increasing concurrency rather than  redesigning your stuff for concurrency with volatiles, reference  variables, lock striping, atomic variable, CAS (compare-and swap),  condition queues and other concurrent data structure design techniques.</p>
<p style="text-align: justify;">In Java, the class ReentrantReadWriteLock class which implements the ReadWriteLock interface takes a boolean argument in a constructor to indicate fairness.</p>
<p style="text-align: justify;">In .NET, the ReaderWriterLockSlim class provides similar functionality.</p>
<p style="text-align: justify;">See <a href="http://www.javaspecialists.eu/archive/Issue165.html">this</a> article from the <em>Java Specialists</em> newsletter for benchmarks and numbers comparing fair and non-fair locks and their behaviour in Java 5 and Java 6.</p>
<div class='yarpp-related-rss'>
<p>Related posts:<ol>
<li><a href='http://www.onkarjoshi.com/blog/76/java-synchronization-benchmark/' rel='bookmark' title='Java Synchronization Benchmark'>Java Synchronization Benchmark</a></li>
<li><a href='http://www.onkarjoshi.com/blog/222/assigning-a-reference-to-itself-in-java-has-no-effect-right-wrong/' rel='bookmark' title='Assigning a reference to itself in Java has no effect, right? &#8211; WRONG!'>Assigning a reference to itself in Java has no effect, right? &#8211; WRONG!</a></li>
<li><a href='http://www.onkarjoshi.com/blog/203/difference-between-free-space-and-usable-space/' rel='bookmark' title='There is a difference between free space and usable space!'>There is a difference between free space and usable space!</a></li>
<li><a href='http://www.onkarjoshi.com/blog/230/sending-a-sigbreak-signal-to-a-java-process-to-do-a-thread-dump-in-windows/' rel='bookmark' title='Sending a SIGBREAK signal to a Java process to do a thread dump in Windows'>Sending a SIGBREAK signal to a Java process to do a thread dump in Windows</a></li>
</ol></p>
</div>
<img src="http://feeds.feedburner.com/~r/onkarjoshi/~4/T-jg9yesu34" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.onkarjoshi.com/blog/183/blocked-thread-with-readwritelock-due-to-writer-starvation/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		<feedburner:origLink>http://www.onkarjoshi.com/blog/183/blocked-thread-with-readwritelock-due-to-writer-starvation/</feedburner:origLink></item>
		<item>
		<title>Patni walk-in ad on Facebook</title>
		<link>http://feedproxy.google.com/~r/onkarjoshi/~3/NweHr6SlNJQ/</link>
		<comments>http://www.onkarjoshi.com/blog/180/patni-walk-in-ad-on-facebook/#comments</comments>
		<pubDate>Sun, 29 Aug 2010 08:16:33 +0000</pubDate>
		<dc:creator>Onkar Joshi</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[adsense]]></category>
		<category><![CDATA[Advertising]]></category>
		<category><![CDATA[facebook]]></category>
		<category><![CDATA[Google]]></category>
		<category><![CDATA[linkedin]]></category>
		<category><![CDATA[Patni]]></category>
		<category><![CDATA[privacy]]></category>

		<guid isPermaLink="false">http://www.onkarjoshi.com/blog/?p=180</guid>
		<description><![CDATA[Patni Computer Systems is a large IT services company and operates out of several locations in India. A few days back Facebook decided to show me this ad for walk-in interviews. Nothing unremarkable about it except that it is probably the first IT company ad that I saw on Facebook. Interesting. Many people fill in [...]<div class='yarpp-related-rss yarpp-related-none'>

No related posts.
</div>
]]></description>
				<content:encoded><![CDATA[<p style="text-align: justify;">Patni Computer Systems is a large IT services company and operates out of several locations in India. A few days back Facebook decided to show me this ad for walk-in interviews.</p>
<p style="text-align: justify;">Nothing unremarkable about it except that it is probably the first IT company ad that I saw on Facebook.</p>
<p style="text-align: justify;"><img class="aligncenter size-full wp-image-181" title="patni-walk-in-facebook-ad" src="http://www.onkarjoshi.com/blog/wp-content/uploads/2010/08/patni-walk-in-facebook-ad.png" alt="" width="151" height="213" /></p>
<p style="text-align: justify;">Interesting. Many people fill in the names of current and past employers, how long they have been there and which city they are based in. If I were a recruiter at Infosys, Wipro, TCS etc., I would consider doing some targeted advertising. If there were a place to put in core tech skills &#8211; recruiters would be able to do some really targeted advertising like: &#8220;show this ad to all people with SAP in their core skills living in Pune and have been with current employer for over 2 years&#8221;.</p>
<p style="text-align: justify;">Maybe Facebook could even scrape data off a LinkedIn profile if I place a link to it on my profile. (Probably won&#8217;t make LinkedIn happy if they do it without some $$$ changing hands.)</p>
<p style="text-align: justify;">I think that the targeted advertising potential of Facebook (and other sites like Google/GMail/AdSense, LinkedIn) still remains under utilized. While a lot of people talk about privacy issues, I am not particularly bothered as far as there is no spam, phone calls or a human personally trying to get in touch with me or looking at my data. If I am going to see ads, I would willingly volunteer data on what I am interested in so that I see relevant ads.</p>
<p style="text-align: justify;">Your thoughts?</p>
<div class='yarpp-related-rss yarpp-related-none'>
<p>No related posts.</p>
</div>
<img src="http://feeds.feedburner.com/~r/onkarjoshi/~4/NweHr6SlNJQ" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.onkarjoshi.com/blog/180/patni-walk-in-ad-on-facebook/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		<feedburner:origLink>http://www.onkarjoshi.com/blog/180/patni-walk-in-ad-on-facebook/</feedburner:origLink></item>
		<item>
		<title>Spring Transaction advice : AOP proxy vs AspectJ weaving</title>
		<link>http://feedproxy.google.com/~r/onkarjoshi/~3/Ltf5RREV6Co/</link>
		<comments>http://www.onkarjoshi.com/blog/178/spring-transaction-advice-aop-proxy-vs-aspectj-weaving/#comments</comments>
		<pubDate>Sat, 21 Aug 2010 21:23:37 +0000</pubDate>
		<dc:creator>Onkar Joshi</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[AOP]]></category>
		<category><![CDATA[AspectJ]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Proxy]]></category>
		<category><![CDATA[Spring]]></category>
		<category><![CDATA[Transaction]]></category>

		<guid isPermaLink="false">http://www.onkarjoshi.com/blog/?p=178</guid>
		<description><![CDATA[You are using Spring Transactions with Annotations. MyBS.methodRequired has Required propagation. MyBS.methodRequiresNew has Requires_New propagation. &#8230; methodRequired (&#8230;) { &#8230; methodRequiresNew(&#8230;); &#8230; } Do you get a new transaction if you call methodRequiresNew from methodRequired? You don&#8217;t! Not if you are using the default proxy mode via AOP proxies through which transactional advice is applied. [...]<div class='yarpp-related-rss'>

Related posts:<ol>
<li><a href='http://www.onkarjoshi.com/blog/209/using-xss-to-adjust-java-default-thread-stack-size-to-save-memory-and-prevent-stackoverflowerror/' rel='bookmark' title='Using -Xss to adjust Java default thread stack size to save memory and prevent StackOverflowError'>Using -Xss to adjust Java default thread stack size to save memory and prevent StackOverflowError</a></li>
<li><a href='http://www.onkarjoshi.com/blog/203/difference-between-free-space-and-usable-space/' rel='bookmark' title='There is a difference between free space and usable space!'>There is a difference between free space and usable space!</a></li>
</ol>
</div>
]]></description>
				<content:encoded><![CDATA[<p style="text-align: justify;">You are using Spring Transactions with Annotations.</p>
<p style="text-align: justify;">MyBS.methodRequired has Required propagation.</p>
<p style="text-align: justify;">MyBS.methodRequiresNew has Requires_New propagation.</p>
<p style="text-align: justify;">&#8230; methodRequired (&#8230;) { &#8230; methodRequiresNew(&#8230;); &#8230; }</p>
<p style="text-align: justify;">Do you get a new transaction if you call methodRequiresNew from methodRequired?</p>
<p style="text-align: justify;">You don&#8217;t! Not if you are using the default proxy mode via AOP proxies through which transactional advice is applied. If you move the method with the new transaction to a different class and then call it &#8211; you do get a new transaction. What&#8217;s happening here?</p>
<p style="text-align: justify;">When proxies are used to add transactional behaviour and you call a method directly within the class, there is no proxy in between. So no transactional behaviour can be added. So only calls from &#8216;outside&#8217; will use the behaviour specified by the @Transactional annotation. For &#8216;internal&#8217; calls, the @Transactional annotation is silently ignored!</p>
<p style="text-align: justify;">The ways around this that I can think of (<em>Comments welcome if you have more suggestions</em>):</p>
<ul style="text-align: justify;">
<li>Move such code to a new class. Then the calls become external. This may not be very neat depending on how your code is structured.</li>
<li>Use BeanFactoryPostProcessor and put a reference to the proxied bean into the bean. A self referring bean. Instead of calling the method directly, use the injected reference to make the call.</li>
<li>You could also just pull the proxied bean from the application context with the getBean method. But that&#8217;s Anti Dependency Injection. Not good.</li>
<li>Use AspectJ mode for transactions instead of proxy mode.</li>
</ul>
<p style="text-align: justify;"><a href="http://static.springsource.org/spring/docs/2.5.x/reference/transaction.html" target="_blank">Quote from the Spring API reference docs</a>:</p>
<p style="text-align: justify; padding-left: 60px;"><em>Note: In proxy mode (which is the default), only &#8216;external&#8217; method calls coming in through the proxy will be intercepted. This means that &#8216;self-invocation&#8217;, i.e. a method within the target object calling some other method of the target object, won&#8217;t lead to an actual transaction at runtime even if the invoked method is marked with @Transactional!</em></p>
<p style="text-align: justify; padding-left: 60px;"><em>Consider the use of AspectJ mode (see below) if you expect self-invocations to be wrapped with transactions as well. In this case, there won&#8217;t be a proxy in the first place; instead, the target class will be &#8216;weaved&#8217; (i.e. its byte code will be modified) in order to turn @Transactional into runtime behavior on any kind of method.</em></p>
<div class='yarpp-related-rss'>
<p>Related posts:<ol>
<li><a href='http://www.onkarjoshi.com/blog/209/using-xss-to-adjust-java-default-thread-stack-size-to-save-memory-and-prevent-stackoverflowerror/' rel='bookmark' title='Using -Xss to adjust Java default thread stack size to save memory and prevent StackOverflowError'>Using -Xss to adjust Java default thread stack size to save memory and prevent StackOverflowError</a></li>
<li><a href='http://www.onkarjoshi.com/blog/203/difference-between-free-space-and-usable-space/' rel='bookmark' title='There is a difference between free space and usable space!'>There is a difference between free space and usable space!</a></li>
</ol></p>
</div>
<img src="http://feeds.feedburner.com/~r/onkarjoshi/~4/Ltf5RREV6Co" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.onkarjoshi.com/blog/178/spring-transaction-advice-aop-proxy-vs-aspectj-weaving/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		<feedburner:origLink>http://www.onkarjoshi.com/blog/178/spring-transaction-advice-aop-proxy-vs-aspectj-weaving/</feedburner:origLink></item>
		<item>
		<title>HotSpot JVM – Client / Server VM optimization – 260ms vs 0ms!</title>
		<link>http://feedproxy.google.com/~r/onkarjoshi/~3/9nb17KDdZ-A/</link>
		<comments>http://www.onkarjoshi.com/blog/174/hotspot-jvm-client-server-vm-optimization/#comments</comments>
		<pubDate>Sun, 15 Aug 2010 00:57:07 +0000</pubDate>
		<dc:creator>Onkar Joshi</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[JIT]]></category>
		<category><![CDATA[JVM]]></category>
		<category><![CDATA[Optimization]]></category>
		<category><![CDATA[Performance]]></category>
		<category><![CDATA[Virtual Machine]]></category>
		<category><![CDATA[VM]]></category>

		<guid isPermaLink="false">http://www.onkarjoshi.com/blog/?p=174</guid>
		<description><![CDATA[The Sun/Oracle HotSpot Java Virtual Machine is available for use in two flavors &#8211; the Client VM and the Server VM. The VM to be used can be specified by the -server and -client switches passed when starting the JVM with the java command. The default VM when no switch is specified is the Client [...]<div class='yarpp-related-rss'>

Related posts:<ol>
<li><a href='http://www.onkarjoshi.com/blog/226/crash-your-jvm-by-killing-the-garbage-collector/' rel='bookmark' title='Crash your JVM by killing the garbage collector!'>Crash your JVM by killing the garbage collector!</a></li>
<li><a href='http://www.onkarjoshi.com/blog/128/understand-ftp-passive-pasv-and-active-modes/' rel='bookmark' title='Understand FTP Passive (PASV) and Active modes'>Understand FTP Passive (PASV) and Active modes</a></li>
<li><a href='http://www.onkarjoshi.com/blog/219/volatile-array/' rel='bookmark' title='Atomic array classes and volatile arrays in the JVM'>Atomic array classes and volatile arrays in the JVM</a></li>
<li><a href='http://www.onkarjoshi.com/blog/247/heap-dump-of-a-running-jvm-with-jmap/' rel='bookmark' title='Heap dump of a running JVM with jmap'>Heap dump of a running JVM with jmap</a></li>
<li><a href='http://www.onkarjoshi.com/blog/76/java-synchronization-benchmark/' rel='bookmark' title='Java Synchronization Benchmark'>Java Synchronization Benchmark</a></li>
</ol>
</div>
]]></description>
				<content:encoded><![CDATA[<p style="text-align: justify;">The Sun/Oracle HotSpot Java Virtual Machine is available for use in two flavors &#8211; the Client VM and the Server VM.</p>
<p style="text-align: justify;">The VM to be used can be specified by the <strong>-server</strong> and<strong> -client</strong> switches passed when starting the JVM with the <strong>java </strong>command. The default VM when no switch is specified is the Client VM.</p>
<p style="text-align: justify;">The difference, in a nutshell, is that the Client VM is optimized for fast load times at the cost of runtime performance. The Server VM is built for aggressive optimization for runtime performance at the cost of slower load time.</p>
<p style="text-align: justify;">The example below shows a simple instance of a clearly observable difference between the two. The code puts out the time taken to run a loop that counts down from 500 million to zero.</p>
<p style="text-align: justify;">The results indicate that the Client VM took around 260 milliseconds each time. Amazingly, the Server VM takes <em>ZERO </em>milliseconds each time! This happens because of the more aggressive optimization. The compiler does some funky analysis and reaches the conclusion that the code in the loop does nothing and removing that code would not affect the flow of the program. So it just deletes that code from the compiled code that it produces. This results in the zero run time that we observe. Cool, eh?</p>
<p style="text-align: justify;">Note that there is no need to recompile the code into new .class files between the tests with the two switches. The .class file fed to the JVM is the same in both cases. So the same byte code is initially read but the Server VM puts more effort into doing optimizations and doing JIT (Just In Time) compilation to produce faster code.</p>
<p style="text-align: justify;">Go ahead and check right now if the startup script for your big server side <em>Enterprise</em> Java app has the <strong>-server</strong> switch. If not, perhaps you should seriously consider adding it in.</p>
<p style="text-align: justify;">
<p><img class="aligncenter size-full wp-image-175" title="hotspot-server-client-vm" src="http://www.onkarjoshi.com/blog/wp-content/uploads/2010/08/hotspot-server-client-vm.png" alt="" width="420" height="590" /></p>
<div class='yarpp-related-rss'>
<p>Related posts:<ol>
<li><a href='http://www.onkarjoshi.com/blog/226/crash-your-jvm-by-killing-the-garbage-collector/' rel='bookmark' title='Crash your JVM by killing the garbage collector!'>Crash your JVM by killing the garbage collector!</a></li>
<li><a href='http://www.onkarjoshi.com/blog/128/understand-ftp-passive-pasv-and-active-modes/' rel='bookmark' title='Understand FTP Passive (PASV) and Active modes'>Understand FTP Passive (PASV) and Active modes</a></li>
<li><a href='http://www.onkarjoshi.com/blog/219/volatile-array/' rel='bookmark' title='Atomic array classes and volatile arrays in the JVM'>Atomic array classes and volatile arrays in the JVM</a></li>
<li><a href='http://www.onkarjoshi.com/blog/247/heap-dump-of-a-running-jvm-with-jmap/' rel='bookmark' title='Heap dump of a running JVM with jmap'>Heap dump of a running JVM with jmap</a></li>
<li><a href='http://www.onkarjoshi.com/blog/76/java-synchronization-benchmark/' rel='bookmark' title='Java Synchronization Benchmark'>Java Synchronization Benchmark</a></li>
</ol></p>
</div>
<img src="http://feeds.feedburner.com/~r/onkarjoshi/~4/9nb17KDdZ-A" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.onkarjoshi.com/blog/174/hotspot-jvm-client-server-vm-optimization/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		<feedburner:origLink>http://www.onkarjoshi.com/blog/174/hotspot-jvm-client-server-vm-optimization/</feedburner:origLink></item>
		<item>
		<title>Fix ConcurrentModificationException on ArrayList with CopyOnWriteArrayList</title>
		<link>http://feedproxy.google.com/~r/onkarjoshi/~3/e_CQpWh3rlM/</link>
		<comments>http://www.onkarjoshi.com/blog/170/threads-concurrency-fix-concurrent-modification-exception-on-arraylist-with-copyonwritearraylist/#comments</comments>
		<pubDate>Sun, 01 Aug 2010 13:15:34 +0000</pubDate>
		<dc:creator>Onkar Joshi</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Concurrency]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Multi-threading]]></category>
		<category><![CDATA[Threads]]></category>

		<guid isPermaLink="false">http://www.onkarjoshi.com/blog/?p=170</guid>
		<description><![CDATA[You have a List in your application that is traversed or iterated over very frequently but is modified very rarely. Like a &#8216;Top 10&#8242; kind of list on your home page which is served for every hit to the home page (think hundreds of hits per second) and is updated by an hourly Quartz job. [...]<div class='yarpp-related-rss yarpp-related-none'>

No related posts.
</div>
]]></description>
				<content:encoded><![CDATA[<p style="text-align: justify;">You have a <em>List </em>in your application that is traversed or iterated over very frequently but is modified very rarely. Like a &#8216;Top 10&#8242; kind of list on your home page which is served for every hit to the home page (think hundreds of hits per second) and is updated by an hourly Quartz job.</p>
<p style="text-align: justify;">If you use an ArrayList for that list and no synchronization, you run the risk of a <em>ConcurrentModificationException </em>being thrown every hour when the list is modified by the Quartz job because the list may currently be in the middle of a traversal or iteration for a user visiting your homepage.</p>
<p style="text-align: justify;">One way a person might try to fix it is to use a <em>Vector </em>or rather <em>Collections.synchronizedList(List&lt;T&gt;)</em>. But this doesn&#8217;t help! While <em>add()</em>, <em>remove()</em>, <em>get()</em> will now be thread-safe on the list, Iterators will still throw <em>ConcurrentModificationException</em>! You will need to synchronize on the list object before iterating on it as well as in the Quartz job where you modify it. That&#8217;s just terrible from a performance and scalability point of view! Synchronization will be needed everywhere and all the time just because of an hourly modification.</p>
<p style="text-align: justify;">Fortunately, there is a better solution. Use a <em>CopyOnWriteArrayList</em>.</p>
<p style="text-align: justify;">Whenever a structural modification is made to this list, a new copy is created. This is not inefficient if modifications happen rarely. Iterators on this will not experience a ConcurrentModification because the list they started iterating on is never modified.</p>
<p style="text-align: justify;">Another way one may try to avoid Concurrent Modification without adding synchronization code all over is to build a new <em>List </em>in their scheduled job and then switch out the reference which is used for iteration with the new list. Assigning a reference is an atomic operation in the JVM. This approach would fail if the code doing the iteration used an old style for loop -<em> for (int i=0; i&lt;list.size(); i++) { &#8230; list.get(i) &#8230;}</em>. A change in the size of the switched list introduces a failure point. Worse, there are visibility problems here since the changes from a different thread may not be seen at all. Using the volatile keyword may help see the changes to the reference from a different thread, but the changed list size would still be a problem.</p>
<p style="text-align: justify;">The memory consistency and happens-before guarantees of <em>Copy On Write Array List </em>make these problems disappear. Also, the code is simple since one doesn&#8217;t need to use volatile or synchronized. Less code, less bugs!</p>
<p style="text-align: justify;">Another use case for <em>CopyOnWriteArrayList </em>is the case of the Observer design pattern. If event listeners are added and removed by multiple threads, it is quite possible that using a <em>CopyOnWriteArrayList </em>might be appropriate for correctness and simplicity.</p>
<p style="text-align: justify;">Hope this helps. Remember to get your code reviewed by your nearest concurrency guru!</p>
<div class='yarpp-related-rss yarpp-related-none'>
<p>No related posts.</p>
</div>
<img src="http://feeds.feedburner.com/~r/onkarjoshi/~4/e_CQpWh3rlM" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.onkarjoshi.com/blog/170/threads-concurrency-fix-concurrent-modification-exception-on-arraylist-with-copyonwritearraylist/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		<feedburner:origLink>http://www.onkarjoshi.com/blog/170/threads-concurrency-fix-concurrent-modification-exception-on-arraylist-with-copyonwritearraylist/</feedburner:origLink></item>
		<item>
		<title>Identifying a thread with high CPU usage in a Java app</title>
		<link>http://feedproxy.google.com/~r/onkarjoshi/~3/cEx1HZr3TJU/</link>
		<comments>http://www.onkarjoshi.com/blog/166/identifying-a-thread-with-high-cpu-usage-in-a-java-app/#comments</comments>
		<pubDate>Fri, 09 Jul 2010 09:01:52 +0000</pubDate>
		<dc:creator>Onkar Joshi</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[JConsole]]></category>
		<category><![CDATA[JVisualVM]]></category>
		<category><![CDATA[Performance]]></category>

		<guid isPermaLink="false">http://www.onkarjoshi.com/blog/?p=166</guid>
		<description><![CDATA[One of the threads in your app is consuming way too much CPU. Perhaps pegging a core at 100%. How do you find out which thread? Use JConsole. It comes with the JDK. But out-of-the-box, JConsole won&#8217;t provide the info we need. You will need to use it with a plugin that gathers and displays [...]<div class='yarpp-related-rss'>

Related posts:<ol>
<li><a href='http://www.onkarjoshi.com/blog/156/mcafee-anti-virus-mcshield-exe-process-eats-100-cpu-too-often/' rel='bookmark' title='McAfee anti virus mcshield.exe process eats 100% CPU too often'>McAfee anti virus mcshield.exe process eats 100% CPU too often</a></li>
<li><a href='http://www.onkarjoshi.com/blog/224/how-to-suspend-vm-on-startup-when-remote-debugging-your-java-app/' rel='bookmark' title='How to suspend VM on startup when remote debugging your Java app'>How to suspend VM on startup when remote debugging your Java app</a></li>
<li><a href='http://www.onkarjoshi.com/blog/104/sun-jdk-7-released/' rel='bookmark' title='Sun JDK 7 released'>Sun JDK 7 released</a></li>
<li><a href='http://www.onkarjoshi.com/blog/121/kaspersky-ate-my-jconsole/' rel='bookmark' title='Kaspersky ate my jconsole!'>Kaspersky ate my jconsole!</a></li>
<li><a href='http://www.onkarjoshi.com/blog/230/sending-a-sigbreak-signal-to-a-java-process-to-do-a-thread-dump-in-windows/' rel='bookmark' title='Sending a SIGBREAK signal to a Java process to do a thread dump in Windows'>Sending a SIGBREAK signal to a Java process to do a thread dump in Windows</a></li>
</ol>
</div>
]]></description>
				<content:encoded><![CDATA[<p>One of the threads in your app is consuming way too much CPU. Perhaps pegging a core at 100%. How do you find out which thread?</p>
<p>Use JConsole. It comes with the JDK. But out-of-the-box, JConsole won&#8217;t provide the info we need. You will need to use it with a plugin that gathers and displays CPU usage info.</p>
<p>The JTop plugin comes with the JDK with source as a demo plugin for JConsole. It shows cumulative CPU usage for each thread. So if a thread has high CPU usage it can be spotted easily. You can see the JTop tab in JConsole if your start it like this -</p>
<p style="text-align: center;"><em>jconsole -pluginpath &#8220;%JAVA_HOME%\demo\management\JTop\JTop.jar&#8221;</em></p>
<p style="text-align: center;"><em><img class="aligncenter size-full wp-image-167" title="jconsole-jtop" src="http://www.onkarjoshi.com/blog/wp-content/uploads/2010/07/jconsole-jtop.png" alt="" width="326" height="299" /><br />
</em></p>
<p style="text-align: justify;">JTop may be nice. But what you would rather be using is the <a href="http://lsd.luminis.nl/top-threads-plugin-for-jconsole/" target="_blank">Top Threads plugin</a> written by Peter Doornbosch. It is free and is available from his blog. The TopThreads JConsole plugin will show you more info and includes usage history, current and average CPU usage. To get the TopThreads tab, start JConsole like this -</p>
<p style="text-align: center;"><em>jconsole -pluginpath &#8220;c:\topthreads.jar&#8221;</em></p>
<p style="text-align: center;"><em><img class="aligncenter size-full wp-image-168" title="jconsole-topthreads" src="http://www.onkarjoshi.com/blog/wp-content/uploads/2010/07/jconsole-topthreads.png" alt="" width="527" height="539" /><br />
</em></p>
<p style="text-align: justify;">JVisualVM also comes with the JDK and can help in such situations. The CPU profiling feature is especially handy considering the fact that it comes with the JDK and is free. Tools like JProfiler and YourKit are pretty costly unless you are really putting them to good use. Surprisingly few people know about this neat tool that comes bundled with the JDK. If your JDK bin directory is in your PATH, you can start JVisualVM from the console like this -</p>
<p style="text-align: center;"><em>jvisualvm</em></p>
<p style="text-align: center;"><em><img class="aligncenter size-full wp-image-169" title="jvisualvm" src="http://www.onkarjoshi.com/blog/wp-content/uploads/2010/07/jvisualvm.png" alt="" width="460" height="382" /><br />
</em></p>
<p style="text-align: justify;">Go ahead and give it a quick try right away. Start your Java app. Start JVisualVM. Attach JVisualVM to your app. Check out all the data the monitors and profilers provide.</p>
<div class='yarpp-related-rss'>
<p>Related posts:<ol>
<li><a href='http://www.onkarjoshi.com/blog/156/mcafee-anti-virus-mcshield-exe-process-eats-100-cpu-too-often/' rel='bookmark' title='McAfee anti virus mcshield.exe process eats 100% CPU too often'>McAfee anti virus mcshield.exe process eats 100% CPU too often</a></li>
<li><a href='http://www.onkarjoshi.com/blog/224/how-to-suspend-vm-on-startup-when-remote-debugging-your-java-app/' rel='bookmark' title='How to suspend VM on startup when remote debugging your Java app'>How to suspend VM on startup when remote debugging your Java app</a></li>
<li><a href='http://www.onkarjoshi.com/blog/104/sun-jdk-7-released/' rel='bookmark' title='Sun JDK 7 released'>Sun JDK 7 released</a></li>
<li><a href='http://www.onkarjoshi.com/blog/121/kaspersky-ate-my-jconsole/' rel='bookmark' title='Kaspersky ate my jconsole!'>Kaspersky ate my jconsole!</a></li>
<li><a href='http://www.onkarjoshi.com/blog/230/sending-a-sigbreak-signal-to-a-java-process-to-do-a-thread-dump-in-windows/' rel='bookmark' title='Sending a SIGBREAK signal to a Java process to do a thread dump in Windows'>Sending a SIGBREAK signal to a Java process to do a thread dump in Windows</a></li>
</ol></p>
</div>
<img src="http://feeds.feedburner.com/~r/onkarjoshi/~4/cEx1HZr3TJU" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.onkarjoshi.com/blog/166/identifying-a-thread-with-high-cpu-usage-in-a-java-app/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		<feedburner:origLink>http://www.onkarjoshi.com/blog/166/identifying-a-thread-with-high-cpu-usage-in-a-java-app/</feedburner:origLink></item>
		<item>
		<title>Debug with Step Filters in Eclipse</title>
		<link>http://feedproxy.google.com/~r/onkarjoshi/~3/n3T7PNdN1_U/</link>
		<comments>http://www.onkarjoshi.com/blog/163/debug-with-step-filters-in-eclipse/#comments</comments>
		<pubDate>Thu, 08 Jul 2010 16:30:01 +0000</pubDate>
		<dc:creator>Onkar Joshi</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Debugging]]></category>
		<category><![CDATA[Eclipse]]></category>
		<category><![CDATA[Java]]></category>

		<guid isPermaLink="false">http://www.onkarjoshi.com/blog/?p=163</guid>
		<description><![CDATA[I got this excellent debugging tip from a colleague at work recently. Most of the time when you are debugging, you want to be looking at your own code. Not code from libraries or the JDK or even the &#8216;framework&#8217; parts of your own code base. You can configure the Eclipse Java debugger to not [...]<div class='yarpp-related-rss'>

Related posts:<ol>
<li><a href='http://www.onkarjoshi.com/blog/159/conditional-breakpoints-in-java-development-with-eclipse/' rel='bookmark' title='Conditional breakpoints in Java development with Eclipse'>Conditional breakpoints in Java development with Eclipse</a></li>
<li><a href='http://www.onkarjoshi.com/blog/84/configuring-eclipse-to-use-a-jdk-at-a-location-with-spaces-in-it/' rel='bookmark' title='Configuring Eclipse to use a JDK at a location with spaces in it'>Configuring Eclipse to use a JDK at a location with spaces in it</a></li>
<li><a href='http://www.onkarjoshi.com/blog/104/sun-jdk-7-released/' rel='bookmark' title='Sun JDK 7 released'>Sun JDK 7 released</a></li>
<li><a href='http://www.onkarjoshi.com/blog/194/eclipse-tip-add-a-short-cut-key-to-skip-all-breakpoints/' rel='bookmark' title='Eclipse tip: Add a short cut key to Skip All Breakpoints'>Eclipse tip: Add a short cut key to Skip All Breakpoints</a></li>
<li><a href='http://www.onkarjoshi.com/blog/224/how-to-suspend-vm-on-startup-when-remote-debugging-your-java-app/' rel='bookmark' title='How to suspend VM on startup when remote debugging your Java app'>How to suspend VM on startup when remote debugging your Java app</a></li>
</ol>
</div>
]]></description>
				<content:encoded><![CDATA[<p style="text-align: justify;">I got this excellent debugging tip from a colleague at work recently.</p>
<p>Most of the time when you are debugging, you want to be looking at your own code. Not code from libraries or the JDK or even the &#8216;framework&#8217; parts of your own code base.</p>
<p>You can configure the Eclipse Java debugger to not step into those bits of code by configuring a &#8216;Step Filter&#8217;.</p>
<p>1. Go to Windows -&gt; Preferences -&gt; Java -&gt; Debug -&gt; Step Filtering.<br />
2. Check &#8216;Use Step Filters&#8217;.<br />
3. Check the appropriate options on the screen. You can add parts that are relevant to your own codebase.<br />
4. Click &#8216;Apply&#8217;.</p>
<p>Now the next time you press F5 when your breakpoint is on an <em>orderList.add(newOrder) </em>statement, you will not step into the code for the ArrayList.add method. Instead, the debugger will send you to the next appropriate line after the call. This makes sense since you are not likely to be looking for bugs in the JDK. Concentrating on the relevant bits helps maintain your train of thought in those intense debugging sessions, doesn&#8217;t it?</p>
<p style="text-align: justify;">
<img class="aligncenter size-full wp-image-164" title="eclipse-step-filters" src="http://www.onkarjoshi.com/blog/wp-content/uploads/2010/07/eclipse-step-filters.png" alt="" width="488" height="602" /></p>
<div class='yarpp-related-rss'>
<p>Related posts:<ol>
<li><a href='http://www.onkarjoshi.com/blog/159/conditional-breakpoints-in-java-development-with-eclipse/' rel='bookmark' title='Conditional breakpoints in Java development with Eclipse'>Conditional breakpoints in Java development with Eclipse</a></li>
<li><a href='http://www.onkarjoshi.com/blog/84/configuring-eclipse-to-use-a-jdk-at-a-location-with-spaces-in-it/' rel='bookmark' title='Configuring Eclipse to use a JDK at a location with spaces in it'>Configuring Eclipse to use a JDK at a location with spaces in it</a></li>
<li><a href='http://www.onkarjoshi.com/blog/104/sun-jdk-7-released/' rel='bookmark' title='Sun JDK 7 released'>Sun JDK 7 released</a></li>
<li><a href='http://www.onkarjoshi.com/blog/194/eclipse-tip-add-a-short-cut-key-to-skip-all-breakpoints/' rel='bookmark' title='Eclipse tip: Add a short cut key to Skip All Breakpoints'>Eclipse tip: Add a short cut key to Skip All Breakpoints</a></li>
<li><a href='http://www.onkarjoshi.com/blog/224/how-to-suspend-vm-on-startup-when-remote-debugging-your-java-app/' rel='bookmark' title='How to suspend VM on startup when remote debugging your Java app'>How to suspend VM on startup when remote debugging your Java app</a></li>
</ol></p>
</div>
<img src="http://feeds.feedburner.com/~r/onkarjoshi/~4/n3T7PNdN1_U" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.onkarjoshi.com/blog/163/debug-with-step-filters-in-eclipse/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		<feedburner:origLink>http://www.onkarjoshi.com/blog/163/debug-with-step-filters-in-eclipse/</feedburner:origLink></item>
		<item>
		<title>Conditional breakpoints in Java development with Eclipse</title>
		<link>http://feedproxy.google.com/~r/onkarjoshi/~3/VDgvbOA8Z6E/</link>
		<comments>http://www.onkarjoshi.com/blog/159/conditional-breakpoints-in-java-development-with-eclipse/#comments</comments>
		<pubDate>Thu, 08 Jul 2010 09:17:38 +0000</pubDate>
		<dc:creator>Onkar Joshi</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Debugging]]></category>
		<category><![CDATA[Eclipse]]></category>
		<category><![CDATA[Java]]></category>

		<guid isPermaLink="false">http://www.onkarjoshi.com/blog/?p=159</guid>
		<description><![CDATA[Imagine that you have a screen that shows a large list of items with several columns of data for each row. One of the items is showing odd data. You want to step though the code to see what is happening for that row. If you set a normal breakpoint, you&#8217;ll have to break and [...]<div class='yarpp-related-rss'>

Related posts:<ol>
<li><a href='http://www.onkarjoshi.com/blog/194/eclipse-tip-add-a-short-cut-key-to-skip-all-breakpoints/' rel='bookmark' title='Eclipse tip: Add a short cut key to Skip All Breakpoints'>Eclipse tip: Add a short cut key to Skip All Breakpoints</a></li>
<li><a href='http://www.onkarjoshi.com/blog/163/debug-with-step-filters-in-eclipse/' rel='bookmark' title='Debug with Step Filters in Eclipse'>Debug with Step Filters in Eclipse</a></li>
<li><a href='http://www.onkarjoshi.com/blog/84/configuring-eclipse-to-use-a-jdk-at-a-location-with-spaces-in-it/' rel='bookmark' title='Configuring Eclipse to use a JDK at a location with spaces in it'>Configuring Eclipse to use a JDK at a location with spaces in it</a></li>
<li><a href='http://www.onkarjoshi.com/blog/224/how-to-suspend-vm-on-startup-when-remote-debugging-your-java-app/' rel='bookmark' title='How to suspend VM on startup when remote debugging your Java app'>How to suspend VM on startup when remote debugging your Java app</a></li>
<li><a href='http://www.onkarjoshi.com/blog/213/6-things-to-remember-about-saving-memory-with-the-string-intern-method/' rel='bookmark' title='6 things to remember about saving memory with the String.intern method'>6 things to remember about saving memory with the String.intern method</a></li>
</ol>
</div>
]]></description>
				<content:encoded><![CDATA[<p style="text-align: justify;">Imagine that you have a screen that shows a large list of items with several columns of data for each row. One of the items is showing odd data. You want to step though the code to see what is happening for that row.</p>
<p>If you set a normal breakpoint, you&#8217;ll have to break and run repeatedly while manually verifying if the breakpoint is finally being hit for your item of interest.</p>
<p>A better approach is to set a conditional breakpoint. Right click on the breakpoint, select &#8216;Breakpoint properties&#8230;&#8217;, check &#8216;Enable condition&#8217;. You can now set a condition for the breakpoint to break. You can use the variables in the context of the breakpoint in this condition. Something like &#8216;orderNumber.equals(&#8220;RA54365&#8243;)&#8217;.</p>
<p style="text-align: center;">
<p style="text-align: justify;">Now you&#8217;ll hit the breakpoint only for the item of interest. Can be quite a bit of a time saver when used in the right situation. Note that the icon for a conditional breakpoint shows up like a regular breakpoint icon with a question mark superimposed on it.<br />
<img class="aligncenter size-full wp-image-160" title="eclipse-breakpoint-properties" src="http://www.onkarjoshi.com/blog/wp-content/uploads/2010/07/eclipse-breakpoint-properties.png" alt="" width="281" height="239" /><br />
I have also used this at times when I know that something I am doing is resulting in bad data but I&#8217;m not sure what. I set a conditional breakpoint and keep trying out things. When I hit the right steps, the breakpoint suspends the thread and alerts me to it. Neat, isn&#8217;t it? You can do the same when developing with IDEA or NetBeans too.</p>
<p style="text-align: center;"><img class=" size-full wp-image-161  aligncenter" title="eclipse-breakpoint-conditional" src="http://www.onkarjoshi.com/blog/wp-content/uploads/2010/07/eclipse-breakpoint-conditional.png" alt="" width="458" height="437" /></p>
<p style="text-align: left;">Got any cool debugging tips? Drop me a comment!</p>
<div class='yarpp-related-rss'>
<p>Related posts:<ol>
<li><a href='http://www.onkarjoshi.com/blog/194/eclipse-tip-add-a-short-cut-key-to-skip-all-breakpoints/' rel='bookmark' title='Eclipse tip: Add a short cut key to Skip All Breakpoints'>Eclipse tip: Add a short cut key to Skip All Breakpoints</a></li>
<li><a href='http://www.onkarjoshi.com/blog/163/debug-with-step-filters-in-eclipse/' rel='bookmark' title='Debug with Step Filters in Eclipse'>Debug with Step Filters in Eclipse</a></li>
<li><a href='http://www.onkarjoshi.com/blog/84/configuring-eclipse-to-use-a-jdk-at-a-location-with-spaces-in-it/' rel='bookmark' title='Configuring Eclipse to use a JDK at a location with spaces in it'>Configuring Eclipse to use a JDK at a location with spaces in it</a></li>
<li><a href='http://www.onkarjoshi.com/blog/224/how-to-suspend-vm-on-startup-when-remote-debugging-your-java-app/' rel='bookmark' title='How to suspend VM on startup when remote debugging your Java app'>How to suspend VM on startup when remote debugging your Java app</a></li>
<li><a href='http://www.onkarjoshi.com/blog/213/6-things-to-remember-about-saving-memory-with-the-string-intern-method/' rel='bookmark' title='6 things to remember about saving memory with the String.intern method'>6 things to remember about saving memory with the String.intern method</a></li>
</ol></p>
</div>
<img src="http://feeds.feedburner.com/~r/onkarjoshi/~4/VDgvbOA8Z6E" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.onkarjoshi.com/blog/159/conditional-breakpoints-in-java-development-with-eclipse/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		<feedburner:origLink>http://www.onkarjoshi.com/blog/159/conditional-breakpoints-in-java-development-with-eclipse/</feedburner:origLink></item>
		<item>
		<title>McAfee anti virus mcshield.exe process eats 100% CPU too often</title>
		<link>http://feedproxy.google.com/~r/onkarjoshi/~3/N7rn1mKwZqU/</link>
		<comments>http://www.onkarjoshi.com/blog/156/mcafee-anti-virus-mcshield-exe-process-eats-100-cpu-too-often/#comments</comments>
		<pubDate>Sun, 06 Jun 2010 22:00:14 +0000</pubDate>
		<dc:creator>Onkar Joshi</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Windows]]></category>

		<guid isPermaLink="false">http://www.onkarjoshi.com/blog/?p=156</guid>
		<description><![CDATA[McAfee recently gave away free 6-month licenses to their anti virus suite as part of a Facebook promo. I got one too and have been using McAfee since then. I am not impressed with the software at all. The configuration UI takes way too long to load. There is no way to tell the software [...]<div class='yarpp-related-rss'>

Related posts:<ol>
<li><a href='http://www.onkarjoshi.com/blog/166/identifying-a-thread-with-high-cpu-usage-in-a-java-app/' rel='bookmark' title='Identifying a thread with high CPU usage in a Java app'>Identifying a thread with high CPU usage in a Java app</a></li>
<li><a href='http://www.onkarjoshi.com/blog/230/sending-a-sigbreak-signal-to-a-java-process-to-do-a-thread-dump-in-windows/' rel='bookmark' title='Sending a SIGBREAK signal to a Java process to do a thread dump in Windows'>Sending a SIGBREAK signal to a Java process to do a thread dump in Windows</a></li>
<li><a href='http://www.onkarjoshi.com/blog/77/how-to-split-a-file-process-the-pieces-in-multiple-threads-and-combine-results-using-a-shell-script/' rel='bookmark' title='How to split a file, process the pieces in multiple threads and combine results using a shell script'>How to split a file, process the pieces in multiple threads and combine results using a shell script</a></li>
</ol>
</div>
]]></description>
				<content:encoded><![CDATA[<p>McAfee recently gave away free 6-month licenses to their anti virus suite as part of a Facebook promo. I got one too and have been using McAfee since then.</p>
<p>I am not impressed with the software at all. The configuration UI takes way too long to load. There is no way to tell  the software to completely unload itself from memory. The resource usage shoots up too much, too often. I disabled scheduled scans and disabled automatic installation of updates as well.</p>
<p>I noticed that their mcshield.exe process is set to a &#8220;high&#8221; base priority. It is this process that tends to eat 100% CPU too often. Because of the high base priority, all the other processes on my single threaded system become completely non responsive. I searched around and found no way to lower the base priority of this process. For a single core CPU, it does not seem like a good default to me to set a strongly CPU bound process to a &#8220;high&#8221; base priority which starves every other process of any CPU time at all. I did find a whole lot of other people complaining about the high CPU usage caused by this process. Even Google Suggest points to this being a problem for many.</p>
<p>I used AVG (free edition) earlier and that definitely seemed to perform better.</p>
<p>Some of my colleagues purchased the Kaspersky Internet Security Suite recently. They offer a really good deal &#8211; something like a 3-PC license for Rs.600 or so in India. And that&#8217;s what most non-corporate customers would actually be willing to pay for in India. My PC at work too has Kaspersky and I&#8217;m pretty happy with how it works there so far.</p>
<p>More on MSDN about <a href="http://msdn.microsoft.com/en-us/library/ms685100%28VS.85%29.aspx" target="_blank">how Windows schedules threads</a>.</p>
<p><img class="aligncenter size-full wp-image-157" title="mcafee-mcshield-cpu-usage" src="http://www.onkarjoshi.com/blog/wp-content/uploads/2010/06/mcafee-mcshield-cpu-usage.png" alt="" width="473" height="292" /></p>
<div class='yarpp-related-rss'>
<p>Related posts:<ol>
<li><a href='http://www.onkarjoshi.com/blog/166/identifying-a-thread-with-high-cpu-usage-in-a-java-app/' rel='bookmark' title='Identifying a thread with high CPU usage in a Java app'>Identifying a thread with high CPU usage in a Java app</a></li>
<li><a href='http://www.onkarjoshi.com/blog/230/sending-a-sigbreak-signal-to-a-java-process-to-do-a-thread-dump-in-windows/' rel='bookmark' title='Sending a SIGBREAK signal to a Java process to do a thread dump in Windows'>Sending a SIGBREAK signal to a Java process to do a thread dump in Windows</a></li>
<li><a href='http://www.onkarjoshi.com/blog/77/how-to-split-a-file-process-the-pieces-in-multiple-threads-and-combine-results-using-a-shell-script/' rel='bookmark' title='How to split a file, process the pieces in multiple threads and combine results using a shell script'>How to split a file, process the pieces in multiple threads and combine results using a shell script</a></li>
</ol></p>
</div>
<img src="http://feeds.feedburner.com/~r/onkarjoshi/~4/N7rn1mKwZqU" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.onkarjoshi.com/blog/156/mcafee-anti-virus-mcshield-exe-process-eats-100-cpu-too-often/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		<feedburner:origLink>http://www.onkarjoshi.com/blog/156/mcafee-anti-virus-mcshield-exe-process-eats-100-cpu-too-often/</feedburner:origLink></item>
		<item>
		<title>Turn off the Windows Automatic Updates ‘Restart later’ nag screen</title>
		<link>http://feedproxy.google.com/~r/onkarjoshi/~3/qTaL0jcCcK0/</link>
		<comments>http://www.onkarjoshi.com/blog/154/turn-off-the-windows-automatic-updates-remind-me-later-nag-screen/#comments</comments>
		<pubDate>Sat, 05 Jun 2010 13:12:31 +0000</pubDate>
		<dc:creator>Onkar Joshi</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Windows]]></category>

		<guid isPermaLink="false">http://www.onkarjoshi.com/blog/?p=154</guid>
		<description><![CDATA[One of the most annoying dialogs in Windows XP is the one from Automatic Updates that tells you that updates are installed and a restart is needed  The annoying bit about this is that you cannot make it go away. The most you can do is &#8216;Restart later&#8217;. Do that and the the dialog jumps [...]<div class='yarpp-related-rss'>

Related posts:<ol>
<li><a href='http://www.onkarjoshi.com/blog/43/partitioning-help-for-multi-booting-ubuntu-linux-and-windows-xp-safely/' rel='bookmark' title='Partitioning help for multi booting Ubuntu Linux and Windows XP safely'>Partitioning help for multi booting Ubuntu Linux and Windows XP safely</a></li>
<li><a href='http://www.onkarjoshi.com/blog/125/how-to-create-a-file-of-arbitrary-size-with-fsutil-in-windows-xp/' rel='bookmark' title='How to create a file of arbitrary size with fsutil in Windows XP'>How to create a file of arbitrary size with fsutil in Windows XP</a></li>
<li><a href='http://www.onkarjoshi.com/blog/230/sending-a-sigbreak-signal-to-a-java-process-to-do-a-thread-dump-in-windows/' rel='bookmark' title='Sending a SIGBREAK signal to a Java process to do a thread dump in Windows'>Sending a SIGBREAK signal to a Java process to do a thread dump in Windows</a></li>
<li><a href='http://www.onkarjoshi.com/blog/156/mcafee-anti-virus-mcshield-exe-process-eats-100-cpu-too-often/' rel='bookmark' title='McAfee anti virus mcshield.exe process eats 100% CPU too often'>McAfee anti virus mcshield.exe process eats 100% CPU too often</a></li>
</ol>
</div>
]]></description>
				<content:encoded><![CDATA[<p style="text-align: left;">One of the most annoying dialogs in Windows XP is the one from Automatic Updates that tells you that updates are installed and a restart is needed  The annoying bit about this is that you cannot make it go away. The most you can do is &#8216;Restart later&#8217;. Do that and the the dialog jumps out at you again in 10 minutes. I just wanna say, &#8220;<strong>Get out of my face and die, stupid dialog!</strong>&#8220;. It is difficult to measure the productivity lost by the interruptions caused in the train of thought when a coder is &#8220;one with the code&#8221;.</p>
<p>Of course, updates are important and disabling automatic updates would not be a wise thing to do.</p>
<p>The solution that works for me?</p>
<p><span style="color: #000080;">Start &gt; Run &gt; cmd</span></p>
<p><span style="color: #000080;">sc stop wuauserv</span></p>
<p>That stops the Windows Automatic Updates Service. That makes the updates reminder screen go away along with the system tray icon until you restart. Ah, peace. You could use the same command with the start switch as well. The service is started automatically when you restart.</p>
<p>I haven&#8217;t seen how Microsoft did this in Windows Vista or Window 7. I sure hope it is handled better.</p>
<p><img class="aligncenter size-full  wp-image-155" title="automatic-updates-restart-later" src="http://www.onkarjoshi.com/blog/wp-content/uploads/2010/06/automatic-updates-restart-later.png" alt="" width="428" height="132" /></p>
<div class='yarpp-related-rss'>
<p>Related posts:<ol>
<li><a href='http://www.onkarjoshi.com/blog/43/partitioning-help-for-multi-booting-ubuntu-linux-and-windows-xp-safely/' rel='bookmark' title='Partitioning help for multi booting Ubuntu Linux and Windows XP safely'>Partitioning help for multi booting Ubuntu Linux and Windows XP safely</a></li>
<li><a href='http://www.onkarjoshi.com/blog/125/how-to-create-a-file-of-arbitrary-size-with-fsutil-in-windows-xp/' rel='bookmark' title='How to create a file of arbitrary size with fsutil in Windows XP'>How to create a file of arbitrary size with fsutil in Windows XP</a></li>
<li><a href='http://www.onkarjoshi.com/blog/230/sending-a-sigbreak-signal-to-a-java-process-to-do-a-thread-dump-in-windows/' rel='bookmark' title='Sending a SIGBREAK signal to a Java process to do a thread dump in Windows'>Sending a SIGBREAK signal to a Java process to do a thread dump in Windows</a></li>
<li><a href='http://www.onkarjoshi.com/blog/156/mcafee-anti-virus-mcshield-exe-process-eats-100-cpu-too-often/' rel='bookmark' title='McAfee anti virus mcshield.exe process eats 100% CPU too often'>McAfee anti virus mcshield.exe process eats 100% CPU too often</a></li>
</ol></p>
</div>
<img src="http://feeds.feedburner.com/~r/onkarjoshi/~4/qTaL0jcCcK0" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.onkarjoshi.com/blog/154/turn-off-the-windows-automatic-updates-remind-me-later-nag-screen/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		<feedburner:origLink>http://www.onkarjoshi.com/blog/154/turn-off-the-windows-automatic-updates-remind-me-later-nag-screen/</feedburner:origLink></item>
		<item>
		<title>Erlang – A very basic introduction</title>
		<link>http://feedproxy.google.com/~r/onkarjoshi/~3/TjDwOf6qcTQ/</link>
		<comments>http://www.onkarjoshi.com/blog/152/erlang-a-very-basic-introduction/#comments</comments>
		<pubDate>Thu, 03 Jun 2010 22:30:59 +0000</pubDate>
		<dc:creator>Onkar Joshi</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Architecture]]></category>
		<category><![CDATA[Concurrency]]></category>
		<category><![CDATA[Erlang]]></category>
		<category><![CDATA[Fault Tolerance]]></category>
		<category><![CDATA[Scalability]]></category>

		<guid isPermaLink="false">http://www.onkarjoshi.com/blog/?p=152</guid>
		<description><![CDATA[I saw a bunch of presentations on Erlang recently. The talks by Joe Armstrong, the inventor of the language, are quite lightweight on code content and the actual language itself and are interspersed with humor. He mostly talks about the central problems which Erlang is designed to solve &#8211; scalable, fault tolerant, shared nothing architecture [...]<div class='yarpp-related-rss yarpp-related-none'>

No related posts.
</div>
]]></description>
				<content:encoded><![CDATA[<p>I saw a bunch of presentations on Erlang recently. The talks by Joe Armstrong, the inventor of the language, are quite lightweight on code content and the actual language itself and are interspersed with humor. He mostly talks about the central problems which Erlang is designed to solve &#8211; scalable, fault tolerant, shared nothing architecture and communication by &#8216;pure message passing&#8217;.</p>
<p>Some notes for the Erlang layman-</p>
<ul>
<li>It is a functional programming language &#8211; that&#8217;s quite different from what a Java programmer is used too.</li>
<li>Variables in Erlang don&#8217;t vary! Everything is immutable. (Wow, how does someone do any programming at all in Erlang?)</li>
<li>The immutability takes away a lot of the problems of doing concurrency correctly.</li>
<li>Erlang is designed to have hot swappable code &#8211; change running code without bringing down your systems!</li>
<li>No sharing and no locking. This means that an entire class of problems related to synchronization, locks, memory visibility in languages like Java go away.</li>
<li>A &#8216;process&#8217; in Erlang is extremely lightweight and is analogous to what is a thread to a Java programmer (but there are differences if you go into details).</li>
<li>Erlang aims to be scalable to hundreds of thousands or even millions of concurrent processes.</li>
<li>Joe Armstrong reasons that the shared memory model of doing concurrency cannot scale like the pure message passing model of concurrency in Erlang can.</li>
</ul>
<p>I looked around on a few job sites to see if investing time learning more about Erlang is likely to be worth it. Looks like there are very, very few jobs out there currently that quote Erlang as a required skill. Perhaps that will change in a few years when multi-core systems scale up to hundreds of cores. The design principles are still a valuable takeaway from the talks. At least I know something about another way to solve problems of scale, concurrency and fault tolerance. Perhaps I&#8217;ll choose Erlang when the right problem comes along.</p>
<p>For the time being, I&#8217;ll probably just try out running some basic Erlang examples and will keep an eye out for growth in its popularity.</p>
<p><strong>Links to Joe&#8217;s presentations on Erlang on InfoQ</strong><br />
<a href="http://www.infoq.com/presentations/joe-armstrong-erlang-qcon08" target="_blank">Functions + Messages + Concurrency = Erlang</a><br />
<a href="http://www.infoq.com/presentations/Systems-that-Never-Stop-Joe-Armstrong" target="_blank">Systems that Never Stop (and Erlang)</a><br />
<a href="http://www.infoq.com/presentations/Message-Passing-Concurrency" target="_blank">Message Passing Concurrency in Erlang</a><br />
<a href="http://www.infoq.com/presentations/erlang-software-for-a-concurrent-world" target="_blank">Erlang &#8211; Software for a concurrent world</a></p>
<div class='yarpp-related-rss yarpp-related-none'>
<p>No related posts.</p>
</div>
<img src="http://feeds.feedburner.com/~r/onkarjoshi/~4/TjDwOf6qcTQ" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.onkarjoshi.com/blog/152/erlang-a-very-basic-introduction/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.onkarjoshi.com/blog/152/erlang-a-very-basic-introduction/</feedburner:origLink></item>
		<item>
		<title>How to use a patch jar to override existing Java class files temporarily</title>
		<link>http://feedproxy.google.com/~r/onkarjoshi/~3/gWRzUYh6DfY/</link>
		<comments>http://www.onkarjoshi.com/blog/133/how-to-use-a-patch-jar-to-override-existing-java-class-files-temporarily/#comments</comments>
		<pubDate>Tue, 02 Mar 2010 19:45:44 +0000</pubDate>
		<dc:creator>Onkar Joshi</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[class loader]]></category>
		<category><![CDATA[classpath]]></category>
		<category><![CDATA[jar]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[patch]]></category>

		<guid isPermaLink="false">http://www.onkarjoshi.com/blog/?p=133</guid>
		<description><![CDATA[Suppose you have a large application running in production. A production issue has been reported to you. You are not sure what the problem is. You want to add some log statements to the code. Perhaps you want to try out a small fix too &#8211; a 3 line change in the code of a [...]<div class='yarpp-related-rss'>

Related posts:<ol>
<li><a href='http://www.onkarjoshi.com/blog/234/maven-dependency-local-jar-file-from-an-external-third-party-to-be-installed-into-project-repository/' rel='bookmark' title='Maven dependency &#8211; Local jar file from an external third party to be installed into project repository'>Maven dependency &#8211; Local jar file from an external third party to be installed into project repository</a></li>
<li><a href='http://www.onkarjoshi.com/blog/112/wildcard-in-java-classpath/' rel='bookmark' title='Wildcard in Java classpath'>Wildcard in Java classpath</a></li>
<li><a href='http://www.onkarjoshi.com/blog/246/java-the-4-innernested-class-types/' rel='bookmark' title='Java &#8211; The 4 inner/nested class types'>Java &#8211; The 4 inner/nested class types</a></li>
<li><a href='http://www.onkarjoshi.com/blog/244/double-braces-initialization-in-java/' rel='bookmark' title='Double braces initialization in Java'>Double braces initialization in Java</a></li>
<li><a href='http://www.onkarjoshi.com/blog/239/eclipse-jsp-jstl-error-cannot-find-the-tag-library-descriptor/' rel='bookmark' title='Eclipse jsp jstl error &#8211; Cannot find the tag library descriptor for http://java.sun.com/jsp/jstl/core'>Eclipse jsp jstl error &#8211; Cannot find the tag library descriptor for http://java.sun.com/jsp/jstl/core</a></li>
</ol>
</div>
]]></description>
				<content:encoded><![CDATA[<p style="text-align: justify;">Suppose you have a large application running in production. A production issue has been reported to you. You are not sure what the problem is. You want to add some log statements to the code. Perhaps you want to try out a small fix too &#8211; a 3 line change in the code of a single Java file. How would you go about using the logging code or the updated class file in your app? You don&#8217;t want to go through a complex and formal &#8220;Install&#8221; procedure for your new version.</p>
<p style="text-align: justify;"><em>One way to do this is &#8211; </em></p>
<p style="text-align: justify;">Make the code changes in your Eclipse workspace (or whatever IDE you use). Use the &#8216;Export as Jar&#8217; option for the changed source file(s) &#8211; export only the compiled class files. Eclipse will put them in the appropriate package structure. Add the the jar onto the beginning of your classpath &#8211; how to do this will depend on your application. The easiest way is to just drop it into the $JAVA_HOME\lib\ext folder &#8211; the CLASSPATH won&#8217;t matter then.</p>
<p><em>Or you could try something from this list that works for you -</em></p>
<ul>
<li>Modify a start script.</li>
<li>Change an environment variable.</li>
<li>Add to a properties file.</li>
<li>Maybe change a Jar file manifest.</li>
</ul>
<p style="text-align: justify;">Of course, you&#8217;ll also need to restart your app. Hot-Swapping is also a possibility &#8211; that doesn&#8217;t need a restart to update classes in many cases. And Java Rebel brings to the table a much more powerful form of Hot-Swapping that requires far fewer restarts. But neither are recommended for production systems.</p>
<p style="text-align: justify;">The class files within your patch jar should now be used rather than your original class files since the class loader will pick what it finds first. When you are done with your testing, you can simply remove the patch jar and restart again. You can even leave the configuration in place &#8211; a missing patch jar shouldn&#8217;t cause any trouble.</p>
<div class='yarpp-related-rss'>
<p>Related posts:<ol>
<li><a href='http://www.onkarjoshi.com/blog/234/maven-dependency-local-jar-file-from-an-external-third-party-to-be-installed-into-project-repository/' rel='bookmark' title='Maven dependency &#8211; Local jar file from an external third party to be installed into project repository'>Maven dependency &#8211; Local jar file from an external third party to be installed into project repository</a></li>
<li><a href='http://www.onkarjoshi.com/blog/112/wildcard-in-java-classpath/' rel='bookmark' title='Wildcard in Java classpath'>Wildcard in Java classpath</a></li>
<li><a href='http://www.onkarjoshi.com/blog/246/java-the-4-innernested-class-types/' rel='bookmark' title='Java &#8211; The 4 inner/nested class types'>Java &#8211; The 4 inner/nested class types</a></li>
<li><a href='http://www.onkarjoshi.com/blog/244/double-braces-initialization-in-java/' rel='bookmark' title='Double braces initialization in Java'>Double braces initialization in Java</a></li>
<li><a href='http://www.onkarjoshi.com/blog/239/eclipse-jsp-jstl-error-cannot-find-the-tag-library-descriptor/' rel='bookmark' title='Eclipse jsp jstl error &#8211; Cannot find the tag library descriptor for http://java.sun.com/jsp/jstl/core'>Eclipse jsp jstl error &#8211; Cannot find the tag library descriptor for http://java.sun.com/jsp/jstl/core</a></li>
</ol></p>
</div>
<img src="http://feeds.feedburner.com/~r/onkarjoshi/~4/gWRzUYh6DfY" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.onkarjoshi.com/blog/133/how-to-use-a-patch-jar-to-override-existing-java-class-files-temporarily/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		<feedburner:origLink>http://www.onkarjoshi.com/blog/133/how-to-use-a-patch-jar-to-override-existing-java-class-files-temporarily/</feedburner:origLink></item>
		<item>
		<title>Add site owner verification code for a free WordPress.com blog</title>
		<link>http://feedproxy.google.com/~r/onkarjoshi/~3/9xvls4xS-10/</link>
		<comments>http://www.onkarjoshi.com/blog/130/add-site-owner-verification-code-for-a-free-wordpress-com-blog/#comments</comments>
		<pubDate>Tue, 02 Mar 2010 11:19:42 +0000</pubDate>
		<dc:creator>Onkar Joshi</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[bing]]></category>
		<category><![CDATA[Google]]></category>
		<category><![CDATA[Microsoft]]></category>
		<category><![CDATA[tools]]></category>
		<category><![CDATA[webmaster]]></category>
		<category><![CDATA[yahoo]]></category>

		<guid isPermaLink="false">http://www.onkarjoshi.com/blog/?p=130</guid>
		<description><![CDATA[Google Webmaster Tools allows website owners to prove to Google that they are the owner of a particular website. To do this, a Webmaster needs to register on Google Webmaster Tools. He is then given a code that he needs to place at a certain location on his website. Google will then send a crawler [...]<div class='yarpp-related-rss'>

Related posts:<ol>
<li><a href='http://www.onkarjoshi.com/blog/29/dont-post-onto-your-blog-too-fast-to-avoid-losing-traffic/' rel='bookmark' title='Don&#039;t post onto your blog too fast to avoid losing traffic!'>Don&#039;t post onto your blog too fast to avoid losing traffic!</a></li>
<li><a href='http://www.onkarjoshi.com/blog/82/firefox-3-the-awesome-bar/' rel='bookmark' title='Firefox 3 &#8211; The awesome bar'>Firefox 3 &#8211; The awesome bar</a></li>
<li><a href='http://www.onkarjoshi.com/blog/194/eclipse-tip-add-a-short-cut-key-to-skip-all-breakpoints/' rel='bookmark' title='Eclipse tip: Add a short cut key to Skip All Breakpoints'>Eclipse tip: Add a short cut key to Skip All Breakpoints</a></li>
<li><a href='http://www.onkarjoshi.com/blog/73/googling-sun-developer-network-leads-to-microsoft-visual-studio-ad/' rel='bookmark' title='Googling Sun Developer Network leads to Microsoft Visual Studio ad'>Googling Sun Developer Network leads to Microsoft Visual Studio ad</a></li>
</ol>
</div>
]]></description>
				<content:encoded><![CDATA[<p style="text-align: justify;">Google Webmaster Tools allows website owners to prove to Google that they are the owner of a particular website.</p>
<p style="text-align: justify;">To do this, a Webmaster needs to register on Google Webmaster Tools. He is then given a code that he needs to place at a certain location on his website. Google will then send a crawler to that location to look for he code. If the correct code is found, the Webmaster has effectively proved that he has control over that domain.</p>
<p style="text-align: justify;">Google will then show the webmaster various statistics related to search terms, crawlers and links on the claimed website.</p>
<p style="text-align: justify;">Now for quite some time, I was somehow under the impression that free WordPress.com blogs (yourname.wordpress.com) could not prove ownership of their blog since there was no way to upload files to the domain or to add Meta tags to the blog code which is another way that Google allows you to add the code to your site.</p>
<p style="text-align: justify;">Well, silly me. It turns out that even free WordPress.com blogs do have a way to add the required Meta tags. But in my defense, they have really put it in a place where it is hidden away quite well.</p>
<p style="text-align: justify;">Click Tools under the Tools menu on the left hand side bar. Scroll to the lower part of the content section of the page. And here you see the &#8220;Webmaster Tools Verification&#8221; section. You can enter codes for Google Webmaster Tools, Yahoo! site Explorer and Bing Webmaster Center over here.</p>
<p style="text-align: center;"><img class="aligncenter size-full wp-image-131" title="webmaster-tools" src="http://www.onkarjoshi.com/blog/wp-content/uploads/2010/03/webmaster-tools.png" alt="" width="524" height="272" /></p>
<div class='yarpp-related-rss'>
<p>Related posts:<ol>
<li><a href='http://www.onkarjoshi.com/blog/29/dont-post-onto-your-blog-too-fast-to-avoid-losing-traffic/' rel='bookmark' title='Don&#039;t post onto your blog too fast to avoid losing traffic!'>Don&#039;t post onto your blog too fast to avoid losing traffic!</a></li>
<li><a href='http://www.onkarjoshi.com/blog/82/firefox-3-the-awesome-bar/' rel='bookmark' title='Firefox 3 &#8211; The awesome bar'>Firefox 3 &#8211; The awesome bar</a></li>
<li><a href='http://www.onkarjoshi.com/blog/194/eclipse-tip-add-a-short-cut-key-to-skip-all-breakpoints/' rel='bookmark' title='Eclipse tip: Add a short cut key to Skip All Breakpoints'>Eclipse tip: Add a short cut key to Skip All Breakpoints</a></li>
<li><a href='http://www.onkarjoshi.com/blog/73/googling-sun-developer-network-leads-to-microsoft-visual-studio-ad/' rel='bookmark' title='Googling Sun Developer Network leads to Microsoft Visual Studio ad'>Googling Sun Developer Network leads to Microsoft Visual Studio ad</a></li>
</ol></p>
</div>
<img src="http://feeds.feedburner.com/~r/onkarjoshi/~4/9xvls4xS-10" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.onkarjoshi.com/blog/130/add-site-owner-verification-code-for-a-free-wordpress-com-blog/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		<feedburner:origLink>http://www.onkarjoshi.com/blog/130/add-site-owner-verification-code-for-a-free-wordpress-com-blog/</feedburner:origLink></item>
		<item>
		<title>Understand FTP Passive (PASV) and Active modes</title>
		<link>http://feedproxy.google.com/~r/onkarjoshi/~3/mJadfESR9gc/</link>
		<comments>http://www.onkarjoshi.com/blog/128/understand-ftp-passive-pasv-and-active-modes/#comments</comments>
		<pubDate>Tue, 02 Mar 2010 06:52:22 +0000</pubDate>
		<dc:creator>Onkar Joshi</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[active]]></category>
		<category><![CDATA[firewall]]></category>
		<category><![CDATA[ftp]]></category>
		<category><![CDATA[ftps]]></category>
		<category><![CDATA[passive]]></category>
		<category><![CDATA[pasv]]></category>
		<category><![CDATA[port]]></category>
		<category><![CDATA[sftp]]></category>
		<category><![CDATA[ssh]]></category>
		<category><![CDATA[ssl]]></category>

		<guid isPermaLink="false">http://www.onkarjoshi.com/blog/?p=128</guid>
		<description><![CDATA[FTP has two basic transmission channels - A control channel (for FTP commands) A data channel In an Active mode FTP session the data channel is established by the server initiating a connection to the client. This quite often turns out to be a problem for a client that is behind a corporate Firewall / [...]<div class='yarpp-related-rss'>

Related posts:<ol>
<li><a href='http://www.onkarjoshi.com/blog/126/which-library-to-use-for-ftp-sftp-ftps-file-transfer-in-java/' rel='bookmark' title='Which library to use for FTP, SFTP, FTPS file transfer in Java?'>Which library to use for FTP, SFTP, FTPS file transfer in Java?</a></li>
<li><a href='http://www.onkarjoshi.com/blog/174/hotspot-jvm-client-server-vm-optimization/' rel='bookmark' title='HotSpot JVM &#8211; Client / Server VM optimization &#8211; 260ms vs 0ms!'>HotSpot JVM &#8211; Client / Server VM optimization &#8211; 260ms vs 0ms!</a></li>
<li><a href='http://www.onkarjoshi.com/blog/77/how-to-split-a-file-process-the-pieces-in-multiple-threads-and-combine-results-using-a-shell-script/' rel='bookmark' title='How to split a file, process the pieces in multiple threads and combine results using a shell script'>How to split a file, process the pieces in multiple threads and combine results using a shell script</a></li>
</ol>
</div>
]]></description>
				<content:encoded><![CDATA[<p style="text-align: justify;">FTP has two basic transmission channels -</p>
<ul>
<li>A control channel (for FTP commands)</li>
<li>A data channel</li>
</ul>
<p style="text-align: justify;">In an Active mode FTP session the data channel is established by the server initiating a connection to the client. This quite often turns out to be a problem for a client that is behind a corporate Firewall / NAT because connections coming into the network are blocked by default.</p>
<p style="text-align: justify;">To get around this, FTP has a Passive mode. In this mode, the client tells the server to listen for a data connection initiated by the client. The server tells the client which IP, port it will listen on. So the firewall problem is solved since the control and the data channel will both be setup by outgoing connections that are likely to be safe from firewall interference.</p>
<p>Here are some notes you may find to be of use if you are dealing with this -</p>
<ul style="text-align: justify;">
<li>Passive mode ensure that all connections are initiated by the client.</li>
<li>The PASV command is used to enter Passive mode.</li>
<li>The server replies to PASV with something like &#8220;227 Entering Passive Mode (192,168,10,25,10,20).&#8221; &#8211; This means that the server will wait for a data connection from the client on 192.168.10.25 on port 2580 (256 x 10 + 20).</li>
<li>In case of an Active mode connection, the client tells the server that it will wait for a data connection by issuing the PORT command &#8211; &#8220;PORT 192,168,10,25,10,20&#8243;.</li>
<li>If you are writing code to use FTP, SFTP or FTPS without using an FTP client and run into problems, test with a known FTP client &#8211; if it can transfer files successfully, surely your code should be able to do so as well.</li>
<li>All popular FTP clients show a log of the commands they are executing. Look at these for hints on what could be going wrong.</li>
<li>Make sure you are using the right type out of FTP, SFTP, FTPS or out of Active, Passive or out of Explicit, Implicit SSL.</li>
<li>SFTP is different. It has no concept of Active or Passive mode or of separate connections being established for data and control channels.</li>
<li>You can use TCPView to monitor what connections are being setup on your machine.</li>
</ul>
<div class='yarpp-related-rss'>
<p>Related posts:<ol>
<li><a href='http://www.onkarjoshi.com/blog/126/which-library-to-use-for-ftp-sftp-ftps-file-transfer-in-java/' rel='bookmark' title='Which library to use for FTP, SFTP, FTPS file transfer in Java?'>Which library to use for FTP, SFTP, FTPS file transfer in Java?</a></li>
<li><a href='http://www.onkarjoshi.com/blog/174/hotspot-jvm-client-server-vm-optimization/' rel='bookmark' title='HotSpot JVM &#8211; Client / Server VM optimization &#8211; 260ms vs 0ms!'>HotSpot JVM &#8211; Client / Server VM optimization &#8211; 260ms vs 0ms!</a></li>
<li><a href='http://www.onkarjoshi.com/blog/77/how-to-split-a-file-process-the-pieces-in-multiple-threads-and-combine-results-using-a-shell-script/' rel='bookmark' title='How to split a file, process the pieces in multiple threads and combine results using a shell script'>How to split a file, process the pieces in multiple threads and combine results using a shell script</a></li>
</ol></p>
</div>
<img src="http://feeds.feedburner.com/~r/onkarjoshi/~4/mJadfESR9gc" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.onkarjoshi.com/blog/128/understand-ftp-passive-pasv-and-active-modes/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.onkarjoshi.com/blog/128/understand-ftp-passive-pasv-and-active-modes/</feedburner:origLink></item>
		<item>
		<title>Which library to use for FTP, SFTP, FTPS file transfer in Java?</title>
		<link>http://feedproxy.google.com/~r/onkarjoshi/~3/s-18CDihbh4/</link>
		<comments>http://www.onkarjoshi.com/blog/126/which-library-to-use-for-ftp-sftp-ftps-file-transfer-in-java/#comments</comments>
		<pubDate>Mon, 01 Mar 2010 15:14:11 +0000</pubDate>
		<dc:creator>Onkar Joshi</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[ftp]]></category>
		<category><![CDATA[ftps]]></category>
		<category><![CDATA[jcraft]]></category>
		<category><![CDATA[jscape]]></category>
		<category><![CDATA[keystore]]></category>
		<category><![CDATA[keytool]]></category>
		<category><![CDATA[sftp]]></category>
		<category><![CDATA[ssh]]></category>
		<category><![CDATA[ssl]]></category>
		<category><![CDATA[zehon]]></category>

		<guid isPermaLink="false">http://www.onkarjoshi.com/blog/?p=126</guid>
		<description><![CDATA[Recently, I was writing code to transfer data to third party servers. In some cases my interface to them was SFTP (Secure FTP) and in others FTPS (FTP-SSL). And existing coding for one of these really didn&#8217;t take care of the other. I evaluated and tested a few different libraries to see which would work [...]<div class='yarpp-related-rss'>

Related posts:<ol>
<li><a href='http://www.onkarjoshi.com/blog/128/understand-ftp-passive-pasv-and-active-modes/' rel='bookmark' title='Understand FTP Passive (PASV) and Active modes'>Understand FTP Passive (PASV) and Active modes</a></li>
<li><a href='http://www.onkarjoshi.com/blog/123/how-to-create-a-file-of-arbitrary-size-with-shell-script-commands/' rel='bookmark' title='How to create a file of arbitrary size with shell script commands'>How to create a file of arbitrary size with shell script commands</a></li>
</ol>
</div>
]]></description>
				<content:encoded><![CDATA[<p style="text-align: justify;">Recently, I was writing code to transfer data to third party servers. In some cases my interface to them was SFTP (Secure FTP) and in others FTPS (FTP-SSL). And existing coding for one of these really didn&#8217;t take care of the other. I evaluated and tested a few different libraries to see which would work well for us. Here are a few quick notes on a few of them.</p>
<p><strong>JScape</strong></p>
<ul>
<li>I read about quite a few people recommending this as the quality solution.</li>
<li>This isn&#8217;t free in terms of $$$.</li>
<li>If file transfer is important to you and you are willing to pay for it, you may want to go with JScape.</li>
</ul>
<p><strong>Zehon</strong></p>
<ul>
<li>The Zehon libraries have support for FTP, SFTP and FTPS.</li>
<li>They offer a very simple interface in the form of a bunch of static methods to do actions like sending and receiving files.</li>
<li>No source code is provided.</li>
<li>Can be difficult to debug in case of problems.</li>
<li>They do use Apache Commons Net as a base but some of the power is hidden by Zehon in exchange for simplicity.</li>
</ul>
<p><strong>Apache Commons Net</strong></p>
<ul>
<li>Using this directly offers greater power and more complete control over the protocol features compared to Zehon.</li>
<li>For a quick start, see sample code in &#8220;examples.FTPExample&#8221; provided with the Apache Comons Net source distribution.</li>
<li>No support for SFTP.</li>
</ul>
<p><strong>JCraft JSch</strong></p>
<ul>
<li>Widely used for SFTP.</li>
<li>&#8220;JSch is a pure Java implementation of SSH2.&#8221;</li>
</ul>
<p style="text-align: justify;"><em>Here are some issues you may run into -</em></p>
<ul>
<li>You may need to pick up some understanding of &#8220;Impicit SSL&#8221; and of the &#8220;PASV&#8221; (passive) mode to deal with firewall issues.</li>
<li>For Zehon, I had to specify a keystore it could use. Apache picked up the default java certs keystore with its default configuration.</li>
<li style="text-align: justify;">I believe the core Apache Commons Net library (and hence Zehon too) has some kind of a caching/flushing bug. When trying to transfer very small files of size 1 byte to 175 bytes or so, the library reported the file to have been transferred successfully &#8211; but it actually resulted in a zero byte file being created at the target location. Beware! I&#8217;ll write about how I fixed this in a different post. I had to add a bit of code in the Apache Commons Net sources and use my own compiled jar for it to work well.</li>
<li>If you are really doing security correctly &#8211; you will need to know how to use keytool and how to handle your certificates correctly.</li>
<li>You can use the free FileZilla FTP Server to start an FTP server on your own machine for development and testing.</li>
</ul>
<p style="text-align: justify;">
<div class='yarpp-related-rss'>
<p>Related posts:<ol>
<li><a href='http://www.onkarjoshi.com/blog/128/understand-ftp-passive-pasv-and-active-modes/' rel='bookmark' title='Understand FTP Passive (PASV) and Active modes'>Understand FTP Passive (PASV) and Active modes</a></li>
<li><a href='http://www.onkarjoshi.com/blog/123/how-to-create-a-file-of-arbitrary-size-with-shell-script-commands/' rel='bookmark' title='How to create a file of arbitrary size with shell script commands'>How to create a file of arbitrary size with shell script commands</a></li>
</ol></p>
</div>
<img src="http://feeds.feedburner.com/~r/onkarjoshi/~4/s-18CDihbh4" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.onkarjoshi.com/blog/126/which-library-to-use-for-ftp-sftp-ftps-file-transfer-in-java/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
		<feedburner:origLink>http://www.onkarjoshi.com/blog/126/which-library-to-use-for-ftp-sftp-ftps-file-transfer-in-java/</feedburner:origLink></item>
		<item>
		<title>How to create a file of arbitrary size with fsutil in Windows XP</title>
		<link>http://feedproxy.google.com/~r/onkarjoshi/~3/BOE658LDvoc/</link>
		<comments>http://www.onkarjoshi.com/blog/125/how-to-create-a-file-of-arbitrary-size-with-fsutil-in-windows-xp/#comments</comments>
		<pubDate>Sun, 28 Feb 2010 05:20:30 +0000</pubDate>
		<dc:creator>Onkar Joshi</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[command line]]></category>
		<category><![CDATA[util]]></category>
		<category><![CDATA[Windows]]></category>
		<category><![CDATA[xp]]></category>

		<guid isPermaLink="false">http://www.onkarjoshi.com/blog/?p=125</guid>
		<description><![CDATA[This post is a sequel to &#8211; How to create a file of arbitrary size in Linux Few people have used the fsutil command in Windows. Here is how you can use it to create a file of any desired size - fsutil file create myFile.dat 10240 This will create a file of size 10KB [...]<div class='yarpp-related-rss'>

Related posts:<ol>
<li><a href='http://www.onkarjoshi.com/blog/123/how-to-create-a-file-of-arbitrary-size-with-shell-script-commands/' rel='bookmark' title='How to create a file of arbitrary size with shell script commands'>How to create a file of arbitrary size with shell script commands</a></li>
<li><a href='http://www.onkarjoshi.com/blog/14/updating-firefox-2-manually-using-a-mar-file-when-auto-update-fails/' rel='bookmark' title='Updating Firefox 2 manually using a MAR file when auto-update fails'>Updating Firefox 2 manually using a MAR file when auto-update fails</a></li>
<li><a href='http://www.onkarjoshi.com/blog/43/partitioning-help-for-multi-booting-ubuntu-linux-and-windows-xp-safely/' rel='bookmark' title='Partitioning help for multi booting Ubuntu Linux and Windows XP safely'>Partitioning help for multi booting Ubuntu Linux and Windows XP safely</a></li>
<li><a href='http://www.onkarjoshi.com/blog/77/how-to-split-a-file-process-the-pieces-in-multiple-threads-and-combine-results-using-a-shell-script/' rel='bookmark' title='How to split a file, process the pieces in multiple threads and combine results using a shell script'>How to split a file, process the pieces in multiple threads and combine results using a shell script</a></li>
<li><a href='http://www.onkarjoshi.com/blog/154/turn-off-the-windows-automatic-updates-remind-me-later-nag-screen/' rel='bookmark' title='Turn off the Windows Automatic Updates &#8216;Restart later&#8217; nag screen'>Turn off the Windows Automatic Updates &#8216;Restart later&#8217; nag screen</a></li>
</ol>
</div>
]]></description>
				<content:encoded><![CDATA[<p>This post is a sequel to &#8211; <a href="http://www.onkarjoshi.com/blog/123/how-to-create-a-file-of-arbitrary-size-with-shell-script-commands/">How to create a file of arbitrary size in Linux</a></p>
<p>Few people have used the fsutil command in Windows. Here is how you can use it to create a file of any desired size -</p>
<p><strong><span style="color: #008000;">fsutil file create myFile.dat 10240</span></strong></p>
<p>This will create a file of size 10KB in the current directory.</p>
<p>There are other interesting things that <strong>fsutil </strong>is capable of.  You may want to check out the other options it shows in the command line help.</p>
<div class='yarpp-related-rss'>
<p>Related posts:<ol>
<li><a href='http://www.onkarjoshi.com/blog/123/how-to-create-a-file-of-arbitrary-size-with-shell-script-commands/' rel='bookmark' title='How to create a file of arbitrary size with shell script commands'>How to create a file of arbitrary size with shell script commands</a></li>
<li><a href='http://www.onkarjoshi.com/blog/14/updating-firefox-2-manually-using-a-mar-file-when-auto-update-fails/' rel='bookmark' title='Updating Firefox 2 manually using a MAR file when auto-update fails'>Updating Firefox 2 manually using a MAR file when auto-update fails</a></li>
<li><a href='http://www.onkarjoshi.com/blog/43/partitioning-help-for-multi-booting-ubuntu-linux-and-windows-xp-safely/' rel='bookmark' title='Partitioning help for multi booting Ubuntu Linux and Windows XP safely'>Partitioning help for multi booting Ubuntu Linux and Windows XP safely</a></li>
<li><a href='http://www.onkarjoshi.com/blog/77/how-to-split-a-file-process-the-pieces-in-multiple-threads-and-combine-results-using-a-shell-script/' rel='bookmark' title='How to split a file, process the pieces in multiple threads and combine results using a shell script'>How to split a file, process the pieces in multiple threads and combine results using a shell script</a></li>
<li><a href='http://www.onkarjoshi.com/blog/154/turn-off-the-windows-automatic-updates-remind-me-later-nag-screen/' rel='bookmark' title='Turn off the Windows Automatic Updates &#8216;Restart later&#8217; nag screen'>Turn off the Windows Automatic Updates &#8216;Restart later&#8217; nag screen</a></li>
</ol></p>
</div>
<img src="http://feeds.feedburner.com/~r/onkarjoshi/~4/BOE658LDvoc" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.onkarjoshi.com/blog/125/how-to-create-a-file-of-arbitrary-size-with-fsutil-in-windows-xp/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		<feedburner:origLink>http://www.onkarjoshi.com/blog/125/how-to-create-a-file-of-arbitrary-size-with-fsutil-in-windows-xp/</feedburner:origLink></item>
		<item>
		<title>How to create a file of arbitrary size with shell script commands</title>
		<link>http://feedproxy.google.com/~r/onkarjoshi/~3/gnniUtHbkhw/</link>
		<comments>http://www.onkarjoshi.com/blog/123/how-to-create-a-file-of-arbitrary-size-with-shell-script-commands/#comments</comments>
		<pubDate>Sun, 28 Feb 2010 00:47:46 +0000</pubDate>
		<dc:creator>Onkar Joshi</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[script]]></category>
		<category><![CDATA[shell]]></category>
		<category><![CDATA[Solaris]]></category>
		<category><![CDATA[Unix]]></category>

		<guid isPermaLink="false">http://www.onkarjoshi.com/blog/?p=123</guid>
		<description><![CDATA[A few days ago I was working on writing Java code to transfer files via SFTP and FTPS. As part of the test cases, I wanted to try and transfer files of small medium and large sizes like 0 byte, 1 byte, 100 bytes, 1000 bytes, 1MB, 10MB. How would one go about creating files [...]<div class='yarpp-related-rss'>

Related posts:<ol>
<li><a href='http://www.onkarjoshi.com/blog/125/how-to-create-a-file-of-arbitrary-size-with-fsutil-in-windows-xp/' rel='bookmark' title='How to create a file of arbitrary size with fsutil in Windows XP'>How to create a file of arbitrary size with fsutil in Windows XP</a></li>
<li><a href='http://www.onkarjoshi.com/blog/77/how-to-split-a-file-process-the-pieces-in-multiple-threads-and-combine-results-using-a-shell-script/' rel='bookmark' title='How to split a file, process the pieces in multiple threads and combine results using a shell script'>How to split a file, process the pieces in multiple threads and combine results using a shell script</a></li>
<li><a href='http://www.onkarjoshi.com/blog/191/device-dev-random-vs-urandom/' rel='bookmark' title='/dev/random vs /dev/urandom'>/dev/random vs /dev/urandom</a></li>
<li><a href='http://www.onkarjoshi.com/blog/43/partitioning-help-for-multi-booting-ubuntu-linux-and-windows-xp-safely/' rel='bookmark' title='Partitioning help for multi booting Ubuntu Linux and Windows XP safely'>Partitioning help for multi booting Ubuntu Linux and Windows XP safely</a></li>
<li><a href='http://www.onkarjoshi.com/blog/126/which-library-to-use-for-ftp-sftp-ftps-file-transfer-in-java/' rel='bookmark' title='Which library to use for FTP, SFTP, FTPS file transfer in Java?'>Which library to use for FTP, SFTP, FTPS file transfer in Java?</a></li>
</ol>
</div>
]]></description>
				<content:encoded><![CDATA[<p style="text-align: justify;">A few days ago I was working on writing Java code to transfer files via SFTP and FTPS. As part of the test cases, I wanted to try and transfer files of small medium and large sizes like 0 byte, 1 byte, 100 bytes, 1000 bytes, 1MB, 10MB. How would one go about creating files of a certain size in a Linux/Solarix/Unix environment?</p>
<p>You can do it with the <strong>dd </strong>command. You can use /dev/random or /dev/zero as a data source for random bytes or null bytes.</p>
<p>bs = block size<br />
count = number of blocks<br />
if = input file<br />
of = output file</p>
<p style="text-align: justify;">The total size of the file created will be bs x count bytes.</p>
<p>dd if=/dev/random of=myFile.dat bs=1024 count=102400<br />
dd if=/dev/random of=myFile.dat bs=1024 count=1024<br />
dd if=/dev/random of=myFile.dat bs=100 count=1<br />
dd if=/dev/random of=myFile.dat bs=1 count=1</p>
<p>The above commands will create files of sizes 100MB, 1MB, 100 bytes, 1 byte respectively with random data.</p>
<div class='yarpp-related-rss'>
<p>Related posts:<ol>
<li><a href='http://www.onkarjoshi.com/blog/125/how-to-create-a-file-of-arbitrary-size-with-fsutil-in-windows-xp/' rel='bookmark' title='How to create a file of arbitrary size with fsutil in Windows XP'>How to create a file of arbitrary size with fsutil in Windows XP</a></li>
<li><a href='http://www.onkarjoshi.com/blog/77/how-to-split-a-file-process-the-pieces-in-multiple-threads-and-combine-results-using-a-shell-script/' rel='bookmark' title='How to split a file, process the pieces in multiple threads and combine results using a shell script'>How to split a file, process the pieces in multiple threads and combine results using a shell script</a></li>
<li><a href='http://www.onkarjoshi.com/blog/191/device-dev-random-vs-urandom/' rel='bookmark' title='/dev/random vs /dev/urandom'>/dev/random vs /dev/urandom</a></li>
<li><a href='http://www.onkarjoshi.com/blog/43/partitioning-help-for-multi-booting-ubuntu-linux-and-windows-xp-safely/' rel='bookmark' title='Partitioning help for multi booting Ubuntu Linux and Windows XP safely'>Partitioning help for multi booting Ubuntu Linux and Windows XP safely</a></li>
<li><a href='http://www.onkarjoshi.com/blog/126/which-library-to-use-for-ftp-sftp-ftps-file-transfer-in-java/' rel='bookmark' title='Which library to use for FTP, SFTP, FTPS file transfer in Java?'>Which library to use for FTP, SFTP, FTPS file transfer in Java?</a></li>
</ol></p>
</div>
<img src="http://feeds.feedburner.com/~r/onkarjoshi/~4/gnniUtHbkhw" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.onkarjoshi.com/blog/123/how-to-create-a-file-of-arbitrary-size-with-shell-script-commands/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		<feedburner:origLink>http://www.onkarjoshi.com/blog/123/how-to-create-a-file-of-arbitrary-size-with-shell-script-commands/</feedburner:origLink></item>
		<item>
		<title>Kaspersky ate my jconsole!</title>
		<link>http://feedproxy.google.com/~r/onkarjoshi/~3/LJMRGkSmzLg/</link>
		<comments>http://www.onkarjoshi.com/blog/121/kaspersky-ate-my-jconsole/#comments</comments>
		<pubDate>Sat, 27 Feb 2010 16:46:32 +0000</pubDate>
		<dc:creator>Onkar Joshi</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[antivirus]]></category>
		<category><![CDATA[falsepositive]]></category>
		<category><![CDATA[heuristic]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[kaspersky]]></category>

		<guid isPermaLink="false">http://www.onkarjoshi.com/blog/?p=121</guid>
		<description><![CDATA[The other day I was trying to attach JConsole to a locally running Java application. Every time I tried it, Kaspersky anti virus that was running on my system &#8220;detected&#8221; a process intrusion attempt by jconsole and deleted (more accurately, quarantined) jconsole.exe. It popped up a message saying- &#8220;Process is trying to inject into another [...]<div class='yarpp-related-rss'>

Related posts:<ol>
<li><a href='http://www.onkarjoshi.com/blog/156/mcafee-anti-virus-mcshield-exe-process-eats-100-cpu-too-often/' rel='bookmark' title='McAfee anti virus mcshield.exe process eats 100% CPU too often'>McAfee anti virus mcshield.exe process eats 100% CPU too often</a></li>
<li><a href='http://www.onkarjoshi.com/blog/230/sending-a-sigbreak-signal-to-a-java-process-to-do-a-thread-dump-in-windows/' rel='bookmark' title='Sending a SIGBREAK signal to a Java process to do a thread dump in Windows'>Sending a SIGBREAK signal to a Java process to do a thread dump in Windows</a></li>
<li><a href='http://www.onkarjoshi.com/blog/166/identifying-a-thread-with-high-cpu-usage-in-a-java-app/' rel='bookmark' title='Identifying a thread with high CPU usage in a Java app'>Identifying a thread with high CPU usage in a Java app</a></li>
</ol>
</div>
]]></description>
				<content:encoded><![CDATA[<p style="text-align: justify;">The other day I was trying to attach JConsole to a locally running Java application. Every time I tried it, Kaspersky anti virus that was running on my system &#8220;detected&#8221; a process intrusion attempt by jconsole and deleted (more accurately, quarantined) jconsole.exe. It popped up a message saying-</p>
<p style="text-align: justify;">&#8220;<em>Process is trying to inject into another process. This behaviour is typical of same malicious programs (Invader).</em>&#8220;</p>
<p style="text-align: justify;">Now that&#8217;s just silly. Kaspersky really ought to have white-listed jconsole.exe. It is perfectly safe and is designed to do what Kaspersky thinks is malicious behaviour.</p>
<p style="text-align: justify;">My problem was compounded by the fact that I didn&#8217;t have admin rights to Kaspersky settings. It was maintained remotely by the admins in our corporate network. It had be restored by them every time Kaspersky quarantined the file and deleted it from its original location until I finally got them to change the setting for &#8220;Intrusion into process&#8221; under Proactive Defense settings to &#8220;Ask user&#8221; rather than &#8220;Quarantine&#8221; for me.</p>
<p style="text-align: justify;">In my opinion Kaspersky is at fault. It&#8217;s signature DB should have had jconsole.exe white-listed.</p>
<p style="text-align: center;"><img class="aligncenter size-full wp-image-122" title="jconsole_kaspersky_window" src="http://www.onkarjoshi.com/blog/wp-content/uploads/2010/02/jconsole_kaspersky_window.png" alt="" width="500" height="473" /></p>
<div class='yarpp-related-rss'>
<p>Related posts:<ol>
<li><a href='http://www.onkarjoshi.com/blog/156/mcafee-anti-virus-mcshield-exe-process-eats-100-cpu-too-often/' rel='bookmark' title='McAfee anti virus mcshield.exe process eats 100% CPU too often'>McAfee anti virus mcshield.exe process eats 100% CPU too often</a></li>
<li><a href='http://www.onkarjoshi.com/blog/230/sending-a-sigbreak-signal-to-a-java-process-to-do-a-thread-dump-in-windows/' rel='bookmark' title='Sending a SIGBREAK signal to a Java process to do a thread dump in Windows'>Sending a SIGBREAK signal to a Java process to do a thread dump in Windows</a></li>
<li><a href='http://www.onkarjoshi.com/blog/166/identifying-a-thread-with-high-cpu-usage-in-a-java-app/' rel='bookmark' title='Identifying a thread with high CPU usage in a Java app'>Identifying a thread with high CPU usage in a Java app</a></li>
</ol></p>
</div>
<img src="http://feeds.feedburner.com/~r/onkarjoshi/~4/LJMRGkSmzLg" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.onkarjoshi.com/blog/121/kaspersky-ate-my-jconsole/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.onkarjoshi.com/blog/121/kaspersky-ate-my-jconsole/</feedburner:origLink></item>
		<item>
		<title>Check for corruption of files using md5 checksum</title>
		<link>http://feedproxy.google.com/~r/onkarjoshi/~3/eRJalBKCd3g/</link>
		<comments>http://www.onkarjoshi.com/blog/119/check-for-corruption-of-files-using-md5-checksum-via-md5sum-or-winmd5/#comments</comments>
		<pubDate>Sat, 27 Feb 2010 01:49:01 +0000</pubDate>
		<dc:creator>Onkar Joshi</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[md5]]></category>
		<category><![CDATA[md5sum]]></category>
		<category><![CDATA[Shell script]]></category>
		<category><![CDATA[Solaris]]></category>
		<category><![CDATA[Windows]]></category>
		<category><![CDATA[winmd5]]></category>

		<guid isPermaLink="false">http://www.onkarjoshi.com/blog/?p=119</guid>
		<description><![CDATA[You just transferred a large multi-gigabit file from your build server to your QA server. You want to check if the files are exactly the same. Data corruption can happen for many reasons! What do you do? Remember, just because two files are the same size, it doesn&#8217;t mean that they are the same. It [...]<div class='yarpp-related-rss'>

Related posts:<ol>
<li><a href='http://www.onkarjoshi.com/blog/241/find-duplicate-files/' rel='bookmark' title='Find duplicate files'>Find duplicate files</a></li>
<li><a href='http://www.onkarjoshi.com/blog/197/use-binary-diff-tools-like-xdelta-bsdiff-bspatch-to-transfer-large-files/' rel='bookmark' title='Use binary diff tools like xdelta, bsdiff/bspatch to transfer large files'>Use binary diff tools like xdelta, bsdiff/bspatch to transfer large files</a></li>
<li><a href='http://www.onkarjoshi.com/blog/123/how-to-create-a-file-of-arbitrary-size-with-shell-script-commands/' rel='bookmark' title='How to create a file of arbitrary size with shell script commands'>How to create a file of arbitrary size with shell script commands</a></li>
<li><a href='http://www.onkarjoshi.com/blog/77/how-to-split-a-file-process-the-pieces-in-multiple-threads-and-combine-results-using-a-shell-script/' rel='bookmark' title='How to split a file, process the pieces in multiple threads and combine results using a shell script'>How to split a file, process the pieces in multiple threads and combine results using a shell script</a></li>
<li><a href='http://www.onkarjoshi.com/blog/133/how-to-use-a-patch-jar-to-override-existing-java-class-files-temporarily/' rel='bookmark' title='How to use a patch jar to override existing Java class files temporarily'>How to use a patch jar to override existing Java class files temporarily</a></li>
</ol>
</div>
]]></description>
				<content:encoded><![CDATA[<p style="text-align: justify;">You just transferred a large multi-gigabit file from your build server to your QA server. You want to check if the files are exactly the same. Data corruption can happen for many reasons! What do you do?</p>
<p>Remember, just because two files are the same size, it doesn&#8217;t mean that they are the same. It is possible that your download program padded the file to the correct size but didn&#8217;t fill in all the data. Sometimes, stopping and resuming downloads mid way can leave a file corrupted. Memory and disk errors can silently cause corruption by bit rot.</p>
<p>So how do you check the integrity of the file?</p>
<p>Use a checksum like md5sum. It is available by default on all Linux / Unix / Solaris systems. Windows users can use the free utility WinMD5.</p>
<p>The md5 checksum is basically a digital fingerprint of the file. It works by processing the contents of the file via a mixing algorithm that produces output that is practically unique for unique input.</p>
<p style="text-align: justify;">Check the screenshot below that I took on WinXP using WinMd5 sum (on Linux the command is &#8216;<em>md5sum fileName&#8217;</em>). I was comparing the checksum of an Ubuntu Linux VMWare virtual machine I downloaded to the checksum provided on the page from which I had downloaded the file. You can see that my md5 hash turned out to be the same as what was listed on the website (68b2773b177cff1ba71071f83707fba9). If even a single bit were different at my end, the fingerprint would have been completely different.</p>
<p><img class="aligncenter size-full wp-image-120" title="md5-checksum" src="http://www.onkarjoshi.com/blog/wp-content/uploads/2010/02/md5-checksum.png" alt="" width="426" height="182" /></p>
<p style="text-align: justify;">Next time you are wondering if a file is exactly the same as another, just compare the md5 checksums of the two files.</p>
<div class='yarpp-related-rss'>
<p>Related posts:<ol>
<li><a href='http://www.onkarjoshi.com/blog/241/find-duplicate-files/' rel='bookmark' title='Find duplicate files'>Find duplicate files</a></li>
<li><a href='http://www.onkarjoshi.com/blog/197/use-binary-diff-tools-like-xdelta-bsdiff-bspatch-to-transfer-large-files/' rel='bookmark' title='Use binary diff tools like xdelta, bsdiff/bspatch to transfer large files'>Use binary diff tools like xdelta, bsdiff/bspatch to transfer large files</a></li>
<li><a href='http://www.onkarjoshi.com/blog/123/how-to-create-a-file-of-arbitrary-size-with-shell-script-commands/' rel='bookmark' title='How to create a file of arbitrary size with shell script commands'>How to create a file of arbitrary size with shell script commands</a></li>
<li><a href='http://www.onkarjoshi.com/blog/77/how-to-split-a-file-process-the-pieces-in-multiple-threads-and-combine-results-using-a-shell-script/' rel='bookmark' title='How to split a file, process the pieces in multiple threads and combine results using a shell script'>How to split a file, process the pieces in multiple threads and combine results using a shell script</a></li>
<li><a href='http://www.onkarjoshi.com/blog/133/how-to-use-a-patch-jar-to-override-existing-java-class-files-temporarily/' rel='bookmark' title='How to use a patch jar to override existing Java class files temporarily'>How to use a patch jar to override existing Java class files temporarily</a></li>
</ol></p>
</div>
<img src="http://feeds.feedburner.com/~r/onkarjoshi/~4/eRJalBKCd3g" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.onkarjoshi.com/blog/119/check-for-corruption-of-files-using-md5-checksum-via-md5sum-or-winmd5/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		<feedburner:origLink>http://www.onkarjoshi.com/blog/119/check-for-corruption-of-files-using-md5-checksum-via-md5sum-or-winmd5/</feedburner:origLink></item>
		<item>
		<title>Force Firefox to save passwords even if the page disables autocomplete</title>
		<link>http://feedproxy.google.com/~r/onkarjoshi/~3/GOp0_wpKT3c/</link>
		<comments>http://www.onkarjoshi.com/blog/117/force-firefox-to-save-password-even-if-autocomplete-is-disabled/#comments</comments>
		<pubDate>Fri, 26 Feb 2010 06:35:06 +0000</pubDate>
		<dc:creator>Onkar Joshi</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Firefox]]></category>
		<category><![CDATA[Hacking]]></category>
		<category><![CDATA[Mozilla]]></category>

		<guid isPermaLink="false">http://www.onkarjoshi.com/blog/?p=117</guid>
		<description><![CDATA[The remember password feature in Firefox is a huge time saver. Of course, if you use it, you better be using the &#8216;Master password&#8217; feature too which locks down all of your saved passwords with one password that you get asked for just once &#8211; the first time when Firefox tries to load a saved [...]<div class='yarpp-related-rss'>

Related posts:<ol>
<li><a href='http://www.onkarjoshi.com/blog/10/a-simple-firefox-2-hack/' rel='bookmark' title='A Simple Firefox 2 XML Hack'>A Simple Firefox 2 XML Hack</a></li>
<li><a href='http://www.onkarjoshi.com/blog/14/updating-firefox-2-manually-using-a-mar-file-when-auto-update-fails/' rel='bookmark' title='Updating Firefox 2 manually using a MAR file when auto-update fails'>Updating Firefox 2 manually using a MAR file when auto-update fails</a></li>
<li><a href='http://www.onkarjoshi.com/blog/82/firefox-3-the-awesome-bar/' rel='bookmark' title='Firefox 3 &#8211; The awesome bar'>Firefox 3 &#8211; The awesome bar</a></li>
<li><a href='http://www.onkarjoshi.com/blog/115/content-disposition-http-header-get-save-as-dialog-on-browser/' rel='bookmark' title='Content Disposition &#8211; Get a Save As dialog on the browser'>Content Disposition &#8211; Get a Save As dialog on the browser</a></li>
<li><a href='http://www.onkarjoshi.com/blog/217/how-to-optimize-your-travel-site-not/' rel='bookmark' title='How to optimize your travel site &#8211; NOT!'>How to optimize your travel site &#8211; NOT!</a></li>
</ol>
</div>
]]></description>
				<content:encoded><![CDATA[<p style="text-align: justify;">The remember password feature in Firefox is a huge time saver. Of course, if you use it, you better be using the &#8216;Master password&#8217; feature too which locks down all of your saved passwords with one password that you get asked for just once &#8211; the first time when Firefox tries to load a saved password after you start your browser.</p>
<p>Have you noticed that on some sites, Firefox will never give you the option to save your password? Some places where this happens is on Yahoo and Hotmail login screens and on corporate email sites. Ever wondered why this happens?</p>
<p>This happens because some sites explicitly prevent that from happening by using an &#8220;autocomplete=off&#8221; attribute in the form element for that page.</p>
<p>To override this, you can modify a script in Firefox -</p>
<ol style="text-align: justify;">
<li>Close Firefox.</li>
<li>Open nsLoginManager.js from C:\Program Files\Mozilla Firefox\components in a text editor like Notepad or NoteTab++.</li>
<li>Search for &#8220;autocomplete&#8221; in this file and look for the code in the screen shot below.</li>
<li>Change &#8220;off&#8221; to &#8220;XXX&#8221; and save the file.</li>
<li>Done! Firefox will now ignore the autocomplete directive and you will be able to save passwords on more sites!</li>
</ol>
<p style="text-align: justify;"><img class="size-full wp-image-118 aligncenter" title="firefox-autocomplete" src="http://www.onkarjoshi.com/blog/wp-content/uploads/2010/02/firefox-autocomplete.png" alt="" width="476" height="191" /><br />
You may find other tips on the net which suggest commenting out the code in this method or to add code to return false from it. What is cool about my way is that the lines and offsets of all the code in that file stays the same. You just replace three characters with three different characters. This will make sure that if updates are applied to the file, there is no chance of it getting corrupted.</p>
<p>I tested this on Firefox 3.5 and it should work for sure on older 3.x versions as well.</p>
<div class='yarpp-related-rss'>
<p>Related posts:<ol>
<li><a href='http://www.onkarjoshi.com/blog/10/a-simple-firefox-2-hack/' rel='bookmark' title='A Simple Firefox 2 XML Hack'>A Simple Firefox 2 XML Hack</a></li>
<li><a href='http://www.onkarjoshi.com/blog/14/updating-firefox-2-manually-using-a-mar-file-when-auto-update-fails/' rel='bookmark' title='Updating Firefox 2 manually using a MAR file when auto-update fails'>Updating Firefox 2 manually using a MAR file when auto-update fails</a></li>
<li><a href='http://www.onkarjoshi.com/blog/82/firefox-3-the-awesome-bar/' rel='bookmark' title='Firefox 3 &#8211; The awesome bar'>Firefox 3 &#8211; The awesome bar</a></li>
<li><a href='http://www.onkarjoshi.com/blog/115/content-disposition-http-header-get-save-as-dialog-on-browser/' rel='bookmark' title='Content Disposition &#8211; Get a Save As dialog on the browser'>Content Disposition &#8211; Get a Save As dialog on the browser</a></li>
<li><a href='http://www.onkarjoshi.com/blog/217/how-to-optimize-your-travel-site-not/' rel='bookmark' title='How to optimize your travel site &#8211; NOT!'>How to optimize your travel site &#8211; NOT!</a></li>
</ol></p>
</div>
<img src="http://feeds.feedburner.com/~r/onkarjoshi/~4/GOp0_wpKT3c" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.onkarjoshi.com/blog/117/force-firefox-to-save-password-even-if-autocomplete-is-disabled/feed/</wfw:commentRss>
		<slash:comments>18</slash:comments>
		<feedburner:origLink>http://www.onkarjoshi.com/blog/117/force-firefox-to-save-password-even-if-autocomplete-is-disabled/</feedburner:origLink></item>
		<item>
		<title>Content Disposition – Get a Save As dialog on the browser</title>
		<link>http://feedproxy.google.com/~r/onkarjoshi/~3/QlzwXqLGTlI/</link>
		<comments>http://www.onkarjoshi.com/blog/115/content-disposition-http-header-get-save-as-dialog-on-browser/#comments</comments>
		<pubDate>Sun, 21 Feb 2010 09:40:47 +0000</pubDate>
		<dc:creator>Onkar Joshi</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Browser]]></category>
		<category><![CDATA[firebug]]></category>
		<category><![CDATA[header]]></category>
		<category><![CDATA[http]]></category>

		<guid isPermaLink="false">http://www.onkarjoshi.com/blog/?p=115</guid>
		<description><![CDATA[It is common for a web application to have a link to file types such as .xls or .pdf files &#8211; a typical use would be for reports generated by the application. The default behaviour of the browser is to open the linked document within the browser. What do you do if you want the [...]<div class='yarpp-related-rss'>

Related posts:<ol>
<li><a href='http://www.onkarjoshi.com/blog/117/force-firefox-to-save-password-even-if-autocomplete-is-disabled/' rel='bookmark' title='Force Firefox to save passwords even if the page disables autocomplete'>Force Firefox to save passwords even if the page disables autocomplete</a></li>
<li><a href='http://www.onkarjoshi.com/blog/10/a-simple-firefox-2-hack/' rel='bookmark' title='A Simple Firefox 2 XML Hack'>A Simple Firefox 2 XML Hack</a></li>
<li><a href='http://www.onkarjoshi.com/blog/209/using-xss-to-adjust-java-default-thread-stack-size-to-save-memory-and-prevent-stackoverflowerror/' rel='bookmark' title='Using -Xss to adjust Java default thread stack size to save memory and prevent StackOverflowError'>Using -Xss to adjust Java default thread stack size to save memory and prevent StackOverflowError</a></li>
<li><a href='http://www.onkarjoshi.com/blog/14/updating-firefox-2-manually-using-a-mar-file-when-auto-update-fails/' rel='bookmark' title='Updating Firefox 2 manually using a MAR file when auto-update fails'>Updating Firefox 2 manually using a MAR file when auto-update fails</a></li>
<li><a href='http://www.onkarjoshi.com/blog/82/firefox-3-the-awesome-bar/' rel='bookmark' title='Firefox 3 &#8211; The awesome bar'>Firefox 3 &#8211; The awesome bar</a></li>
</ol>
</div>
]]></description>
				<content:encoded><![CDATA[<p>It is common for a web application to have a link to file types such as .xls or .pdf files &#8211; a typical use would be for reports generated by the application. The default behaviour of the browser is to open the linked document within the browser.</p>
<p>What do you do if you want the browser to show the user the SaveAs dialog allowing the file to be saved to a location on the disk?</p>
<p>The browser recognizes only the file type from the well known <em>Content-Type</em> HTTP header. Whether to open or to do a &#8216;Save As&#8217; and an appropriate file name can be indicated by the less known <em>Content-Disposition</em> header. So if you want your browser to show you a SaveAs dialog, make your HTTP headers look like this -</p>
<p>Content-Type: application/pdf<br />
Content-Disposition: attachment; filename=Report-May-2010.pdf;</p>
<p>Usually, one would do this by using the response.setContentDisposition method or its equivalent in your programming language of choice.</p>
<p>Tip: If you are trying to check this or implement this, use FireBug to view the HTTP headers your app is sending.</p>
<p><img class="aligncenter size-full wp-image-116" title="content-disposition" src="http://www.onkarjoshi.com/blog/wp-content/uploads/2010/02/content-disposition.png" alt="" width="460" height="462" /></p>
<div class='yarpp-related-rss'>
<p>Related posts:<ol>
<li><a href='http://www.onkarjoshi.com/blog/117/force-firefox-to-save-password-even-if-autocomplete-is-disabled/' rel='bookmark' title='Force Firefox to save passwords even if the page disables autocomplete'>Force Firefox to save passwords even if the page disables autocomplete</a></li>
<li><a href='http://www.onkarjoshi.com/blog/10/a-simple-firefox-2-hack/' rel='bookmark' title='A Simple Firefox 2 XML Hack'>A Simple Firefox 2 XML Hack</a></li>
<li><a href='http://www.onkarjoshi.com/blog/209/using-xss-to-adjust-java-default-thread-stack-size-to-save-memory-and-prevent-stackoverflowerror/' rel='bookmark' title='Using -Xss to adjust Java default thread stack size to save memory and prevent StackOverflowError'>Using -Xss to adjust Java default thread stack size to save memory and prevent StackOverflowError</a></li>
<li><a href='http://www.onkarjoshi.com/blog/14/updating-firefox-2-manually-using-a-mar-file-when-auto-update-fails/' rel='bookmark' title='Updating Firefox 2 manually using a MAR file when auto-update fails'>Updating Firefox 2 manually using a MAR file when auto-update fails</a></li>
<li><a href='http://www.onkarjoshi.com/blog/82/firefox-3-the-awesome-bar/' rel='bookmark' title='Firefox 3 &#8211; The awesome bar'>Firefox 3 &#8211; The awesome bar</a></li>
</ol></p>
</div>
<img src="http://feeds.feedburner.com/~r/onkarjoshi/~4/QlzwXqLGTlI" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.onkarjoshi.com/blog/115/content-disposition-http-header-get-save-as-dialog-on-browser/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.onkarjoshi.com/blog/115/content-disposition-http-header-get-save-as-dialog-on-browser/</feedburner:origLink></item>
		<item>
		<title>Wildcard in Java classpath</title>
		<link>http://feedproxy.google.com/~r/onkarjoshi/~3/6BTJEjH7SWg/</link>
		<comments>http://www.onkarjoshi.com/blog/112/wildcard-in-java-classpath/#comments</comments>
		<pubDate>Wed, 17 Feb 2010 21:15:13 +0000</pubDate>
		<dc:creator>Onkar Joshi</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[classpath]]></category>
		<category><![CDATA[jar]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[JDK]]></category>
		<category><![CDATA[wildcard]]></category>

		<guid isPermaLink="false">http://www.onkarjoshi.com/blog/?p=112</guid>
		<description><![CDATA[One of the less known new features of JDK 6 is the ability to use wildcards in classpaths. That means that instead of doing&#8230; java -cp lib\x.jar;lib\y.jar;lib\z.jar; com.company.MyProggy &#8230;you could just do&#8230; java -cp lib\*.jar; com.company.MyProggy That generally turns out to be quite a time saver. Especially so if you are trying out something at [...]<div class='yarpp-related-rss'>

Related posts:<ol>
<li><a href='http://www.onkarjoshi.com/blog/133/how-to-use-a-patch-jar-to-override-existing-java-class-files-temporarily/' rel='bookmark' title='How to use a patch jar to override existing Java class files temporarily'>How to use a patch jar to override existing Java class files temporarily</a></li>
<li><a href='http://www.onkarjoshi.com/blog/234/maven-dependency-local-jar-file-from-an-external-third-party-to-be-installed-into-project-repository/' rel='bookmark' title='Maven dependency &#8211; Local jar file from an external third party to be installed into project repository'>Maven dependency &#8211; Local jar file from an external third party to be installed into project repository</a></li>
<li><a href='http://www.onkarjoshi.com/blog/166/identifying-a-thread-with-high-cpu-usage-in-a-java-app/' rel='bookmark' title='Identifying a thread with high CPU usage in a Java app'>Identifying a thread with high CPU usage in a Java app</a></li>
</ol>
</div>
]]></description>
				<content:encoded><![CDATA[<p>One of the less known new features of JDK 6 is the ability to use wildcards in classpaths.</p>
<p>That means that instead of doing&#8230;</p>
<p><span style="color: #0000ff;">java -cp lib\x.jar;lib\y.jar;lib\z.jar; com.company.MyProggy</span></p>
<p>&#8230;you could just do&#8230;</p>
<p><span style="color: #0000ff;">java -cp lib\*.jar; com.company.MyProggy</span></p>
<p>That generally turns out to be quite a time saver. Especially so if you are trying out something at a remote box and <strong>vi </strong>is your only editor.</p>
<p>However, if you use the wild card, there is no way to predict the order in which the jars will be used. In some cases, the order is important &#8211; and in those cases, you will need to add in the jars like one normally does by enumerating each one explicitly.</p>
<p>Also, don&#8217;t forget the semi colon at the end of the classpath. Countless hours have been lost over things not working due to that missing separator. It can be really frustrating!</p>
<div class='yarpp-related-rss'>
<p>Related posts:<ol>
<li><a href='http://www.onkarjoshi.com/blog/133/how-to-use-a-patch-jar-to-override-existing-java-class-files-temporarily/' rel='bookmark' title='How to use a patch jar to override existing Java class files temporarily'>How to use a patch jar to override existing Java class files temporarily</a></li>
<li><a href='http://www.onkarjoshi.com/blog/234/maven-dependency-local-jar-file-from-an-external-third-party-to-be-installed-into-project-repository/' rel='bookmark' title='Maven dependency &#8211; Local jar file from an external third party to be installed into project repository'>Maven dependency &#8211; Local jar file from an external third party to be installed into project repository</a></li>
<li><a href='http://www.onkarjoshi.com/blog/166/identifying-a-thread-with-high-cpu-usage-in-a-java-app/' rel='bookmark' title='Identifying a thread with high CPU usage in a Java app'>Identifying a thread with high CPU usage in a Java app</a></li>
</ol></p>
</div>
<img src="http://feeds.feedburner.com/~r/onkarjoshi/~4/6BTJEjH7SWg" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.onkarjoshi.com/blog/112/wildcard-in-java-classpath/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		<feedburner:origLink>http://www.onkarjoshi.com/blog/112/wildcard-in-java-classpath/</feedburner:origLink></item>
		<item>
		<title>Airtel production database access – Revealed!</title>
		<link>http://feedproxy.google.com/~r/onkarjoshi/~3/w0l6ZiWEu6g/</link>
		<comments>http://www.onkarjoshi.com/blog/109/airtel-production-database-access-revealed/#comments</comments>
		<pubDate>Wed, 17 Feb 2010 19:37:19 +0000</pubDate>
		<dc:creator>Onkar Joshi</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[airtel]]></category>
		<category><![CDATA[bug]]></category>
		<category><![CDATA[Hacking]]></category>
		<category><![CDATA[security]]></category>

		<guid isPermaLink="false">http://www.onkarjoshi.com/blog/?p=109</guid>
		<description><![CDATA[How nice of Airtel (one of the largest telecom service providers in India with a worth of over $10 Billion) to show me the bit of code that was having trouble working when I came to their site to pay my bills. They showed me the full database connection string with the DB server details, [...]<div class='yarpp-related-rss yarpp-related-none'>

No related posts.
</div>
]]></description>
				<content:encoded><![CDATA[<p style="text-align: justify;">How nice of Airtel (one of the largest telecom service providers in India with a worth of over $10 Billion) to show me the bit of code that was having trouble working when I came to their site to pay my bills.</p>
<p>They showed me the full database connection string with the DB server details, IP address and a username and a password. They even let me know where on their server the code for their website was present. Gives a whole new meaning to open source!</p>
<p>Note the following lines in the screen shot below with the stack trace they threw at me -</p>
<ul>
<li style="text-align: justify;"><span style="color: #0000ff;">&#8220;ConStr = &#8220;PROVIDER=SQLOLEDB; DATA SOURCE=X.X.X.X;UID=XXX;PWD=XXX;DATABASE=XXX;network library=dbmssocn;&#8221;</span></li>
<li style="text-align: justify;"><span style="color: #0000ff;">&#8220;D:\Webchutney\AirtelWebsite\Conn.asp&#8221; </span>- It seems WebChutney is a company that has Airtel as one of its clients.</li>
</ul>
<p style="text-align: justify;"><img class="aligncenter size-full wp-image-110" title="airtel-stacktrace" src="http://www.onkarjoshi.com/blog/wp-content/uploads/2010/02/airtel-stacktrace.png" alt="" width="475" height="444" /><br />
Oh well, the IP was of a machine on their internal network so not like anyone could have gained access from outside the network with ease. But when this happens, hackers/crackers generally start sniffing around and probing your network for weak points and generally speaking, that can&#8217;t lead to much good.</p>
<div class='yarpp-related-rss yarpp-related-none'>
<p>No related posts.</p>
</div>
<img src="http://feeds.feedburner.com/~r/onkarjoshi/~4/w0l6ZiWEu6g" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.onkarjoshi.com/blog/109/airtel-production-database-access-revealed/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.onkarjoshi.com/blog/109/airtel-production-database-access-revealed/</feedburner:origLink></item>
	</channel>
</rss>
