In this article, we will check what was added and removed in Java 16.

JDK 16 is the open-source reference implementation of version 16 of the Java SE Platform, as specified by by JSR 390 in the Java Community Process.

JDK 16 reached General Availability on 16 March 2021. Production-ready binaries under the GPL are available from Oracle; binaries from other vendors will follow shortly.

The features and schedule of this release were proposed and tracked via the JEP Process, as amended by the JEP 2.0 proposal. The release was produced using the JDK Release Process (JEP 3).

If you missed what was changed in Java 15 you can check it here:

Features


In this article, we’ll cover Thread Pools and how they make java multithreading programming easier.

Server Programs such as databases and web servers repeatedly execute requests from multiple clients and these are oriented around processing a large number of short tasks. An approach for building a server application would be to create a new thread each time a request arrives and service this new request in the newly created thread.

While this approach seems simple to implement, it has significant disadvantages. A server that creates a new thread for every request would spend more time and consume more system resources in creating and destroying threads than processing actual requests.

Since active threads consume system resources…


In this article, we’ll cover Executors in java multithreaded programming and how to use them.

The Concurrency API introduces the concept of an ExecutorService as a higher-level replacement for working with threads directly. Executors are capable of running asynchronous tasks and typically manage a pool of threads, so we don't have to create new threads manually.

All threads of the internal pool will be reused under the hood for revenant tasks, so we can run as many concurrent tasks as we want throughout the life-cycle of our application with a single executor service.

The java.util.concurrent package defines three executor interfaces:

  • Executor, a simple interface that supports launching new tasks.
  • ExecutorService, a subinterface of Executor, which…


In this article, we will check what was added and removed in Java 15.

JDK 15 is the open-source reference implementation of version 15 of the Java SE Platform, as specified by JSR 390 in the Java Community Process.

JDK 15 reached General Availability on 15 September 2020. Production-ready binaries under the GPL are available from Oracle; binaries from other vendors will follow shortly.

The features and schedule of this release were proposed and tracked via the JEP Process, as amended by the JEP 2.0 proposal. The release was produced using the JDK Release Process (JEP 3).

Removals

Solaris and SPARC Ports

The source code and build support for the Solaris/SPARC, Solaris/x64, and Linux/SPARC ports were removed. …


In this article, we’ll cover Locks in java multithreaded programming and how to use them.

A lock is a thread synchronization mechanism like synchronized blocks except locks can be more sophisticated than Java’s synchronized blocks. Locks are created using synchronized blocks, so it is not like we can get totally rid of the synchronized keyword.

From Java 5 the package java.util.concurrent.locks contains several lock implementations, so you may not have to implement your own locks. But you will still need to know how to use them, and it can still be useful to know the theory behind their implementation.

Lock vs Synchronized Block

There are few differences between the use of synchronized block and using Lock API:

  • A synchronized


In this article, we will cover how to do integration tests in spring boot application with PostgreSQL DB, Liquibase, and JUnit 5.

Previously I wrote an article about how to do integration tests with spring boot, liquibase and test containers.

Here is the link:

This implementation works great and configuration is quite easy. But it has one drawback — configuration was written on the Junit 4.

JUnit 4 has been released in 2006 and written in Java 5. There were a couple of minor releases for Junit 4 till then but the core is still the same.

All developers want to use the latest and greatest technologies. …


In this article, we’ll cover Deadlock situations in java multithreaded programming and how to avoid them.

A deadlock occurs when two or more threads wait forever for a lock or resource held by another of the threads. An application may stall or fail as the deadlocked threads cannot progress.

For instance, if thread 1 locks A, and tries to lock B, and thread 2 has already locked B, and tries to lock A, a deadlock arises. Thread 1 can never get B, and thread 2 can never get A. In addition, neither of them will ever know. They will remain blocked on each their object, A and B, forever. This situation is a deadlock.

The situation…


In this article, we’ll cover a Thread Signaling and how it helps threads to communicate with each other.

Signaling via Shared Objects

A simple way for threads to send signals to each other is by setting the signal values in some shared object variable. Thread A may set the boolean member variable hasDataToProcess to true from inside a synchronized block, and thread B may read the isDataAvailable member variable, also inside a synchronized block. Here is a simple example of an object that can hold such a signal, and provide methods to set and check it:

public class ThreadSignal{  protected boolean isDataAvailable = false;  public synchronized boolean setIsDataAvailable(){
return this.isDataAvailable;
}
public synchronized void isDataAvailable(boolean value){
this.isDataAvailable = value;
}
}

Thread…


In this article, we’ll cover a ThreadLocal and what is the purpose of this class in multithreaded programming.

The Java ThreadLocal class enables you to create variables that can only be read and written by the same thread. Thus, even if two threads are executing the same code, and the code has a reference to the same ThreadLocal variable, the two threads cannot see each other's ThreadLocal variables. Thus, the Java ThreadLocal class provides a simple way to make code thread-safe that would not otherwise be so.

Pattern to use ThreadLocal

ThreadLocal instances are typically private static fields in classes that wish to associate the state with a thread.

For example, the class below generates counters local to each thread. A new…


In this article, we’ll cover Volatile and when we need to use it in multi-threading programming

The Java volatile keyword is used to mark a Java variable as "being stored in main memory". That means, that every read of a volatile variable will be read from the computer's main memory (RAM), and not from the CPU cache and that each writes to a volatile variable will be written to the RAM, and not just to the CPU cache.

Since Java 5 the volatile keyword guarantees more than just that volatile variables are written to and read from main memory.

Variable Visibility Problems

The Java volatile keyword guarantees visibility of changes to variables across threads.

In a multithreaded application where…

Dmytro Timchenko

New tech lover. Software developer, like to learn new stuff and share knowledge with the community.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store