<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Parolski.com &#187; computing</title>
	<atom:link href="http://www.parolski.com/category/computing/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.parolski.com</link>
	<description>Faith, Solaris, and Chicken Korma, by Anton Parol</description>
	<lastBuildDate>Mon, 26 Jul 2010 20:34:17 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>New Sun/Oracle hardware</title>
		<link>http://www.parolski.com/2010/06/29/new-sunoracle-hardware/</link>
		<comments>http://www.parolski.com/2010/06/29/new-sunoracle-hardware/#comments</comments>
		<pubDate>Tue, 29 Jun 2010 19:50:23 +0000</pubDate>
		<dc:creator>Anton Parol</dc:creator>
				<category><![CDATA[computing]]></category>

		<guid isPermaLink="false">http://www.parolski.com/?p=346</guid>
		<description><![CDATA[Well, its a while now but new hardware has been anounced and it really is quite impressive! Key Stats Theres more than the list that I&#8217;m showing, but theses are the most interesting ones. Among other bits are the X4170, X6270 and some new NEMS for the SunBlade 6000 chasis. X4800 5 Rack Units high [...]]]></description>
			<content:encoded><![CDATA[<p>Well, its a while now but new hardware has been anounced and it really is quite impressive!</p>
<h1>Key Stats</h1>
<p>Theres more than the list that I&#8217;m showing, but theses are the most interesting ones. Among other bits are the X4170, X6270 and some new NEMS for the SunBlade 6000 chasis.</p>
<h2><a href="http://www.oracle.com/us/products/servers-storage/servers/x86/sun-fire-x4800-server-077287.html">X4800</a></h2>
<h2><a href="http://www.parolski.com/wp-content/uploads/2010/06/4800.serendipityThumb.png"><img class="size-full wp-image-347 alignnone" title="4800.serendipityThumb" src="http://www.parolski.com/wp-content/uploads/2010/06/4800.serendipityThumb.png" alt="" width="400" height="193" /></a></h2>
<ul>
<li>5 Rack Units high</li>
<li>1 TB of RAM (With 8GB DIMMS, 128 slots)</li>
<li>4 or 8 * Xeon 7600 CPUS (each with 8 cores)</li>
<li>8 PCIe slots</li>
<li>Up to 8 * 300GB   2.5 inch SAS-2 disks</li>
<li>Two NEMS, each with four 10Gb Ethernet ports</li>
<li>Redundant power supplies</li>
</ul>
<h2><a href="http://www.oracle.com/us/products/servers-storage/servers/x86/sun-fire-x4470-server-077286.html">X4470</a></h2>
<p><a href="http://www.parolski.com/wp-content/uploads/2010/06/x4470.serendipityThumb.png"><img class="size-full wp-image-348 alignnone" title="x4470.serendipityThumb" src="http://www.parolski.com/wp-content/uploads/2010/06/x4470.serendipityThumb.png" alt="" width="400" height="172" /></a></p>
<ul>
<li>3 Rack Units high</li>
<li>512 GB RAM (with 8GB DIMMS, 64 slots)</li>
<li>2 or 4 Xeon 7500 series CPUS (each 8 cores)</li>
<li>10 PCIe slots</li>
<li>Up to 6 * 300GB 2.5 inch SAS-2 disks</li>
<li>Redundant power supplies</li>
</ul>
<h2><a href="http://www.oracle.com/us/products/servers-storage/servers/x86/sun-fire-x4170-m2-server-077278.html">X4170M2</a> / <a href="http://www.oracle.com/us/products/servers-storage/servers/x86/sun-fire-x4270-m2-server-077279.html">X4270 M2</a></h2>
<p><a href="http://www.parolski.com/wp-content/uploads/2010/06/4270.serendipityThumb.png"><img class="size-full wp-image-349 alignnone" title="4270.serendipityThumb" src="http://www.parolski.com/wp-content/uploads/2010/06/4270.serendipityThumb.png" alt="" width="399" height="174" /></a></p>
<ul>
<li>1 and 2 Rack units respectively</li>
<li>Up to 12 * 300GB SAS-2 2.5 inch , or up to 24 * 300GB SAS-2 2.5 inch disks</li>
<li>2 CPUs each</li>
<li>144GB RAM each</li>
<li>4 Gb Ethernet onboard each</li>
</ul>
<p>These images were shamlesly copied from <a href="www.c0t0d0s0.org">www.c0t0d0s0.org</a>, who also <a href="http://www.c0t0d0s0.org/archives/6679-Newly-announced-x86-products.html#extended">wrote a far better</a> artcile than I did!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.parolski.com/2010/06/29/new-sunoracle-hardware/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Google chrome benchmarked</title>
		<link>http://www.parolski.com/2010/05/08/google-chrome-benchmarked/</link>
		<comments>http://www.parolski.com/2010/05/08/google-chrome-benchmarked/#comments</comments>
		<pubDate>Sat, 08 May 2010 19:00:11 +0000</pubDate>
		<dc:creator>Anton Parol</dc:creator>
				<category><![CDATA[computing]]></category>
		<category><![CDATA[benchmark]]></category>
		<category><![CDATA[google chrome]]></category>

		<guid isPermaLink="false">http://www.parolski.com/?p=339</guid>
		<description><![CDATA[Well, it appears that google chrome is faster than alot of things. Namely: Potatoes fired from a cannon Paint shot by sound wave energy Lightning striking a little ship (big ships untested) All is explained and proved in the following little video. Credit to the editor of this filming, but I do have to say, [...]]]></description>
			<content:encoded><![CDATA[<p>Well, it appears that google chrome is faster than alot of things. Namely:</p>
<ol>
<li>Potatoes fired from a cannon</li>
<li>Paint shot by sound wave energy</li>
<li>Lightning striking a little ship (big ships untested)</li>
</ol>
<p>All is explained and proved in the following little video. Credit to the editor of this filming, but I do have to say, the final test doesn&#8217;t look 100% fair, the mouse may have been clicked a split second too soon.</p>
<p><object width="1280" height="745"><param name="movie" value="http://www.youtube.com/v/nCgQDjiotG0&#038;hl=en_GB&#038;fs=1&#038;rel=0"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/nCgQDjiotG0&#038;hl=en_GB&#038;fs=1&#038;rel=0" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="480" height="385"></embed></object></p>
]]></content:encoded>
			<wfw:commentRss>http://www.parolski.com/2010/05/08/google-chrome-benchmarked/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The under appreciated bourne shell &#8220;:&#8221; operator</title>
		<link>http://www.parolski.com/2010/04/27/the-under-appreciated-bourne-shell-operator/</link>
		<comments>http://www.parolski.com/2010/04/27/the-under-appreciated-bourne-shell-operator/#comments</comments>
		<pubDate>Tue, 27 Apr 2010 18:59:20 +0000</pubDate>
		<dc:creator>Anton Parol</dc:creator>
				<category><![CDATA[computing]]></category>
		<category><![CDATA[:]]></category>
		<category><![CDATA[bourne shell]]></category>
		<category><![CDATA[operator]]></category>
		<category><![CDATA[scripting]]></category>
		<category><![CDATA[shell]]></category>
		<category><![CDATA[shell scripts]]></category>

		<guid isPermaLink="false">http://www.parolski.com/?p=329</guid>
		<description><![CDATA[&#8220;:&#8221; is a little known Bourne Shell operator which is actually quite handy. However, like a alot of other short hand operators, its easy to forget, especially when its not used that much. So what can it do? You can replace the true command with it, letting you write something like: while : do some_commands [...]]]></description>
			<content:encoded><![CDATA[<p>&#8220;:&#8221; is a little known Bourne Shell operator which is actually quite handy. However, like a alot of other short hand operators, its easy to forget, especially when its not used that much.</p>
<p>So what can it do?</p>
<ul>
<li>You can replace the <em>true</em> command with it, letting you write something like:</li>
</ul>
<p><code> while :<br />
do<br />
some_commands<br />
done<br />
</code></p>
<ul>
<li>Leave the then part of an if statement empty:</li>
</ul>
<p><code>if :<br />
then :<br />
else :<br />
fi</code></p>
<p>I agree, that example is probably useless for now, but amusing none the less.</p>
<p>So there you are! Next time you fancy steering from the norm of using true, you know what to do!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.parolski.com/2010/04/27/the-under-appreciated-bourne-shell-operator/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Larry&#8217;s ship</title>
		<link>http://www.parolski.com/2010/01/29/larrys-ship/</link>
		<comments>http://www.parolski.com/2010/01/29/larrys-ship/#comments</comments>
		<pubDate>Fri, 29 Jan 2010 14:19:38 +0000</pubDate>
		<dc:creator>Anton Parol</dc:creator>
				<category><![CDATA[computing]]></category>
		<category><![CDATA[Ellision]]></category>
		<category><![CDATA[larry]]></category>
		<category><![CDATA[presentation]]></category>
		<category><![CDATA[SPARC]]></category>
		<category><![CDATA[sun]]></category>
		<category><![CDATA[T1000]]></category>

		<guid isPermaLink="false">http://www.parolski.com/?p=299</guid>
		<description><![CDATA[Oracle recently made a set of presentations which outlined what their strategy was in terms of hardware, software, markets etc.. Each speaker had a slide show to accompany their talks, and each of the slideshows was quite extensive. Speaker Webcast Presentation Charles Phillips: Welcome and Oracle + Sun: Transforming the Industry Webcast (43 min.) presentation [...]]]></description>
			<content:encoded><![CDATA[<p>Oracle recently made a set of presentations which outlined what their strategy was in terms of hardware, software, markets etc.. Each speaker had a slide show to accompany their talks, and each of the slideshows was quite extensive.</p>
<table style="height: 319px;" border="0" cellspacing="0" cellpadding="0" width="433">
<tbody>
<tr>
<td></td>
<p><!-- Edit Section Header Here --></tr>
<tr>
<td width="3"></td>
<td><!-- Begin Section Content--> <!-- START TABLE --></p>
<table style="height: 259px;" border="0" cellspacing="1" cellpadding="3" width="431">
<tbody>
<tr valign="top">
<td width="40%">Speaker</td>
<td width="30%">Webcast</td>
<td width="30%">Presentation</td>
</tr>
<tr valign="top">
<td>Charles Phillips: Welcome and Oracle + Sun: Transforming the Industry</td>
<td><a href="http://oracle.com.edgesuite.net/ivt/4000/8104/9238/12641/lobby_external_flash_clean_480x360/default.htm" target="_blank">Webcast</a> (43 min.)</td>
<td><a href="http://www.oracle.com/ocom/groups/public/@ocom/documents/webcontent/044516.pdf" target="_blank">presentation</a> (PDF)</td>
</tr>
<tr valign="top">
<td>John Fowler: Hardware Strategy</td>
<td><a href="http://oracle.com.edgesuite.net/ivt/4000/8104/9238/12643/lobby_external_flash_clean_480x360/default.htm" target="_blank">Webcast</a> (39 min.)</td>
<td><a href="http://www.oracle.com/ocom/groups/public/@ocom/documents/webcontent/044518.pdf" target="_blank">presentation</a> (PDF)</td>
</tr>
<tr valign="top">
<td>Thomas Kurian: Software Strategy</td>
<td><a href="http://oracle.com.edgesuite.net/ivt/4000/8104/9238/12644/lobby_external_flash_clean_480x360/default.htm" target="_blank">Webcast</a> (48 min.)</td>
<td><a href="http://www.oracle.com/ocom/groups/public/@ocom/documents/webcontent/044523.pdf" target="_blank">presentation</a> (PDF)</td>
</tr>
<tr valign="top">
<td>Edward Screven: Operating Systems and Virtualization</td>
<td><a href="http://oracle.com.edgesuite.net/ivt/4000/8104/9238/12661/lobby_external_flash_clean_480x360/default.htm" target="_blank">Webcast</a> (19 min.)</td>
<td><a href="http://www.oracle.com/ocom/groups/public/@ocom/documents/webcontent/044521.pdf" target="_blank">presentation</a> (PDF)</td>
</tr>
<tr valign="top">
<td>Juergen Rottler: Customer Service and Support Strategy</td>
<td><a href="http://oracle.com.edgesuite.net/ivt/4000/8104/9238/12655/lobby_external_flash_clean_480x360/default.htm" target="_blank">Webcast</a> (23 min.)</td>
<td><a href="http://www.oracle.com/ocom/groups/public/@ocom/documents/webcontent/044522.pdf" target="_blank">presentation</a> (PDF)</td>
</tr>
<tr valign="top">
<td>Jeff Epstein: Operational Strategy</td>
<td><a href="http://oracle.com.edgesuite.net/ivt/4000/8104/9238/12659/lobby_external_flash_clean_480x360/default.htm" target="_blank">Webcast</a> (8 min.)</td>
<td><a href="http://www.oracle.com/ocom/groups/public/@ocom/documents/webcontent/044524.pdf" target="_blank">presentation</a> (PDF)</td>
</tr>
<tr valign="top">
<td>Larry Ellison: Oracle + Sun</td>
<td><a href="http://oracle.com.edgesuite.net/ivt/4000/8104/9238/12652/lobby_external_flash_clean_480x360/default.htm" target="_blank">Webcast</a> (59 min.)</td>
<td><a href="http://www.oracle.com/ocom/groups/public/@ocom/documents/webcontent/044515.pdf" target="_blank">presentation</a> (PDF)</td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
<p>Well, all but one. Larry&#8217;s!</p>
<p>His slideshow has one slide; a picture of a racing yacht with Oracle and Sun logos on it! This for me sums up his character. Hes got a ton of energy and sees his company more like something that he needs to guide and be successful with, and at the same time looks good whilst doing it!</p>
<p>In this respect, Oracle have made it very clear what they want to do with the portfolio they have acquired from Sun, and this does include investing heavily in SPARC processors. Given the kind of performance we saw with the T1000 on <a href="http://www.stdlib.net/~colmmacc/2006/03/23/niagara-vs-ftpheanetie-showdown/">Heanets</a> review, I&#8217;m personally looking forward to the day when Oracle manage to further commoditise this cool hardware <img src='http://www.parolski.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.parolski.com/2010/01/29/larrys-ship/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Star7 PDA Prototype</title>
		<link>http://www.parolski.com/2010/01/25/star7-pda-prototype/</link>
		<comments>http://www.parolski.com/2010/01/25/star7-pda-prototype/#comments</comments>
		<pubDate>Mon, 25 Jan 2010 19:45:39 +0000</pubDate>
		<dc:creator>Anton Parol</dc:creator>
				<category><![CDATA[computing]]></category>
		<category><![CDATA[prototype]]></category>
		<category><![CDATA[Star7 PDA]]></category>

		<guid isPermaLink="false">http://www.parolski.com/?p=291</guid>
		<description><![CDATA[This little box seems to be quite far ahead of its time. I can imagine that there must be so many futurologist out there just waiting to see their ideas come into the mainstream, and then jump for joy when it finally does!]]></description>
			<content:encoded><![CDATA[<p><object width="425" height="344"><param name="movie" value="http://www.youtube.com/v/Ahg8OBYixL0&#038;color1=0xb1b1b1&#038;color2=0xcfcfcf&#038;hl=en_US&#038;feature=player_embedded&#038;fs=1"></param><param name="allowFullScreen" value="true"></param><param name="allowScriptAccess" value="always"></param><embed src="http://www.youtube.com/v/Ahg8OBYixL0&#038;color1=0xb1b1b1&#038;color2=0xcfcfcf&#038;hl=en_US&#038;feature=player_embedded&#038;fs=1" type="application/x-shockwave-flash" allowfullscreen="true" allowScriptAccess="always" width="425" height="344"></embed></object><br />
<br />
This little box seems to be quite far ahead of its time. I can imagine that there must be so many futurologist out there just waiting to see their ideas come into the mainstream, and then jump for joy when it finally does!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.parolski.com/2010/01/25/star7-pda-prototype/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Future could be brighter for Sun as it merges with Oracle</title>
		<link>http://www.parolski.com/2010/01/21/future-could-be-brighter-for-sun-as-it-merges-with-oracle/</link>
		<comments>http://www.parolski.com/2010/01/21/future-could-be-brighter-for-sun-as-it-merges-with-oracle/#comments</comments>
		<pubDate>Thu, 21 Jan 2010 17:53:17 +0000</pubDate>
		<dc:creator>Anton Parol</dc:creator>
				<category><![CDATA[computing]]></category>
		<category><![CDATA[oracle]]></category>
		<category><![CDATA[Sun Microsystems]]></category>

		<guid isPermaLink="false">http://www.parolski.com/?p=286</guid>
		<description><![CDATA[It has been announced today that approval has finally been given for Oracle to merge with Sun Microsystems. The process began in September 2009 which means that its been long enough for plenty of rumours to go around about whats going to happen both internally with head count cuts, and of course with the product [...]]]></description>
			<content:encoded><![CDATA[<p>It has been <a href="http://europa.eu/rapid/pressReleasesAction.do?reference=IP/10/40&amp;format=HTML&amp;aged=0&amp;language=EN&amp;guiLanguage=en">announced</a> <a href="http://www.oracle.com/us/corporate/press/043821">today</a> that approval has finally been given for Oracle to merge with Sun Microsystems. The process began in September 2009 which means that its been long enough for plenty of rumours to go around about whats going to happen both internally with head count cuts, and of course with the product line itself. Most importantly, the people with power to make decisions in these two structures now actually have the opportunity to go ahead and make those decisions.</p>
<p>If Larry is<a href="http://www.youtube.com/watch?v=yrEPTeTzg6M"> true to his word</a> about what he sees for the future of the Sun product line, I for one would certainly say that the future is going to be fairly bright.</p>
<p>Mr Ellisons (CEO of Oracle) own words:</p>
<p>&#8220;We are keeping everything. We are keeping tape, we are keeping storage, we are keeping x86 technology, we&#8217;re keeping SPARC technology, we&#8217;re going to increase the investment in it&#8230;&#8221;</p>
<p>&#8220;&#8230;we are NOT going to spin anything off.&#8221;</p>
<p>The discussions about improving data center power consumption efficiency and increasing demand for online services place the <a href="http://www.sun.com/servers/finder/index.xml?cat=all&amp;dd1c4045-54db-11dd-9496-080020a9ed93=ultrasparct2plus">T-series</a> equipment very well for those who know just how good they are. Coupled with the fact that Sun had famously invested early in the R+D for this kind of technology, theres also a great opportunity to get <a href="www.opensolaris.com">OpenSolaris</a> beefed up in terms of packages and installers, and deployed in these environments.</p>
<p>I&#8217;m looking forward to seeing how its all going to pan out!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.parolski.com/2010/01/21/future-could-be-brighter-for-sun-as-it-merges-with-oracle/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>python&#8217;s HTTP server</title>
		<link>http://www.parolski.com/2009/09/26/pythons-http-server/</link>
		<comments>http://www.parolski.com/2009/09/26/pythons-http-server/#comments</comments>
		<pubDate>Fri, 25 Sep 2009 23:44:30 +0000</pubDate>
		<dc:creator>Anton Parol</dc:creator>
				<category><![CDATA[computing]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[http]]></category>
		<category><![CDATA[localhost]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[solaris]]></category>
		<category><![CDATA[source]]></category>

		<guid isPermaLink="false">http://www.parolski.com/?p=268</guid>
		<description><![CDATA[Python comes with an HTTP server built in, making sharing directories on your *nix machines as easy as: anton@opensolaris:~/mess/test$ python -m SimpleHTTPServer Serving HTTP on 0.0.0.0 port 8000 &#8230; localhost &#8211; - [26/Sep/2009 00:23:47] &#8220;GET / HTTP/1.0&#8243; 200 - localhost &#8211; - [26/Sep/2009 00:24:24] &#8220;GET / HTTP/1.1&#8243; 200 - So now when we go to [...]]]></description>
			<content:encoded><![CDATA[<p>Python comes with an HTTP server built in, making sharing directories on your *nix machines as easy as:</p>
<blockquote><p>anton@opensolaris:~/mess/test$ python -m SimpleHTTPServer<br />
Serving HTTP on 0.0.0.0 port 8000 &#8230;<br />
localhost &#8211; - [26/Sep/2009 00:23:47] &#8220;GET / HTTP/1.0&#8243; 200 -<br />
localhost &#8211; - [26/Sep/2009 00:24:24] &#8220;GET / HTTP/1.1&#8243; 200 -</p></blockquote>
<p>So now when we go to localhost:8000 , we get the directory!:</p>
<blockquote><p>anton@opensolaris:~/mess$ lynx -dump localhost:8000<br />
Directory listing for /<br />
__________________________________________________________________</p>
<p>* [1]lalala<br />
__________________________________________________________________</p>
<p>References</p>
<p>1. http://localhost:8000/lalala</p></blockquote>
<p>&#8230;or&#8230;</p>
<blockquote><p>anton@opensolaris:~$ lynx -source localhost:8000<br />
&lt;title&gt;Directory listing for /&lt;/title&gt;<br />
&lt;h2&gt;Directory listing for /&lt;/h2&gt;<br />
&lt;hr&gt;<br />
&lt;ul&gt;<br />
&lt;li&gt;&lt;a href=&#8221;lalala&#8221;&gt;lalala&lt;/a&gt;<br />
&lt;/ul&gt;<br />
&lt;hr&gt;</p></blockquote>
<p>&#8230;for those of you that want to see the source it produced! A very quick short term solution if you don&#8217;t want to go about setting up apache or change your apache settings!</p>
<blockquote><p><img src="file:///tmp/moz-screenshot.png" alt="" /></p></blockquote>
]]></content:encoded>
			<wfw:commentRss>http://www.parolski.com/2009/09/26/pythons-http-server/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Half a half: Part 2</title>
		<link>http://www.parolski.com/2008/12/13/half-a-half-part-2/</link>
		<comments>http://www.parolski.com/2008/12/13/half-a-half-part-2/#comments</comments>
		<pubDate>Sat, 13 Dec 2008 21:12:26 +0000</pubDate>
		<dc:creator>Anton Parol</dc:creator>
				<category><![CDATA[computing]]></category>
		<category><![CDATA[BigDecimal]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[problem]]></category>

		<guid isPermaLink="false">http://www.parolski.com/?p=158</guid>
		<description><![CDATA[Ten days ago we had a look at Java&#8217;s ability to deal with numbers which had alot of decimal places. Liam pointed out that having to loop through a variety of operations is longer than performing a more efficient operation once. With Liams magical formula, we get the following Java, with no loop: 1 2 [...]]]></description>
			<content:encoded><![CDATA[<p>Ten days ago we had a look at Java&#8217;s ability to deal with numbers which had alot of decimal places. Liam pointed out that having to loop through a variety of operations is longer than performing a more efficient operation once.</p>
<p>With Liams magical formula, we get the following Java, with no loop:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
</pre></td><td class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.math.BigDecimal</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> The_proper_half <span style="color: #009900;">&#123;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #003399;">Integer</span> times_to_loop<span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #008000; font-style: italic; font-weight: bold;">/**
     * @param args the number of times you want to run the loop
     */</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000066; font-weight: bold;">void</span> main<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> args<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        calculate<span style="color: #009900;">&#40;</span><span style="color: #003399;">Integer</span>.<span style="color: #006633;">valueOf</span><span style="color: #009900;">&#40;</span>args<span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000066; font-weight: bold;">void</span> calculate<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> times_to_loop<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #666666; font-style: italic;">//The Number we want to half</span>
        <span style="color: #003399;">BigDecimal</span> number_to_half <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">BigDecimal</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;10&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #666666; font-style: italic;">//The result of doing the half</span>
        <span style="color: #003399;">BigDecimal</span> the_half <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">BigDecimal</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;0&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #666666; font-style: italic;">//The number we want to divide by</span>
        <span style="color: #003399;">BigDecimal</span> divider <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">BigDecimal</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;2&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        the_half <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>number_to_half.<span style="color: #006633;">divide</span><span style="color: #009900;">&#40;</span>divider.<span style="color: #006633;">pow</span><span style="color: #009900;">&#40;</span>times_to_loop<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;The last number has &quot;</span> <span style="color: #339933;">+</span>
                <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #003399;">Integer</span><span style="color: #009900;">&#41;</span> number_to_half.<span style="color: #006633;">subtract</span><span style="color: #009900;">&#40;</span>the_half<span style="color: #009900;">&#41;</span>.<span style="color: #006633;">toString</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">length</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
                <span style="color: #339933;">-</span> <span style="color: #cc66cc;">2</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #0000ff;">&quot; decimal places: &quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span>number_to_half.<span style="color: #006633;">subtract</span><span style="color: #009900;">&#40;</span>the_half<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>As you can see, we only perform the opertation once (line 23), but admitadly, to get the correct number at the end, we still do the subtraction at the end!</p>
<p>Regarding optimisation, there are huge benefits. It turns out that the old way if hugely costly for thousands of iterations. These are the results for 10000 iterations, the old way:</p>
<pre>anton@anton-laptop classes $ time java Half_of_a_half 10000 &gt; /dev/null

real    5m22.714s
user    5m21.320s
sys    0m1.052s</pre>
<p>The results for the new way are much better:</p>
<pre>anton@anton-laptop classes $ time java The_proper_half 10000 &gt; /dev/null

real    0m1.019s
user    0m1.248s
sys    0m0.052s</pre>
<p>So it went from over five minutes, down to just a second. That was just by changing from a loop a single statement. Thats pretty cool stuff!</p>
<p>I have to admit here, the difficult bit is probably not the code. Its the abillity to see how a problem may be translated from one way of expressing it to another. Its that bit of genius thats really done the work here. Credit to Liam for the genius!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.parolski.com/2008/12/13/half-a-half-part-2/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Half a number, half it again and add it to the first half.</title>
		<link>http://www.parolski.com/2008/12/03/half-a-number-half-it-again-and-add-it-to-the-first-half/</link>
		<comments>http://www.parolski.com/2008/12/03/half-a-number-half-it-again-and-add-it-to-the-first-half/#comments</comments>
		<pubDate>Wed, 03 Dec 2008 20:37:17 +0000</pubDate>
		<dc:creator>Anton Parol</dc:creator>
				<category><![CDATA[computing]]></category>
		<category><![CDATA[BigDecimal]]></category>
		<category><![CDATA[java]]></category>

		<guid isPermaLink="false">http://www.parolski.com/?p=136</guid>
		<description><![CDATA[This is a common riddle, so if you&#8217;ve heard it, don&#8217;t shout out the answer (people might think your strange for shouting at the internet&#8230;.) Take a number. Then, half that number. Then half that half and add it to the first half. Before that gives people a headache, lets do a little example: Lets [...]]]></description>
			<content:encoded><![CDATA[<p>This is a common riddle, so if you&#8217;ve heard it, don&#8217;t shout out the answer (people might think your strange for shouting at the internet&#8230;.)</p>
<p>Take a number. Then, half that number. Then half that half and add it to the first half. Before that gives people a headache, lets do a little example:</p>
<p>Lets use 10 . Then half of ten gives us 5. Then, half five (2.5) and add it to the first half, 5. This gives us 7.5</p>
<p>Continue to half the last half, adding it to the sum of the previous halves. Phew, I hope thats explained properly.i.e. half two point five, and add it the the 7.5 we already have, which give us 8.25</p>
<p>Okay, so the question is this. If we keeping adding on the halves, will we ever reach 10 again? Well, I like Java, so lets get all geeky and model the problem. For this, the double and float data types won&#8217;t give us enough decimal places. For this, we&#8217;ll need: math.BigDecimal . The Big Decimal. Sounds ominous!</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
</pre></td><td class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.math.BigDecimal</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> Half_of_a_half <span style="color: #009900;">&#123;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #003399;">Integer</span> times_to_loop<span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #008000; font-style: italic; font-weight: bold;">/**
     * @param args the number of times you want to run the loop
     */</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000066; font-weight: bold;">void</span> main<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> args<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        calculate<span style="color: #009900;">&#40;</span><span style="color: #003399;">Integer</span>.<span style="color: #006633;">valueOf</span><span style="color: #009900;">&#40;</span>args<span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000066; font-weight: bold;">void</span> calculate<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> times_to_loop<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #666666; font-style: italic;">//The Number we want to half</span>
        <span style="color: #003399;">BigDecimal</span> number_to_half <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">BigDecimal</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;10&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #666666; font-style: italic;">//The result of doing the half</span>
        <span style="color: #003399;">BigDecimal</span> the_half <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">BigDecimal</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;0&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #666666; font-style: italic;">//The number we want to divide by</span>
        <span style="color: #003399;">BigDecimal</span> divider <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">BigDecimal</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;2&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #000000; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> i <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> i <span style="color: #339933;">&amp;</span>lt<span style="color: #339933;">;</span> times_to_loop<span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
            number_to_half <span style="color: #339933;">=</span> number_to_half.<span style="color: #006633;">divide</span><span style="color: #009900;">&#40;</span>divider<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            the_half <span style="color: #339933;">=</span> the_half.<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span>number_to_half<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
            <span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span>the_half<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
        <span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;The last number has &quot;</span> <span style="color: #339933;">+</span>
                <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #003399;">Integer</span><span style="color: #009900;">&#41;</span> the_half.<span style="color: #006633;">toString</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">length</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">-</span> <span style="color: #cc66cc;">2</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #0000ff;">&quot; decimal places&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>This code takes a single parameter on the command line: the number of times to half by</p>
<p>e.g.<br />
<code><br />
anton@anton-laptop classes $ java Half_of_a_half 10<br />
5<br />
7.5<br />
8.75<br />
9.375<br />
9.6875<br />
9.84375<br />
9.921875<br />
9.9609375<br />
9.98046875<br />
9.990234375<br />
The last number has 9 decimal places<br />
</code><br />
So as we can see, the decimal places just get long and longer. The additions are never big enough to get us close enough to the original number. Problem solved!</p>
<p>The fun bit is realising the significance of the calculation, or rather, the speed with which it was done. Performing 1000 divisions and additions takes less that 0.2 of a second! Maybe thats not so fast by todays computing ability, but by human standards thats pretty extreme.<br />
<code><br />
anton@anton-laptop classes $ time java Half_of_a_half 1000 &gt; /dev/null<br />
</code><br />
<code><br />
real    0m1.387s<br />
user    0m1.916s<br />
sys    0m0.036s<br />
</code></p>
]]></content:encoded>
			<wfw:commentRss>http://www.parolski.com/2008/12/03/half-a-number-half-it-again-and-add-it-to-the-first-half/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Using synchronized methods in java</title>
		<link>http://www.parolski.com/2008/10/04/using-synchronized-methods-in-java/</link>
		<comments>http://www.parolski.com/2008/10/04/using-synchronized-methods-in-java/#comments</comments>
		<pubDate>Sat, 04 Oct 2008 21:14:07 +0000</pubDate>
		<dc:creator>Anton Parol</dc:creator>
				<category><![CDATA[computing]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[synchronized methods]]></category>
		<category><![CDATA[threads]]></category>

		<guid isPermaLink="false">http://www.parolski.com/?p=116</guid>
		<description><![CDATA[This post has long code segments in it, so I&#8217;ll explain what it all does at the top. Then at the end, just copy paste into your favourite editor/IDE to play with it. So the title kind of gives it away, but the concept behind it was quite interesting. Imagine you have some kind of [...]]]></description>
			<content:encoded><![CDATA[<p>This post has long code segments in it, so I&#8217;ll explain what it all does at the top. Then at the end, just copy paste into your favourite editor/IDE to play with it.</p>
<p>So the title kind of gives it away, but the concept behind it was quite interesting. Imagine you have some kind of resource, like a network connection, a file etc, which is needs to be accessed by many threads, but only one thread at a time. Using<a href="http://java.sun.com/docs/books/tutorial/essential/concurrency/syncmeth.html"> synchronized methods</a> achieves this. Its especially handy where you might have hundreds of threads which need to modify the same resource, but should do it, one at a time. This code can do that (although its not perfect by far)</p>
<p>In this example, we have a padlock, which we can open , and close. Of course, we can&#8217;t open it whilst its being closed, and vica versa. You could just run the openLock and closeLock methods one after the other, but using threads gives us some bonus features. For example, we might want to open the padlock, get half way through, and then realise we want to pause, leaving the rest of the work for later. Or maybe we want to get halfway through closing the padlock, and then change our mind and open it (i.e. without fully closing it)</p>
<p>So heres the code, enjoy!<br />
The padlock:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
</pre></td><td class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">workingWithSynchronizedThreads</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.util.logging.Level</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.util.logging.Logger</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #008000; font-style: italic; font-weight: bold;">/**
 * This class represents a simple padlock. You know, like the kind you use to
 * lock up your bike. I use it as an example of how we can make fields in
 * java , then try and access them through different threads. Using syncronised
 * methods, we will prevent the lock from being opened whilst were still trying
 * to close it.
 * @author anton
 */</span>
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> padlock <span style="color: #009900;">&#123;</span>
&nbsp;
    <span style="color: #008000; font-style: italic; font-weight: bold;">/**
     * Constructor object to make a new padlock
     * @param isThePadlockOpen Whether the padlock is open or closed
     */</span>
    <span style="color: #000000; font-weight: bold;">public</span> padlock<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">boolean</span> isThePadlockOpen<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">isThePadlockOpen</span> <span style="color: #339933;">=</span> isThePadlockOpen<span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #008000; font-style: italic; font-weight: bold;">/**
     * This field tells us whether or not the lock is open or closed (true for
     * open, false for locked)
     */</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">boolean</span> isThePadlockOpen<span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #008000; font-style: italic; font-weight: bold;">/**
     * This method simply sets the padlock to be closed by setting isOpen to false
     * Closing the lock takes two seconds (hence the sleep statements) ).
     */</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">synchronized</span> <span style="color: #000066; font-weight: bold;">void</span> closeLock<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #003399;">Thread</span>.<span style="color: #006633;">sleep</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">1000</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            isThePadlockOpen <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">false</span><span style="color: #339933;">;</span>
            <span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;I'm closing the lock&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #003399;">Thread</span>.<span style="color: #006633;">sleep</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">1000</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            tellMeIfThisLockIsOpen<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">InterruptedException</span> ex<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;I couldn't close the lock&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            Logger.<span style="color: #006633;">getLogger</span><span style="color: #009900;">&#40;</span>padlock.<span style="color: #000000; font-weight: bold;">class</span>.<span style="color: #006633;">getName</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">log</span><span style="color: #009900;">&#40;</span>Level.<span style="color: #006633;">SEVERE</span>, <span style="color: #000066; font-weight: bold;">null</span>, ex<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #008000; font-style: italic; font-weight: bold;">/**
     * This method simply sets the padlock to be open by setting isOpen to true.
     * Opening a lock takes two seconds (hence the sleep statements ).
     */</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">synchronized</span> <span style="color: #000066; font-weight: bold;">void</span> openLock<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #003399;">Thread</span>.<span style="color: #006633;">sleep</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">1000</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            isThePadlockOpen <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">true</span><span style="color: #339933;">;</span>
            <span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;I'm opening the lock&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #003399;">Thread</span>.<span style="color: #006633;">sleep</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">1000</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            tellMeIfThisLockIsOpen<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">InterruptedException</span> ex<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;I couldn't open the lock&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            Logger.<span style="color: #006633;">getLogger</span><span style="color: #009900;">&#40;</span>padlock.<span style="color: #000000; font-weight: bold;">class</span>.<span style="color: #006633;">getName</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">log</span><span style="color: #009900;">&#40;</span>Level.<span style="color: #006633;">SEVERE</span>, <span style="color: #000066; font-weight: bold;">null</span>, ex<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #008000; font-style: italic; font-weight: bold;">/**
     * Lets us know if our padlock object is open or closed
     */</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> tellMeIfThisLockIsOpen<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>isThePadlockOpen <span style="color: #339933;">==</span> <span style="color: #000066; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;The lock is open!&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">else</span> <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>isThePadlockOpen <span style="color: #339933;">==</span> <span style="color: #000066; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;The lock is closed!&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Something is seriously wrong!&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>The closeLockThread:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
</pre></td><td class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">workingWithSynchronizedThreads</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #008000; font-style: italic; font-weight: bold;">/**
 *
 * @author anton
 */</span>
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> closeLockThread <span style="color: #000000; font-weight: bold;">extends</span> <span style="color: #003399;">Thread</span> <span style="color: #009900;">&#123;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> padlock padlock<span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> closeLockThread<span style="color: #009900;">&#40;</span><span style="color: #003399;">Object</span> padlock<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">padlock</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>padlock<span style="color: #009900;">&#41;</span> padlock<span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    @Override
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> run<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        padlock.<span style="color: #006633;">closeLock</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>The openLockThread:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
</pre></td><td class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">workingWithSynchronizedThreads</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #008000; font-style: italic; font-weight: bold;">/**
 *
 * @author anton
 */</span>
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> openLockThread <span style="color: #000000; font-weight: bold;">extends</span> <span style="color: #003399;">Thread</span> <span style="color: #009900;">&#123;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> padlock padlock<span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> openLockThread<span style="color: #009900;">&#40;</span><span style="color: #003399;">Object</span> padlock<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">padlock</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>padlock<span style="color: #009900;">&#41;</span> padlock<span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    @Override
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> run<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        padlock.<span style="color: #006633;">openLock</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Okay, less mess with some threads!!!:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
</pre></td><td class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">workingWithSynchronizedThreads</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #008000; font-style: italic; font-weight: bold;">/**
 *
 * @author anton
 */</span>
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> messAroundWithSomePadlocks <span style="color: #009900;">&#123;</span>
&nbsp;
    <span style="color: #008000; font-style: italic; font-weight: bold;">/**
     * @param args the command line arguments
     */</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000066; font-weight: bold;">void</span> main<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> args<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        padlock myLock <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> padlock<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        closeLockThread iWannaCloseTheLock <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> closeLockThread<span style="color: #009900;">&#40;</span>myLock<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        openLockThread iWannaOpenTheLock <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> openLockThread<span style="color: #009900;">&#40;</span>myLock<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        iWannaCloseTheLock.<span style="color: #006633;">start</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        iWannaOpenTheLock.<span style="color: #006633;">start</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>The things that need attention are:</p>
<ol>
<li>Do we need to do that casting from padlock to padlock in the openLock and closeLock thread classes?</li>
<li>Is it ok/understandable to make a field a question? (public boolean isThePadlockOpen;) ?</li>
</ol>
<p>The inspiration for this work came from looking at some code were working on in my department, but the learning was really done looking at the<a href="http://java.sun.com/docs/books/tutorial/index.html"> Java Tutorials</a>, which are ace!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.parolski.com/2008/10/04/using-synchronized-methods-in-java/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
