Mohinish's Blog

Rants from a technologically confused mind !!

Atomic Operations

leave a comment »

Java 1.5 added capability to define atomic variables, e.g AtomicInteger. The word ‘automic’ comes from the concept of Atomic Operations which is a process that is computed as a single unit of work without any interference.

For example, reading and writing a value to a int variable is automic, the value of variable doesnt change during this process, however the operation i++ is not since it involves first reading the value from i and then incrementing it, however the value i may change due to some other thread during the process.

Automic varibles like AutomicInteger maintains this automic feature by providing methods like getAndDecrement(), getAndSet() etc which prevents any other thread to modify the value while executing these methods.

Advertisement

Written by rootedlabs

September 26, 2011 at 3:28 am

Posted in Java

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.