mirror of
https://gitee.com/dromara/hutool.git
synced 2025-04-24 18:04:54 +08:00
SyncFinisher增加setExceptionHandler方法
This commit is contained in:
parent
08343db0f0
commit
d0556a4e48
@ -16,6 +16,8 @@ import org.dromara.hutool.core.lang.Console;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
public class SyncFinisherTest {
|
||||
|
||||
/**
|
||||
@ -23,16 +25,21 @@ public class SyncFinisherTest {
|
||||
*/
|
||||
@Test
|
||||
void executeExceptionTest() {
|
||||
final AtomicBoolean hasException = new AtomicBoolean(false);
|
||||
final SyncFinisher syncFinisher = new SyncFinisher(10);
|
||||
syncFinisher.addWorker(()->{
|
||||
Console.log(Integer.parseInt("XYZ"));//这里会抛RuntimeException
|
||||
});
|
||||
|
||||
syncFinisher.setExceptionHandler((t, e) -> {
|
||||
hasException.set(true);
|
||||
Assertions.assertEquals("For input string: \"XYZ\"", e.getMessage());
|
||||
});
|
||||
|
||||
syncFinisher.start();
|
||||
syncFinisher.close();
|
||||
ThreadUtil.sleep(300);
|
||||
Assertions.assertTrue(hasException.get());
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user