Java virtual thread (LOOM) and thread fairness

Project Loom ( JEP 425 ) is probably one of the most anticipated additions to Java ever. Its implementation of virtual threading (or “green threading”) ensures that developers can create highly concurrent applications, such as those with hundreds of thousands of open HTTP connections, adhering to the well-known thread-per-request programming model without resorting to less familiar and often more complex reactive methods. Only recently, after several years of effort, has Loom been merged into the main line of the OpenJDK and made available as a preview feature in the latest Java 19 early access release.

Java introduces static images to solve problems like slow running

In a recent social media post, Mark Reinhold, Chief Architect of Oracle’s Java Platform Group, officially announced the launch of the “Leyden” project. The project is said to have been approved and will alleviate slow startup and performance issues by introducing “static images” on the Java platform, designed to accelerate the creation of Java businesses. It is understood that the “Leyden” project was first proposed around May 2020 and has been discussed for more than 2 years now.

Use of CyclicBarrier in java concurrency

Introduction CyclicBarrier is a thread-safe component introduced in java 5. It has the concept of a barrier, which is used to wait for all threads to finish executing before performing a specific operation. If we have many threads and each thread computes some data, then we need to wait for all the threads to finish executing and then add up the data computed by each thread to the final result, then we can use CyclicBarrier.

Use of CountDownLatch in java concurrency

Introduction In java concurrency, it is very important to control access to shared variables, sometimes we also want to control the order of execution of concurrent threads, for example: wait for all threads to finish executing before executing another thread, or wait for all threads to be ready before starting the execution of all threads, This time we can use CountDownLatch. CountDownLatch contains a counter that is placed in the QueuedSynchronizer.

Java stream common operations on streams

Introduction As we all know, starting from Java8, jdk has added a new Stream class to complement the collection class. Stream provides a higher-order abstraction of Java collection operations and expressions using an intuitive way similar to querying data from a database with SQL statements. This style treats the collection of elements to be processed as a stream, which travels through the pipeline and can be processed at the nodes of the pipeline, such as filtering, sorting, aggregating, etc.

High-performance collections EnumMap and EnumSet

This article introduces EnumMap and EnumSet, which is a collection class under the java.util package. The Map and Set structures are especially used in our daily work, and often used to store data or pass parameters, but there is no way to control the data setting of Map, we have no idea what kind of data others will put into it, or if the type and number of data Key of our Map is fixed in some scenarios, then in this case How can we improve the security and performance of the system?

Java Discovers Annual Encryption Vulnerability

Recently, security researcher Khaled Nassar made public on GitHub the PoC code for a newly disclosed digital signature bypass vulnerability in Java, tracked as CVE-2022-21449. The vulnerability is known to have been discovered by Neil Madden, a researcher at security consulting firm ForgeRock, in November of last year, and was notified to Oracle the same day. Although Oracle gave the vulnerability a CVSS rating of 7.5, ForgeRock said they had privately disclosed the vulnerability when it was first discovered and rated the vulnerability a 10 on the CVSS.

JDK 19 / Java 19 has proposed two features

JDK 18/Java 18 has been released last month, according to the plan JDK 19 will be released in September this year, a few days ago the official proposed two features that will be released in the next version. One is the Vector API, and the other is a port of the JDK to RISC-V. The former Vector API is an API that expresses vector computation and will be incubated for the fourth time in the next Java release; the latter proposes a feature to port the JDK to the open source Linux/RISC-V instruction set architecture (ISA).

Thread-Affinity for CPU-bound threads

Introduction In modern computer systems, there can be multiple CPUs, and each CPU can have multiple cores. In order to take full advantage of the capabilities of modern CPUs, JAVA introduced multithreading, where different threads can run on different CPUs or different CPU cores at the same time. However, for JAVA programmers it is possible to control how many threads are created, but which CPU the threads are running on is generally difficult to know.

Oracle fixes Java annual encryption vulnerability affecting Java 15 and above

Oracle pushed out a security update yesterday to fix a vulnerability that allowed attackers to forge certain types of SSL certificates and handshakes, two-factor authentication information, and authorization credentials generated by a range of widely used open standards. This allows an attacker to easily digitally sign files and other data. This vulnerability affects the implementation of ECDSA (Elliptic Curve Digital Signature Algorithm) in Java 15 and above. ECDSA is an algorithm that uses elliptic curve cryptography principles to digitally authenticate messages.

The Father of Java: Don't Stick with Java 8

James Gosling, the father of Java, recently twitter that developers should abandon JDK 8 as soon as possible and opt for JDK 17 LTS, which brings huge improvements in every aspect. But maybe the father of Java was just promoting Corretto, the OpenJDK distribution for his boss AWS. and he suggests that developers still using JDK 8 might consider using Corretto’s new version- -Includes all the latest updates and CVE defenses.

Basic use of ThreadPool

Preface In Java, threads are the counterpart of system threads and are used to handle a range of system resources. The number of threads that can be opened is limited in both windows and linux, so if you create unlimited threads in your java program, you will encounter a situation where no threads can be created. CPU cores are limited and if there are multiple threads running at the same time, the CPU will rotate according to the priority of the threads and allocate a specific amount of CPU time to each thread.

The fork join framework in java

Preface Fork join framework is the introduction of java 7 framework, the introduction of this framework is mainly to improve the ability of parallel computing. Fork join has two main steps, the first is fork, a large task into many small tasks, the second is join, the results of the first task join up to generate the final result. If there is no return value in the first step, join will wait until all the small tasks are finished.

Daemon Thread in Java

Preface There are two types of threads in java, user threads and daemon threads. User threads are high priority threads and the JVM will wait for all the User Threads to finish running before it finishes running. daemon threads are low-priority threads that serve User Threads. Because daemon threads are low priority and serve only user threads, the JVM will automatically exit when all user threads are finished, regardless of whether there are still daemon threads running.

Notes on upgrading from Java 8 to Java 11

Preface Although the latest version of Java has evolved to Java 18, most projects on the market are still using Java 8. Many people are apprehensive about upgrading their Java version because the Java API is not necessarily forward compatible from Java 8. Java 11 is the next long-supported version of Java 8, and there is no doubt that Java 11 is even better than Java 8. superior. This article describes the code checking tools used to convert code from Java 8 to Java 11, as well as the problems you may encounter and suggestions for resolving them.

AbstractQueuedSynchronizer implementation principle - 2

Preface In the previous articleAbstractQueuedSynchronizer implementation principle - 1, we explained the acquisition and release of exclusive synchronization state in AbstractQueuedSynchronizer, and here we start to explain the acquisition and release of shared synchronization state in AbstractQueuedSynchronizer. Shared Synchronous State Acquisition and Release Shared lock as the name implies is that multiple threads can share a lock, use acquireShared in the synchronizer to get the shared lock (synchronous state), the source code of the method is as follows.

AbstractQueuedSynchronizer implementation principle - 1

Preface AbstractQueuedSynchronizer is the basic framework for implementing concurrency tools in the JDK, and a deeper understanding of it will help us to better use its features and related tools. We hope you will read this article carefully and gain something from it. In Java, access to shared resources by multiple threads is controlled by lock. We know that the lock function can be implemented by the synchronized keyword, which can implicitly acquire locks, that is, we do not need to care about the process of acquiring and releasing locks by using this keyword, but while it provides convenience, it also means that its flexibility is reduced.

Simple use of the Atomic class

Problem Background In a multi-threaded environment, the most common problem we encounter is synchronizing the values of variables. Since variables need to be shared across multiple threads, we must need to employ some synchronization mechanism to control them. From the previous article we know that the Lock mechanism can be used, and of course, the Atomic class we are talking about today. Here we will introduce each of the two ways.

Use of join in java

Introduction join() is a method we often use in java that sets the current thread to the WAITTING state and then waits for the calling thread to finish executing or be interrupted. Definition join() is a method defined in Thread, let’s look at his definition. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 /** * Waits for this thread to die.

The life cycle of threads in java

Introduction Threads is a frequently used technology in java, this article will explain in detail the life cycle of threads in java, I hope you can give some help. The state of Thread in java There are six states of Thread in java, which are. NEW - newly created Thread, has not yet started execution RUNNABLE - Thread in runnable state, including ready to run and running. BLOCKED - Threads that are waiting for a resource lock WAITING - A thread that is waiting indefinitely for other threads to perform a specific operation TIMED_WAITING - Waiting for a certain amount of time for other threads to perform a specific operation TERMINATED - the thread has finished executing We can visualize this in a diagram.