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