달력

2

« 2025/2 »

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28

'JAVA이야기'에 해당되는 글 119

  1. 2011.09.24 Future클래스와 ExecutorService
2011. 9. 24. 16:48

Future클래스와 ExecutorService JAVA이야기2011. 9. 24. 16:48

ExecutorService exec = Executors.newSingleThread(new FactoryThread());
Future<T> f = exec.submit(Callable<T> call);
T result = f.get();

callable과 runnable의 차이점
T callable()
void runnable()
callable은 리턴값이 있고, runnable은 리턴값이 없다.

exec는 queue를 가지고 있다.
exec.sumbit()은 스레드를 queue에 넣는다.
이 스레드는 언제실행될 지 모른다. 그래서 이 스레드의 결과값에 대한 정보를 저장하기 위해 Future클래스라고 명명
f.get() 메소드를 호출하면 Callable의 작업이 실행될 때까지 블로킹되며, 완료되면 리턴한다. 
즉 리턴값을 뱉을때까지 기다린다라는 뜻.


 

'JAVA이야기' 카테고리의 다른 글

Semaphore와 CountDownLatch  (0) 2011.09.26
ReentrantLock  (0) 2011.09.26
집중 대응 정책  (0) 2011.09.19
ThreadPoolExecutor  (0) 2011.09.19
[ThreadPool] 오래실행되는 작업  (0) 2011.09.19
:
Posted by НooпeУ


Code Start Code End