Home » concurrency

Tag Archives: concurrency

JavaFX Concurrency Example

This is a JavaFX Concurrency Example. Java GUI applications are inherently multithreaded. Multiple threads perform different tasks to keep the UI in sync with the user actions. JavaFX, like Swing and AWT, uses a single thread, called JavaFX Application Thread, to process all UI events.                   The following table shows an overview ...

Read More »

java.util.concurrent.atomic.AtomicBoolean Example

In this example, we shall be demonstrating the use of java.util.concurrent.atomic.AtomicBoolean Class added in Java 5. The AtomicBoolean class is used to update a boolean value atomically i.e. only one thread can modify the boolean variable at a time. It provides two constructors, a parameterless one with default value as false and a constructor with argument as initial boolean value. ...

Read More »

java.util.concurrent.Phaser Example

In this example, we shall be demonstrating the java.util.concurrent.Phaser Class. The Phaser Class was introduced in Java 7. Phaser is like a collection of advantages of CountDownLatch and CyclicBarrier Classes.             CountDownLatch vs CyclicBarrier vs Phaser The CountDownLatch is : Created with a fixed number of threads Cannot be reset Allows threads to wait(CountDownLatch#await()) or ...

Read More »

java.util.concurrent.ForkJoinPool Example

In this example, we shall be demonstrating the use of java.util.concurrent.ForkJoinPool Class. This class was introduced in Java 7. The java.util.concurrent.ForkJoinPool Class implements java.util.concurrent.Executor and java.util.concurrent.ExecutorService interfaces. This class works on divide-and-conquer policy. Each major subtask is divided into a number of sub-tasks and a new thread is spawned for each new sub-task. Recursion is the most popular strategy for ...

Read More »

Java AtomicIntegerArray Example

In this example we shall talk about the AtomicIntegerArray class of Java. Java provides the java.util.concurrent.atomic package specification for lock-free and thread-safe programming on single variables. The AtomicIntegerArray class is an int array in which elements may be updated atomically. Its difference with an simple AtomicInteger[] is that it creates one object, whereas when using AtomicInteger[], one object per array ...

Read More »

Java ReadWriteLock Example

In this example, we are going to demonstrate the use of ReadWriteLock in Java. Mutually Exclusive Locks, as the ReentrantLock discussed in the previous article, offer far less level of concurrency than non-mutually exclusive locks. If multiple threads are accessing an object for reading data, it does not make sense to use a synchronized block or any other mutually exclusive ...

Read More »