블럭킹 | 논블럭킹 | 동기 | 비동기
Blocking | Non Blocking | Sync | Async 에 대해 알아보자
Last updated
@GetMapping("sync-nonblock")
public void syncNonBlock(){
ExecutorService service = Executors.newSingleThreadExecutor();
Callable<String> task = new Callable<String>() {
@Override
public String call() throws Exception {
try {
Thread.sleep(3000);
} catch (InterruptedException e) {
e.printStackTrace();
}
logger.info("BlockController.syncNonBlock.call");
return "Future Done!!";
}
};
Future<String> future = service.submit(task);
try {
logger.info("BlockController.syncNonBlock.main");
String futureResult = future.get();
System.out.println("futureResult: " + futureResult);
} catch (Exception e) {
// Exception Handling
}
}public void asyncBlock(){
blockService.async();
logger.info("BlockController.asyncBlock");
}
@Async
public void async(){
try {
Thread.sleep(3000);
} catch (InterruptedException e) {
e.printStackTrace();
}
logger.info("BlockService.async");
secondBlockService.async();
}