This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Threads and Synchronization and the fly likes AtomicInteger.incrementAndGet infinite loop? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Threads and Synchronization
Bookmark "AtomicInteger.incrementAndGet infinite loop?" Watch "AtomicInteger.incrementAndGet infinite loop?" New topic
Author

AtomicInteger.incrementAndGet infinite loop?

Peter Kovac
Ranch Hand

Joined: Aug 08, 2010
Posts: 42
Hi,

Is it possible that AtomicInteger.incrementAndGet or similar methods will run forever?




thanks,
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18538
    
  40

Peter Kovac wrote:
Is it possible that AtomicInteger.incrementAndGet or similar methods will run forever?


In theory, I guess it is possible. In practice, I don't see how.

The only way to get an infinite loop, is to have constant CAS failures. And the only way to have constant CAS failures, is for another thread to exist -- another thread which constantly changes the integer. And for the scheduler to have the other thread change the integer in a way that your thread can't do two iterations in a row.

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Peter Kovac
Ranch Hand

Joined: Aug 08, 2010
Posts: 42
Henry Wong wrote:
Peter Kovac wrote:
Is it possible that AtomicInteger.incrementAndGet or similar methods will run forever?

The only way to get an infinite loop, is to have constant CAS failures.


Thanks..
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: AtomicInteger.incrementAndGet infinite loop?
 
Similar Threads
Cannot be resolved.
Volatile boolean versus AtomicBoolean
AtomicBigDecimal class -- interesting find
ResultSet Sensitive and Concurrent Updatable Problem
AtomicDouble class -- update