Java Virtual Threads

Virtual threading is something I’m really excited about. It’s a long-awaited feature in the language and we’ve made very few attempts to implement it in the past, but it’s finally here and it’s been merged into Java 19. This means that it will be included as a preview feature and we will be able to use it as soon as JDK 19 is released. Most of the content on the virtual (green) threads is written by non-Java developers, why is that?

How to avoid memory leaks in java programs

Although jvm has a garbage collection mechanism, if the program is written without paying attention to some specific rules, it can still lead to memory leaks in java programs, which may end up with OutOfMemory exceptions. 1. Causes of memory leaks in Java Objects in java are divided into 2 types in terms of usage, referenced and unreferenced. Garbage collection only recovers objects that are not referenced. Referenced objects, even if they are no longer used, are not recycled.

ElasticSearch new version of JavaClient using the introduction

The java client used by ElasticSearch before version 7.17 was the Java REST Client, but since version 7.17, the Java REST Client has been officially marked as deprecated and the new version of the Java Client is recommended. This article introduces the new version of the ElasticSearch Java Client’s basic usage. The specific code reference Example project. I. Overview Elasticsearch 7.17 version of the new Java API Client has the following advantages.

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.

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?

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.