This week's book giveaway is in the Design forum.
We're giving away four copies of Building Microservices and have Sam Newman 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 Building Microservices this week in the Design 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: 20057
    
  44

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’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com
 
subject: AtomicInteger.incrementAndGet infinite loop?
 
It's not a secret anymore!