【发布时间】:2020-06-18 15:43:31
【问题描述】:
如果两个线程最终可能同时修改 TestReporter 实例,下面的代码是否正常?
@Test
public void someTest(TestReporter testReporter) {
// do some stuff
CompletableFuture.allOf(
CompletableFuture.runAsync(() -> {
// do task A
testReporter.publishEntry("taskA", "valueA");
}),
CompletableFuture.runAsync(() -> {
// do task B
testReporter.publishEntry("taskB", "valueB");
})
).join();
}
【问题讨论】:
标签: java multithreading unit-testing junit5