Scale up as you grow — whether you're running one virtual machine or ten thousand.

From GPU-powered inference and Kubernetes to managed databases and storage, get everything you need to build, scale, and deploy intelligent applications.

Thank you very much for your site and tutorials! You are doing very great job, even after almost 7 years in java development i can find something new in your blog posts! Thank you very much and good luck!
- Alex
How is atomicity incorporated into the Atomic Integer class? it has to be via locks right ?? Then how is this different from Synchronisation block?
- Sorrowfull Blinger
Hi, Simply i can modify the program you suggested above for atomic but i haven’t seen any benefit of this atomic variable because in both cases i am getting same result. So can you please provide another example for the same to see what exactly it is… package test; import java.util.concurrent.atomic.AtomicInteger; public class JavaAtomic { public static void main(String[] args) throws InterruptedException { ProcessingThread pt = new ProcessingThread(); Thread t1 = new Thread(pt, “t1”); Thread t2 = new Thread(pt, “t2”); t1.start(); t2.start(); t1.join(); t2.join(); System.out.println(“Processing count=” + pt.getCount()); } } class ProcessingThread implements Runnable { // private AtomicInteger count = new AtomicInteger(); int count = 0; @Override public void run() { // count.incrementAndGet(); for (int i = 0; i < 4; i++) { count++; } } public int getCount() { // return this.count.get(); return count; } }
- sachin
Good site for java interview preparation. But i didn’t understand why to use Atomic integer class. Can you please provide the scenario where we can use this
- Lalita
it’s very usefully for me ,this is my first time visited this site.The tutorials understandability,thanks a lot.But i didn’t understand how to use Atomic integer class?
- Wells Lee
I think the count value going “5,6,7,8” is perfectly acceptable in your first example isn’t it? But Yes. I got the concept.
- IM
This is a wrong explanation u r joining both threads . Did not expect this dumb kind of explanation from such a senior analyst. Clear ur concepts first.
- Nitin
I think we need better explanation, not just the syntax on how to use AtomicInteger, its available everywhere else on the internet.
- Prashant