Java concurrency articles

Misleading concurrent keyword

Often we think that if something is from "concurrent" package, it's automatically thread-safe. By definition is true, but the definitions rarely make the applications and through this post we'll see why.

Continue Reading β†’

LockSupport in Java

During reading Thread documentation I found a class that existence I've ignored until now - LockSupport. Some of its methods influence Thread states, so it was quite natural choice for the topic of next posts.

Continue Reading β†’

Thread lifecycle in Java

Simply speaking a thread goes from created to terminated state, passing by the execution phase. However in practice it's not so simple because some other steps can occur during execution

Continue Reading β†’

OS Thread Scheduler and Java Thread

Most of time threads manipulation is limited to programming language. Even if this high abstraction is sufficient, it's also good to know what happens under-the-hood when a new thread is created in any programming language (Java in the case of this post).

Continue Reading β†’

Handling InterruptedException

The risk of InterruptedException appears very often in multi-threading environment. As a declared exception, it must be defined either in method signature or caught in try-catch block. However, it must be done in some correct way.

Continue Reading β†’

TransferQueue

Often consumer-producer applications stores common elements in shared queue. Java offers different types of this data structure and one of them is TransferQueue.

Continue Reading β†’

Completable future

With Java 8 comes a complementary class to classical Future objects. This class not only helps to work with promises but also makes possible to get future results in non-blocking way.

Continue Reading β†’

Atomic package

Atomicity in thread-safe parallel programming is one of crucial points. Thanks to it, any thread participating in the parallel code execution receives the final value, without the risk to get an "intermediate" value modified by another thread.

Continue Reading β†’

Divide and conquer with fork/join framework

When performance matters (when it does not?), dealing with a big task can prove to be very costly. One of solutions for this kind of bottlenecks could be the using of divide and conquer algorithms. In Java it can be retrieved in fork/join framework.

Continue Reading β†’

CopyOnWriteArrayList as thread-safe ArrayList

Working with collections in multi-threading environment is a little bit tricky. But fortunately, Java offers some objects able to store data in thread-safe way. One of them is CopyOnWriteArrayList, introduced with Java 5.

Continue Reading β†’

CountedCompleter

Java 8 brings another type of ForkJoinTask, CountedCompleter. And because sometimes this class is considered little bit obscure, we'll try to understand it through this article.

Continue Reading β†’

Phaser in Java concurrency

JDK 7 introduced a interesting concurrency concept of mix between CountDownLatch and CyclicBarrier mechanisms. It's name - Phaser.

Continue Reading β†’

Thread pools in Java concurrency

Before writing production code based on Java's executors, we should learn another inseparable concept of concurrency, thread pools.

Continue Reading β†’

Barriers in Java concurrency

A barrier in the real world helps to separate two different concepts, for example two countries. In programming, it's a technique to achieve threads synchronization. Java implements its own version of barriers in java.util.concurrent package.

Continue Reading β†’

Completion service in Java

Producer-consumer services can be very quickly realized with native Java features. One of them, arrived with the 7th version of Java, is CompletionService.

Continue Reading β†’

Objects locking

Synchronized blocks are only one of methods to handle concurrent access to Java's objects. Another one are the implementation of classes included in java.util.concurrent.locks package.

Continue Reading β†’

Object monitor pattern

Classes synchronization in Java multi-threading environment can be done thanks to many classes from java.util.concurrent package. But it can also be achieved thanks to some traditional methods, as monitors.

Continue Reading β†’

Future in Java

Concurrent programming isn't not only about executing several tasks in parallel threads. It's only about analyzing results of these process. In Java, we can analyze them thanks to the idea of futures.

Continue Reading β†’

Executor services in Java

Java 1.5 introduced a concept of executors, very useful for concurrent environments. Thanks to them we can easily create thread pools and even manipulate results generated by the threads. This article will cover this subject.

Continue Reading β†’

CountDownLatch in Java

Java's version 1.5 introduced more of features to help to deal with multi-threading programs. One of these features is a class which allows a main thread to wait another threads before continue. The name of this class is CountDownLatch.

Continue Reading β†’