<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	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/"
		>
<channel>
	<title>Comments on: Why synchronize? Go ATOMIC!</title>
	<atom:link href="http://www.javablogging.com/why-synchronize-go-atomic/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.javablogging.com/why-synchronize-go-atomic/</link>
	<description>Tracking surprises, features and bugs</description>
	<lastBuildDate>Sun, 05 Feb 2012 15:43:49 -0500</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Kiren</title>
		<link>http://www.javablogging.com/why-synchronize-go-atomic/comment-page-1/#comment-11116</link>
		<dc:creator>Kiren</dc:creator>
		<pubDate>Wed, 08 Jun 2011 08:16:03 +0000</pubDate>
		<guid isPermaLink="false">http://www.javablogging.com/?p=303#comment-11116</guid>
		<description>I&#039;ve used atomic integer, and interestingly, it does seem to be not totally threadsafe...I have an app using an AtomicInteger as an index over an array. 

Sometimes, it does not behave:
	int indexVal=index.getAndIncrement(); // Keep this in case its cause the side-effect (1 in 14400).
		logger.debug(&quot;Getting connection from &quot; + indexVal);
		DataSource myDs = dataSources.get(indexVal);

		if (index.get() &gt;= dataSources.size()) {
			index.set(0);
		}
		return myDs;

For some reason, the index goes pass the length, as in the comment, maybe 1 every 14000 requests, 25 conncurrent requests.</description>
		<content:encoded><![CDATA[<p>I&#8217;ve used atomic integer, and interestingly, it does seem to be not totally threadsafe&#8230;I have an app using an AtomicInteger as an index over an array. </p>
<p>Sometimes, it does not behave:<br />
	int indexVal=index.getAndIncrement(); // Keep this in case its cause the side-effect (1 in 14400).<br />
		logger.debug(&#8221;Getting connection from &#8221; + indexVal);<br />
		DataSource myDs = dataSources.get(indexVal);</p>
<p>		if (index.get() &gt;= dataSources.size()) {<br />
			index.set(0);<br />
		}<br />
		return myDs;</p>
<p>For some reason, the index goes pass the length, as in the comment, maybe 1 every 14000 requests, 25 conncurrent requests.</p>
]]></content:encoded>
	</item>
</channel>
</rss>

