<?xml version="1.0" encoding="UTF-8"?>
<!-- generator="wordpress/2.2" -->
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	>

<channel>
	<title>Anand Rajasekar</title>
	<link>http://www.anandsekar.com</link>
	<description>ரெங்கசாமி ஆனந்த் சேகர் ராஜசேகர்</description>
	<pubDate>Thu, 08 May 2008 05:19:33 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.2</generator>
	<language>en</language>
			<item>
		<title>InheritableThreadLocal and Tomcat</title>
		<link>http://www.anandsekar.com/2008/05/08/inheritablethreadlocal-and-tomcat/</link>
		<comments>http://www.anandsekar.com/2008/05/08/inheritablethreadlocal-and-tomcat/#comments</comments>
		<pubDate>Thu, 08 May 2008 05:18:40 +0000</pubDate>
		<dc:creator>anandsekar</dc:creator>
		
		<category><![CDATA[Java]]></category>

		<guid isPermaLink="false">http://www.anandsekar.com/2008/05/08/inheritablethreadlocal-and-tomcat/</guid>
		<description><![CDATA[InheritableThreadLocal does not work with tomcat as tomcat thread pool does not clear the thread local contacts after a request has been executed. This results in no good way to share information information between the parent and the child threads that are created using thread local variables. 
One way to solve this problem is to [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://java.sun.com/j2se/1.4.2/docs/api/java/lang/InheritableThreadLocal.html">InheritableThreadLocal</a> does not work with tomcat as tomcat thread pool does not clear the thread local contacts after a request has been executed. This results in no good way to share information information between the parent and the child threads that are created using thread local variables. </p>
<p>One way to solve this problem is to maintain a reference to the parent thread by writing your own thread that is constructed by a thread factory.</p>
<div class="codesnip-container" >
<div class="codesnip">
<ol>
<li class="li1">
<div class="de1"><span class="kw2">public</span> <span class="kw2">class</span> MyThread <span class="kw2">extends</span> <a href="http://www.google.com/search?q=allinurl%3AThread+java.sun.com&#038;bntl=1"><span class="kw3">Thread</span></a> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">private</span> <a href="http://www.google.com/search?q=allinurl%3AThread+java.sun.com&#038;bntl=1"><span class="kw3">Thread</span></a> parent;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">public</span> MyThread<span class="br0">&#40;</span><a href="http://www.google.com/search?q=allinurl%3AThread+java.sun.com&#038;bntl=1"><span class="kw3">Thread</span></a> parent<span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; super<span class="br0">&#40;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">this</span>.<span class="me1">parent</span> = parent;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">public</span> <a href="http://www.google.com/search?q=allinurl%3AThread+java.sun.com&#038;bntl=1"><span class="kw3">Thread</span></a> getParent<span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">return</span> parent;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span> </div>
</li>
</ol>
</div>
</div>
<div class="codesnip-container" >
<div class="codesnip">
<ol>
<li class="li1">
<div class="de1"><span class="co2">import java.util.concurrent.ThreadFactory;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="kw2">public</span> <span class="kw2">class</span> MyThreadFactory <span class="kw2">implements</span> ThreadFactory <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; @Override</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">public</span> <a href="http://www.google.com/search?q=allinurl%3AThread+java.sun.com&#038;bntl=1"><span class="kw3">Thread</span></a> newThread<span class="br0">&#40;</span><a href="http://www.google.com/search?q=allinurl%3ARunnable+java.sun.com&#038;bntl=1"><span class="kw3">Runnable</span></a> arg0<span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">return</span> <span class="kw2">new</span> MyThread<span class="br0">&#40;</span><a href="http://www.google.com/search?q=allinurl%3AThread+java.sun.com&#038;bntl=1"><span class="kw3">Thread</span></a>.<span class="me1">currentThread</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span> </div>
</li>
</ol>
</div>
</div>
<div class="codesnip-container" >
<div class="codesnip">
<ol>
<li class="li1">
<div class="de1"><span class="co2">import java.util.HashMap;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="co2">import java.util.Map;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="kw2">public</span> <span class="kw2">class</span> ClassNeedingInheritableThreadLocal <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">private</span> <a href="http://www.google.com/search?q=allinurl%3AMap+java.sun.com&#038;bntl=1"><span class="kw3">Map</span></a> inheritableThreadLocal=<span class="kw2">new</span> <a href="http://www.google.com/search?q=allinurl%3AHashMap+java.sun.com&#038;bntl=1"><span class="kw3">HashMap</span></a><span class="br0">&#40;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">public</span> <a href="http://www.google.com/search?q=allinurl%3AObject+java.sun.com&#038;bntl=1"><span class="kw3">Object</span></a> getInheritableThreadContext<span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">return</span> inheritableThreadLocal.<span class="me1">get</span><span class="br0">&#40;</span>getThread<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">public</span> <span class="kw4">void</span> setInheritableThreadContext<span class="br0">&#40;</span><a href="http://www.google.com/search?q=allinurl%3AObject+java.sun.com&#038;bntl=1"><span class="kw3">Object</span></a> context<span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; inheritableThreadLocal.<span class="me1">put</span><span class="br0">&#40;</span>getThread<span class="br0">&#40;</span><span class="br0">&#41;</span>, context<span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">private</span> <a href="http://www.google.com/search?q=allinurl%3AThread+java.sun.com&#038;bntl=1"><span class="kw3">Thread</span></a> getThread<span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.google.com/search?q=allinurl%3AThread+java.sun.com&#038;bntl=1"><span class="kw3">Thread</span></a> currentThread=<a href="http://www.google.com/search?q=allinurl%3AThread+java.sun.com&#038;bntl=1"><span class="kw3">Thread</span></a>.<span class="me1">currentThread</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span><span class="br0">&#40;</span>currentThread instanceof MyThread<span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; currentThread=getParent<span class="br0">&#40;</span><span class="br0">&#40;</span>MyThread<span class="br0">&#41;</span> currentThread<span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">return</span> currentThread;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">public</span> <a href="http://www.google.com/search?q=allinurl%3AThread+java.sun.com&#038;bntl=1"><span class="kw3">Thread</span></a> getParent<span class="br0">&#40;</span>MyThread myThread<span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.google.com/search?q=allinurl%3AThread+java.sun.com&#038;bntl=1"><span class="kw3">Thread</span></a> parent=myThread.<span class="me1">getParent</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span><span class="br0">&#40;</span>parent instanceof MyThread<span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">return</span> getParent<span class="br0">&#40;</span><span class="br0">&#40;</span>MyThread<span class="br0">&#41;</span> parent<span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span> <span class="kw1">else</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">return</span> parent;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span> </div>
</li>
</ol>
</div>
</div>
<p>Create a executor service by using our thread factory</p>
<div class="codesnip-container" >
<div class="codesnip">
<ol>
<li class="li1">
<div class="de1">ExecutorService service=Executors.<span class="me1">newFixedThreadPool</span><span class="br0">&#40;</span><span class="nu0">10</span>, <span class="kw2">new</span> MyThreadFactory<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>; </div>
</li>
</ol>
</div>
</div>
<p>Remember that you would need to clean up all the objects that were put in the thread local. This can be done with a filter or by using AOP.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.anandsekar.com/2008/05/08/inheritablethreadlocal-and-tomcat/feed/</wfw:commentRss>
		</item>
		<item>
		<title>நீயே யென் வாழ்கையின் ஆராதனை</title>
		<link>http://www.anandsekar.com/2007/12/20/49/</link>
		<comments>http://www.anandsekar.com/2007/12/20/49/#comments</comments>
		<pubDate>Thu, 20 Dec 2007 21:18:40 +0000</pubDate>
		<dc:creator>anandsekar</dc:creator>
		
		<category><![CDATA[Poems]]></category>

		<guid isPermaLink="false">http://www.anandsekar.com/2007/12/20/49/</guid>
		<description><![CDATA[

நீ பார்த முதல் ஒளிநான் கேட்டேன் உன் முதல் ஒலி
அரிந்தேன்னே வாழ்கையின் அர்தம்வியந்தேன்னே வாழ்கையின் அதிசயம்சூவைத்தேனே வாழ்கையின் அருமைநீயே யென் வாழ்கையின் ஆராதனை  
]]></description>
			<content:encoded><![CDATA[<div style="text-align: center;">
<div id="o06f" style="padding: 1em 0pt; text-align: center;"><img style="width: 320px; height: 479.85px;" src="http://docs.google.com/File?id=dd98j8jf_35hpc2nqqz"></div>
<p>நீ பார்த முதல் ஒளி<br />நான் கேட்டேன் உன் முதல் ஒலி</p>
<p>அரிந்தேன்னே வாழ்கையின் அர்தம்<br />வியந்தேன்னே வாழ்கையின் அதிசயம்<br />சூவைத்தேனே வாழ்கையின் அருமை<br />நீயே யென் வாழ்கையின் ஆராதனை  </div>
]]></content:encoded>
			<wfw:commentRss>http://www.anandsekar.com/2007/12/20/49/feed/</wfw:commentRss>
		</item>
		<item>
		<title>ஆராதனா</title>
		<link>http://www.anandsekar.com/2007/12/20/48/</link>
		<comments>http://www.anandsekar.com/2007/12/20/48/#comments</comments>
		<pubDate>Thu, 20 Dec 2007 20:53:16 +0000</pubDate>
		<dc:creator>anandsekar</dc:creator>
		
		<category><![CDATA[Poems]]></category>

		<guid isPermaLink="false">http://www.anandsekar.com/2007/12/20/48/</guid>
		<description><![CDATA[                   ஆராதனா ..      நீ கண் சிமிட்டும் நிமிடம்   நீ பால் வேண்டாம் எண்று சொன்னா விதம்   எண் மார்பில் தூங்கும் நேரம்   தேங்கும், தேங்கும், மனதில் தேங்கும்      [...]]]></description>
			<content:encoded><![CDATA[<p><BR> <BR> <DIV STYLE=TEXT-ALIGN:center>   <DIV STYLE="PADDING:1em 0pt; TEXT-ALIGN:center">     <IMG SRC="http://docs.google.com/File?id=dd98j8jf_29jbhhwzgd">   </DIV>   <BR>   <B>ஆராதனா ..</B><BR>   <BR>   நீ கண் சிமிட்டும் நிமிடம்<BR>   நீ பால் வேண்டாம் எண்று சொன்னா விதம்<BR>   எண் மார்பில் தூங்கும் நேரம்<BR>   தேங்கும், தேங்கும், மனதில் தேங்கும்<BR>   <BR>   நீ எண் கண் பார்து சிரித்த நிமிடம்<BR>   நீ தூங்க மாட்டேன் எண்று அழுதா விதம்<BR>   எண் தாலாட்டு பாட்டுக்கு உறங்கும் நேரம்<BR>   தேங்கும், தேங்கும், மனதில் தேங்கும்<BR>   <BR>   இப்படிக்கு<BR>   ஐய்யா<BR>   <BR>   <BR>   <BR>   <BR> </DIV> <BR></p>
]]></content:encoded>
			<wfw:commentRss>http://www.anandsekar.com/2007/12/20/48/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Finding if Multicast is supported</title>
		<link>http://www.anandsekar.com/2007/10/30/finding-if-multicast-is-supported/</link>
		<comments>http://www.anandsekar.com/2007/10/30/finding-if-multicast-is-supported/#comments</comments>
		<pubDate>Tue, 30 Oct 2007 04:09:48 +0000</pubDate>
		<dc:creator>anandsekar</dc:creator>
		
		<category><![CDATA[Linux]]></category>

		<guid isPermaLink="false">http://www.anandsekar.com/2007/10/30/finding-if-multicast-is-supported/</guid>
		<description><![CDATA[One way to easily find if mulitcast is supported in a *nix system is to issue
netstat -gn
which returns the membership groups of the mulitcast addresses in the system
e.g. output
Group Memberships: IPv4
Interface Group                RefCnt
&#8212;&#8212;&#8212; &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211; &#8212;&#8212;
lo0      [...]]]></description>
			<content:encoded><![CDATA[<p>One way to easily find if mulitcast is supported in a *nix system is to issue</p>
<p>netstat -gn</p>
<p>which returns the membership groups of the mulitcast addresses in the system</p>
<p>e.g. output<br />
Group Memberships: IPv4<br />
Interface Group                RefCnt<br />
&#8212;&#8212;&#8212; &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211; &#8212;&#8212;<br />
lo0       224.0.0.75                1<br />
lo0       224.0.0.1                 1<br />
eri0      224.0.0.75                1<br />
eri0      224.0.0.1                 2</p>
]]></content:encoded>
			<wfw:commentRss>http://www.anandsekar.com/2007/10/30/finding-if-multicast-is-supported/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Using Locks for more granular concurrent access</title>
		<link>http://www.anandsekar.com/2007/09/21/using-locks-for-more-granular-concurrent-access/</link>
		<comments>http://www.anandsekar.com/2007/09/21/using-locks-for-more-granular-concurrent-access/#comments</comments>
		<pubDate>Fri, 21 Sep 2007 21:03:02 +0000</pubDate>
		<dc:creator>anandsekar</dc:creator>
		
		<category><![CDATA[Java]]></category>

		<guid isPermaLink="false">http://www.anandsekar.com/2007/09/21/using-locks-for-more-granular-concurrent-access/</guid>
		<description><![CDATA[Locks introduced in Java 5 allow a more granular control on a shared resource. When a method is synchronized only the thread that obtains the lock is allowed to enter into that method or any other synchronized method of the class. However some times we may need a more granular control, typically when we have [...]]]></description>
			<content:encoded><![CDATA[<p>Locks introduced in Java 5 allow a more granular control on a shared resource. When a method is synchronized only the thread that obtains the lock is allowed to enter into that method or any other synchronized method of the class. However some times we may need a more granular control, typically when we have two or more resources we want to share across threads.</p>
<p>e.g.</p>
<div class="codesnip-container" >
<div class="codesnip">
<ol>
<li class="li1">
<div class="de1">package org.<span class="me1">lock</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="kw2">public</span> <span class="kw2">class</span> LockExample <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="kw2">private</span> <span class="kw4">boolean</span> initialized;</div>
</li>
<li class="li1">
<div class="de1"><span class="kw4">int</span> salary=<span class="nu0">0</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="kw2">public</span> <span class="kw4">void</span> increaseSalary<span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="kw1">if</span><span class="br0">&#40;</span>!initialized<span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">initialized=<span class="kw2">true</span>;</div>
</li>
<li class="li1">
<div class="de1">salary=<span class="nu0">1000</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">salary=salary+<span class="nu0">100</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="kw2">public</span> <span class="kw4">void</span> reset<span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">initialized=<span class="kw2">false</span>;</div>
</li>
<li class="li1">
<div class="de1">salary=<span class="nu0">0</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span> </div>
</li>
</ol>
</div>
</div>
<p>In this example we need to synchronize access on the initialization and the reset operations. Also we want to make sure that threads have a serialized access when they increase salary.</p>
<p>This is where we can leverage locks. We define two locks, one for initialization and one for the salary operation.</p>
<div class="codesnip-container" >
<div class="codesnip">
<ol>
<li class="li1">
<div class="de1">package org.<span class="me1">lock</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="co2">import java.util.concurrent.locks.Lock;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="co2">import java.util.concurrent.locks.ReentrantLock;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="kw2">public</span> <span class="kw2">class</span> LockExample <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; Lock initializationLock=<span class="kw2">new</span> ReentrantLock<span class="br0">&#40;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; Lock salaryLock=<span class="kw2">new</span> ReentrantLock<span class="br0">&#40;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">private</span> <span class="kw4">boolean</span> initialized;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw4">int</span> salary=<span class="nu0">0</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; </div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">public</span> <span class="kw4">void</span> increaseSalary<span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span><span class="br0">&#40;</span>!initialized<span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; initializationLock.<span class="me1">lock</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">try</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; initialized=<span class="kw2">true</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; salary=<span class="nu0">1000</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span> <span class="kw2">finally</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; initializationLock.<span class="me1">unlock</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; salaryLock.<span class="me1">lock</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">try</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; salary=salary+<span class="nu0">100</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span> <span class="kw2">finally</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; salaryLock.<span class="me1">unlock</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; </div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">public</span> <span class="kw4">void</span> reset<span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; initializationLock.<span class="me1">lock</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">try</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; initialized=<span class="kw2">false</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; salary=<span class="nu0">0</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span> <span class="kw2">finally</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; initializationLock.<span class="me1">unlock</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span> </div>
</li>
</ol>
</div>
</div>
<p>If you are using Java 1.4 you can utilize temporary synchronization objects to achieve the same result</p>
<div class="codesnip-container" >
<div class="codesnip">
<ol>
<li class="li1">
<div class="de1">package org.<span class="me1">lock</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="kw2">public</span> <span class="kw2">class</span> Lock14Example <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">private</span> <a href="http://www.google.com/search?q=allinurl%3AObject+java.sun.com&#038;bntl=1"><span class="kw3">Object</span></a> initializationLock=<span class="kw2">new</span> <a href="http://www.google.com/search?q=allinurl%3AObject+java.sun.com&#038;bntl=1"><span class="kw3">Object</span></a><span class="br0">&#40;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">private</span> <a href="http://www.google.com/search?q=allinurl%3AObject+java.sun.com&#038;bntl=1"><span class="kw3">Object</span></a> salaryLock=<span class="kw2">new</span> <a href="http://www.google.com/search?q=allinurl%3AObject+java.sun.com&#038;bntl=1"><span class="kw3">Object</span></a><span class="br0">&#40;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">private</span> <span class="kw4">boolean</span> initialized;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw4">int</span> salary=<span class="nu0">0</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; </div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">public</span> <span class="kw4">void</span> increaseSalary<span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span><span class="br0">&#40;</span>!initialized<span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">synchronized</span><span class="br0">&#40;</span>initializationLock<span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; initialized=<span class="kw2">true</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; salary=<span class="nu0">1000</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">synchronized</span><span class="br0">&#40;</span>salaryLock<span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; salary=salary+<span class="nu0">100</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; </div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">public</span> <span class="kw4">void</span> reset<span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">synchronized</span><span class="br0">&#40;</span>initializationLock<span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; initialized=<span class="kw2">false</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; salary=<span class="nu0">0</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span> </div>
</li>
</ol>
</div>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.anandsekar.com/2007/09/21/using-locks-for-more-granular-concurrent-access/feed/</wfw:commentRss>
		</item>
		<item>
		<title>My First Marathon</title>
		<link>http://www.anandsekar.com/2006/11/06/my-first-marathon/</link>
		<comments>http://www.anandsekar.com/2006/11/06/my-first-marathon/#comments</comments>
		<pubDate>Mon, 06 Nov 2006 18:28:35 +0000</pubDate>
		<dc:creator>anandsekar</dc:creator>
		
		<category><![CDATA[Running]]></category>

		<guid isPermaLink="false">http://www.pullaveli.com/?p=11</guid>
		<description><![CDATA[I completed the Silicon Valley Marathon on the 29th October in 5 hours and 7 minutes. Its just an amazing feeling. The last 4 miles was particularly remember able, when every step was a huge effort and the crowd cheering you all the way ! Some runners who had completed the marathon walked back with [...]]]></description>
			<content:encoded><![CDATA[<p>I completed the Silicon Valley Marathon on the 29th October in 5 hours and 7 minutes. Its just an amazing feeling. The last 4 miles was particularly remember able, when every step was a huge effort and the crowd cheering you all the way ! Some runners who had completed the marathon walked back with medals around their neck to cheer on.  It was so refreshing to see Priya on the final turn, joining along to run the last 200m ! Minutes later I had a medal around my neck !</p>
<p><center><img id="image57" src="http://www.anandsekar.com/wp-content/uploads/2006/10/DSCF0203.JPG" alt="Silicon Valley Marathon" height="384" width="288" /></center></p>
<p>I had trained for 4 months running 337 miles during my training. Still remember the last two miles when I swore to myself .. â€œNever a marathon againâ€. Two days later, here I am all charged up for my next marathon ! Finally I am a Marathoner !</p>
]]></content:encoded>
			<wfw:commentRss>http://www.anandsekar.com/2006/11/06/my-first-marathon/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Joining all lines in a file using sed</title>
		<link>http://www.anandsekar.com/2006/10/12/joining-all-lines-in-a-file-using-sed/</link>
		<comments>http://www.anandsekar.com/2006/10/12/joining-all-lines-in-a-file-using-sed/#comments</comments>
		<pubDate>Fri, 13 Oct 2006 06:19:19 +0000</pubDate>
		<dc:creator>anandsekar</dc:creator>
		
		<category><![CDATA[Linux]]></category>

		<guid isPermaLink="false">http://www.pullaveli.com/?p=43</guid>
		<description><![CDATA[Sed (Stream EDitor) is a very powerful stream editor to manipulate text files.
I needed an utility that would join all lines in a text file to a single line with &#8220;\n&#8221; as a separator so that I could easily cut and paste inline velocity templates into java code. Here is the final sed command !
sed [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://en.wikipedia.org/wiki/Sed">Sed</a> (Stream EDitor) is a very powerful stream editor to manipulate text files.<br />
I needed an utility that would join all lines in a text file to a single line with &#8220;\n&#8221; as a separator so that I could easily cut and paste inline velocity templates into java code. Here is the final sed command !</p>
<div class="codesnip-container" >sed -e :a -e &#8216;/$/N; s/\n/\\n/; ta&#8217; [filename]</div>
<p>Explanation :</p>
<div class="codesnip-container" >-e - denotes a command to be executed<br />
:a - is a label<br />
/$/N - defines the scope of the match for the current and the (N)ext line<br />
s/\n/\\n/; - replaces all EOL with &#8220;\n&#8221;<br />
ta; - goto label a if the match is sucessful</div>
]]></content:encoded>
			<wfw:commentRss>http://www.anandsekar.com/2006/10/12/joining-all-lines-in-a-file-using-sed/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Installing Internet Explorer on Linux</title>
		<link>http://www.anandsekar.com/2006/09/29/installing-internet-explorer-on-linux/</link>
		<comments>http://www.anandsekar.com/2006/09/29/installing-internet-explorer-on-linux/#comments</comments>
		<pubDate>Fri, 29 Sep 2006 17:52:19 +0000</pubDate>
		<dc:creator>anandsekar</dc:creator>
		
		<category><![CDATA[Linux]]></category>

		<guid isPermaLink="false">http://www.pullaveli.com/?p=42</guid>
		<description><![CDATA[The easiest way to install IE in linux is to use IEs4Linux. This is a script that would download all required installables from Microsoft and install IE on your linux system. You need have wine and cabextract preinstalled on the linux box.
]]></description>
			<content:encoded><![CDATA[<p>The easiest way to install IE in linux is to use <a href="http://www.tatanka.com.br/ies4linux/page/Main_Page">IEs4Linux</a>. This is a script that would download all required installables from Microsoft and install IE on your linux system. You need have wine and cabextract preinstalled on the linux box.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.anandsekar.com/2006/09/29/installing-internet-explorer-on-linux/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Entrust Certification Chain Validation Error using Java Clients</title>
		<link>http://www.anandsekar.com/2006/08/31/entrust-certification-chain-validation-error-using-java-clients/</link>
		<comments>http://www.anandsekar.com/2006/08/31/entrust-certification-chain-validation-error-using-java-clients/#comments</comments>
		<pubDate>Thu, 31 Aug 2006 17:28:40 +0000</pubDate>
		<dc:creator>anandsekar</dc:creator>
		
		<category><![CDATA[Java]]></category>

		<guid isPermaLink="false">http://www.pullaveli.com/?p=40</guid>
		<description><![CDATA[We were stumped yesterday trying to debug why all java clients trying to connect to a secure site using entrust&#8217;s Secure Server Certificates were throwing a certificate chain validation error. It turned out that the intermediate certificate that we downloaded from entrust had a bad expiration date. To correct this problem download the intermediate certificate [...]]]></description>
			<content:encoded><![CDATA[<p>We were stumped yesterday trying to debug why all java clients trying to connect to a secure site using entrust&#8217;s Secure Server Certificates were throwing a certificate chain validation error. It turned out that the intermediate certificate that we downloaded from entrust had a bad expiration date. To correct this problem download the intermediate certificate again from entrust (they have posted the correct certificate now !) or remove the intermediate certificate from the server. (<a href="http://www.entrust.net/ssl-technical/chaincert_faq.cfm">http://www.entrust.net/ssl-technical/chaincert_faq.cfm</a>)</p>
]]></content:encoded>
			<wfw:commentRss>http://www.anandsekar.com/2006/08/31/entrust-certification-chain-validation-error-using-java-clients/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Why the Linux file system does not need defragmenting &#8230;</title>
		<link>http://www.anandsekar.com/2006/08/19/why-the-linux-file-system-does-not-need-defragmenting/</link>
		<comments>http://www.anandsekar.com/2006/08/19/why-the-linux-file-system-does-not-need-defragmenting/#comments</comments>
		<pubDate>Sat, 19 Aug 2006 17:58:37 +0000</pubDate>
		<dc:creator>anandsekar</dc:creator>
		
		<category><![CDATA[Linux]]></category>

		<guid isPermaLink="false">http://www.pullaveli.com/?p=39</guid>
		<description><![CDATA[I came across this excellant article explaining in simple ways why the linux file system does not need to be defragmented. Read On ..
]]></description>
			<content:encoded><![CDATA[<p>I came across this excellant article explaining in simple ways why the linux file system does not need to be defragmented. <a href="http://geekblog.oneandoneis2.org/index.php/2006/08/17/why_doesn_t_linux_need_defragmenting">Read On ..</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.anandsekar.com/2006/08/19/why-the-linux-file-system-does-not-need-defragmenting/feed/</wfw:commentRss>
		</item>
	</channel>
</rss>
