tutorials

Java's missing feature: extension methods

What is an extension method? An extension method is the ability to “add” a method directly to an existing type without creating a new derived type, recompiling, or otherwise modifying the existing type. When calling an extension method, there is no significant difference compared to calling the actual method defined in the type. Why you need extension methods Consider a function that, after fetching a string containing multiple item IDs from Redis (each item ID is separated by an English comma), first de-duplicates the item IDs (and is able to maintain the order of the elements), and then finally concatenates the individual item IDs using English commas.

Java Memory Issues in Cloud Native

Java has been one of the most popular programming languages in the past two decades with its active open source community and well-established ecological advantages. Entering the cloud-native era, the booming cloud-native technology releases cloud computing dividends, drives business to cloud-native transformation, and accelerates the digital transformation of enterprises. However, Java’s cloud-native transformation path faces great challenges, and there are many contradictions between Java’s operation mechanism and cloud-native features. Enterprises are leveraging cloud-native technology for deep cost optimization, and resource cost management has been raised to an unprecedented level.

Detailed explanation of JAVA thread problem diagnosis tool Thread Dump

Thread Dump is a very useful tool for diagnosing problems with Java applications. Every Java virtual machine has the ability to generate a thread-dump of the state of all threads at a given point in time. Although the thread dump printed by each Java virtual machine varies slightly, most of them provide a snapshot of the currently active thread and a stack trace of all Java threads in the JVM. The stack information usually contains the full class name and the methods executed and, if possible, the source code line number.

Found a bug in MapStruct expressions

Preface MapStruct is a code generator that greatly simplifies the implementation of mappings between Java Bean types based on a conventionally preferred approach to configuration. The generated mapping code uses simple method calls, so it is fast, type-safe and easy to understand. mapStruct’s expression function is designed to deal with the mapping of special object properties, such as the DTO status property into PO status requires further processing, this time you need to use the expression function.

Getting Started with JavaParser: Analyzing Java Code Programmatically

The JavaParser library provides an abstract syntax tree for Java code. The AST structure allows you to use Java code in a simple programmatic way. When using JavaParser, we usually want to perform a series of operations at a time. Usually, we want to operate on the entire project, so given a directory, we will explore all Java files. This class should help to accomplish the following operations. import java.io.File; public class DirExplorer { public interface FileHandler { void handle(int level, String path, File file); } public interface Filter { boolean interested(int level, String path, File file); } private FileHandler fileHandler; private Filter filter; public DirExplorer(Filter filter, FileHandler fileHandler) { this.

Jenkins Deploying Java Applications to Tomcat Server

For Java programs, Jenkins requires the use of build tools such as maven, ant, etc., with maven being more popular. Here we use maven to implement the deployment of Java applications. Prepare Java code in GitLab Deploy Tomcat and configure it apt-get -y install tomcat9 tomcat9-admin cp -r /usr/share/tomcat9-admin/* /var/lib/tomcat9/webapps/ Open /var/lib/tomcat9/conf/tomcat-users.xml and do the following configuration. Add the following three lines to create users and authorize them. manager-script for remote script execution privileges <role rolename="manager-gui"/> <role rolename="manager-script"/> <user username="tomcat" password="tomcat" roles="manager-gui,manager-script"/> Open /var/lib/tomcat9/webapps/manager/META-INF/context.

Java Containerization Guide

I. System selection About the most basic underlying image, usually most of us have only three choices: Alpine, Debian, CentOS; of these three for the operation and maintenance of the most familiar with the general CentOS, but unfortunately CentOS later no longer exists in a stable version, about its stability has been a mysterious problem; this is a matter of opinion, I Personally, I don’t use it if I can 😆.

Making Java Agent work better on Dragonwell

Background Java Agent technology can dynamically modify Java application behavior without reworking the code. It is because of these features that many middleware teams, cloud vendor teams, and open source products, started using Java Agent technology to provide some basic capabilities, such as Apache Skywalking, OpenTelemetry all provide Java Agent. Earlier, middleware teams provided capabilities through SDKs (e.g., observable, microservice governance capabilities, etc.); however, each time middleware teams added new features and fixed defects, they needed each business party to update the SDK version and re-release it.

Java19 Official GA! See how virtual threads can dramatically increase system throughput

Java19 was released yesterday, bringing a new feature that Java developers have been waiting for - virtual threads. Before Java had this new feature, Golang’s Goroutine had been popular for a long time, and it was a big hit in the field of concurrent programming. With the rapid development and promotion of Golang, it seems that coroutine has become one of the necessary features of the best languages in the world.

Solution for JWT Token auto-renewal

Preface In a front-end/back-end development model, the back-end service issues a jwt token to the user after the front-end user logs in successfully. Each subsequent request will put this token in the request header and pass it to the backend service, which will have a filter to intercept the token and check whether the token is expired, and if the token is expired, the frontend will jump to the login page to log in again.