更新测试案列
This commit is contained in:
parent
d36a9267c8
commit
adfe6eb0ab
2
pom.xml
2
pom.xml
@ -14,7 +14,7 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.apache.logging.log4j</groupId>
|
<groupId>org.apache.logging.log4j</groupId>
|
||||||
<artifactId>log4j-slf4j-impl</artifactId>
|
<artifactId>log4j-slf4j-impl</artifactId>
|
||||||
<version>2.10.0</version>
|
<version>2.20.0</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
@ -5,11 +5,14 @@ import cn.wudashan.util.MDCUtil;
|
|||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import java.util.Random;
|
||||||
import java.util.concurrent.ExecutorService;
|
import java.util.concurrent.ExecutorService;
|
||||||
import java.util.concurrent.Executors;
|
import java.util.concurrent.Executors;
|
||||||
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 主函数
|
* 主函数
|
||||||
|
*
|
||||||
* @author wudashan
|
* @author wudashan
|
||||||
*/
|
*/
|
||||||
public class Main {
|
public class Main {
|
||||||
@ -19,32 +22,26 @@ public class Main {
|
|||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
|
|
||||||
// 入口传入请求ID
|
|
||||||
MDCUtil.putRequestId();
|
|
||||||
|
|
||||||
// 主线程打印日志
|
Stream.generate(() -> new Random().nextInt(10)).distinct().limit(10)
|
||||||
logger.debug("log in main thread");
|
.parallel().forEach(e -> {
|
||||||
|
// 入口传入请求ID
|
||||||
|
MDCUtil.putRequestId();
|
||||||
|
// 主线程打印日志
|
||||||
|
logger.debug("{} log in main thread", e);
|
||||||
|
|
||||||
// 异步线程打印日志,用MDCRunnable装饰Runnable
|
// 异步线程打印日志,用MDCRunnable装饰Runnable
|
||||||
new Thread(new MDCRunnable(new Runnable() {
|
new Thread(new MDCRunnable(() -> logger.debug("{} log in other thread", e))).start();
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
logger.debug("log in other thread");
|
|
||||||
}
|
|
||||||
})).start();
|
|
||||||
|
|
||||||
// 异步线程池打印日志,用MDCRunnable装饰Runnable
|
// 异步线程池打印日志,用MDCRunnable装饰Runnable
|
||||||
EXECUTOR.execute(new MDCRunnable(new Runnable() {
|
EXECUTOR.execute(new MDCRunnable(() -> logger.debug("{} log in other thread pool", e)));
|
||||||
@Override
|
|
||||||
public void run() {
|
// 出口移除请求ID
|
||||||
logger.debug("log in other thread pool");
|
MDCUtil.removeRequestId();
|
||||||
}
|
|
||||||
}));
|
});
|
||||||
EXECUTOR.shutdown();
|
EXECUTOR.shutdown();
|
||||||
|
|
||||||
// 出口移除请求ID
|
|
||||||
MDCUtil.removeRequestId();
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user