기본 질문 일 수 있지만이 포럼에서 확인을 얻고 싶습니다.동기화 된 블록 내에서 새 스레드 시작
public Object method1() {
synchronized(this) {
method2();
method3();
method4();
}
method4()
은 시간이 많이 소요 내가이 완료 기다릴 필요가 없습니다 :
public Object invoke(MethodInvocation methodInvocation) throws Throwable {
Future<Object> future = executorService.submit(new AsyncCallable(
methodInvocation));
Object retVal = null;
try {
retVal = future.get(10, TimeUnit.SECONDS);
} catch (Exception e) {
logger.error("Exception while running the method Async", e);
throw e;
}
return retVal;
} //AsyncCallable implements Callable interface
다른 스레드에서 시작하지만 즉시 기다리지 않습니까? – Gray
이것은 쉽게 실행할 수 있고 어떤 일이 발생하는지 볼 수 있습니다. 시도 해봐! –
확인. 나는 method4()를 무한 루프에서 실행시켜 보았고 10 초 후에 타임 아웃했다. [나의 타임 아웃 한도]. 그래서 method1()은 쓰레드가 실행을 완료 할 때까지 기다린다. 나는 코드에서 무엇이 잘못되었는지 알지 못한다. 스레드를 비동기로 만들 수 있습니까? – gad