Dynamically Adding Appenders to Log4j
In addition to configuring Log4j through configuration files in formats such as properties and XML, Log4j also provides various interfaces that allow you to dynamically modify Log4j configuration using code, such as adding an appender to a logger. The method is straightforward: create a new appender and add it to the logger. Here is a sample code: 123456789KafkaLog4jAppender kafkaAppender = new KafkaLog4jAppender();kafkaAppender.setBrokerList(broker);kafkaAppender.setTopic(topic);kafkaAppende...
[Translation] Some Experiences Writing Benchmarks in Java
Sometimes we need to write some simple performance test code. I happened to come across an experience-based post on Stack Overflow: https://stackoverflow.com/questions/504103/how-do-i-write-a-correct-micro-benchmark-in-java — how to write benchmarks to minimize environmental influence. Here’s my translation: Tips from a Java HotSpot author on writing microbenchmarks: Rule 0: Read good papers on the JVM and microbenchmarks. For example, https://www.ibm.com/developerworks/java/library/j-jtp0222...
Maven Mirror and Repository: Configuring Multiple Repositories
Mirror and repository in Maven are two easily confused concepts, as both are used to configure the addresses of remote Maven repositories. As the name suggests, a repository directly configures the site address, while a mirror acts as a site’s mirror, proxying requests to one or several sites, achieving a complete replacement of repositories. RepositoryThere are two ways to configure multiple repositories: configuring multiple profiles or configuring multiple repositories within a single prof...
Building Executable JAR Packages with Maven Shade Plugin
Eclipse has a feature called “Export Runnable JAR File” that packages a project along with all its dependencies into a Fat JAR, with a specified Main class, so you can run the code directly using java jar xxx.jar. However, what if you’re not using Eclipse? Actually, with the help of Maven, we can easily achieve the same functionality. Maven provides a Shade Plugin that can be used to build Fat JARs, and it also supports specifying the Main class. 12345678910111213141516171819202122232425262...
ActiveMQ Plugin Development Guide and Examples
ActiveMQ provides a plugin development mechanism (http://activemq.apache.org/developing-plugins.html) that allows you to conveniently add various custom functionalities. The effect is similar to directly modifying ActiveMQ’s source code, but using plugins is much better than modifying source code in terms of both convenience and risk. In theory, we can implement almost any functionality imaginable through this approach. Development GuideFirst, you need to add the ActiveMQ dependency to your p...
Running Java Programs from the Command Line by Adding Third-Party Jars to the Classpath
When running a Java program from the command line, how do you include third-party jar packages? There are actually many methods, most of which involve tinkering with the classloader. Here I’ll introduce a relatively simple approach: adding all the required jar packages to the classpath before running. Specifically, you write a shell script that defines a parameter — you can call it CLASSPATH or something else. CLASSPATH=yourownjar.jar:xxx.jar:/xx/xx/xxx1.jar:”$CLASSPATH” ...
Fixing the SecurityException: Invalid Signature File Digest for Manifest Main Attributes in Fat Jars
Recently I encountered an error when trying to run a fat jar: 1234567891011121314151617181920Exception in thread "main" java.lang.SecurityException: Invalid signature file digest for Manifest main attributes at sun.security.util.SignatureFileVerifier.processImpl(SignatureFileVerifier.java:287) at sun.security.util.SignatureFileVerifier.process(SignatureFileVerifier.java:240) at java.util.jar.JarVerifier.processEntry(JarVerifier.java:317) at java.util.jar.JarVerifier.update(JarVerifi...
Understanding Redis Cluster Through Practice
Redis Cluster is an official clustering solution provided by Redis. It has been available as a stable release since version 3.0, is widely adopted, and has stood the test of time. Personally, I believe it can fully replace other clustering solutions like Codis and Twemproxy. Cluster PrinciplesCluster implements data sharding. A Redis Cluster contains 16,384 hash slots. Any key can be mapped to a specific slot using the formula CRC16(key) % 16384. Which slot belongs to which node is predetermi...
An Approach to Storing Sets in HBase
As we know, HBase stores data as binary key-value pairs, unlike Redis which provides built-in support for various data structures. So how can we store set-type data in HBase? One approach is to serialize the entire set as a single object and store it in HBase. However, this means that for any subsequent add, delete, update, or query operation, you must first retrieve the entire stored content, make the necessary modifications, and then overwrite the original value. This approach is clearly no...
Log4j2 XML Configuration Examples and Differences from Log4j
1234567891011121314151617181920212223242526272829303132333435<?xml version="1.0" encoding="UTF-8" ?><configuration status="warn"> <Appenders> <Console name="Console" target="SYSTEM_OUT"> <PatternLayout pattern="[%p] %d %c %l - %m%n"/> </Console> <RollingFile name="activity" fileName="/opt/fox.log" filePattern="/opt/f...

![[Translation] Some Experiences Writing Benchmarks in Java](/en/img/4987.jpg)












