글쎄 제목이 무엇입니까? Executors.newSingleThreadExecutor().execute(command)
과 new Thread(command).start();
Executors.newSingleThreadExecutor(). execute (명령)와 new Thread (명령)의 차이점 .start();
답변
의 차이점은 무엇입니까?
일단 인스턴스가 생기면 Executor
인스턴스를 여러 개 제출하여 차례대로 실행할 수 있습니다. 당신은 원시 Thread
으로 간단히 할 수 없습니다. 실행 가능한이 완료되면 당신이 new Thread(someRunnable).start();
를 실행할 때 오류 또는 RuntimeException을이이 자동으로 삼켜됩니다 집행 인에 던져 경우
, 새로운 스레드()
하나 개 눈에 띄는 차이를 System.err에 인쇄 할 것입니다 실은 조용히 죽을 것이다.
Executor는 종료 할 때까지 지속됩니다. 따라서 실행 중 Executors.newSingleThreadExecutor().execute(command)
응용 프로그램이나 JVM이 완료되었다고 생각되면 Executor가 백그라운드 스레드에서 실행 중일 수 있습니다.
Executors.newSingleThreadExecutor(). execute (command)는 이전에 생성 된 스레드를 재사용합니다. 새 Thread()의 경우처럼 새 스레드를 생성하지 않습니다. 60 초 동안 사용되지 않은 스레드가 종료 된 경우 해당 스레드는 newFixedThreadPool (1)과 동일한 종류의 풀입니다.
한 자리 스레드의 경우에도 ExecutorService
또는 ThreadPoolExecutor
을 사용하는 것을 선호합니다. 그들은 더 많은 유연성을 제공합니다.
java Fork/Join pool, ExecutorService and CountDownLatch
Java's Fork/Join vs ExecutorService - when to use which?
은 당신이 당신의 자신의 스레드 대신 ExecutorService
시작했다고 가정 :
ExecutorService
&
ThreadPoolExecutor
섹션에서보세요. 앞으로 다중 스레드를 지원해야 할 필요가 있다면
ExecutorService
또는
ThreadPoolExecutor
이 더 나은 제어 및 유연성을 제공 할 것입니다. 아래 API에서 필요한 수의 매개 변수를 미세 조정할 수 있습니다.
ThreadPoolExecutor(int corePoolSize, int maximumPoolSize, long keepAliveTime,
TimeUnit unit, BlockingQueue<Runnable> workQueue, ThreadFactory threadFactory,
RejectedExecutionHandler handler)
- 1. lcdui와 lwuit 명령의 차이점
- 2. thread 후의 콜백 .Start()가 끝났습니까?
- 3. thread.start()와 executor.submit (thread)의 차이점
- 4. 화석 dvcs 업데이트와 체크 아웃 명령의 차이점
- 5. MyClass.prototype = new Object()와 MyClass.prototype = Object의 차이점
- 6. 사용 방법 Thread inside Thread with ThreadSafty
- 7. Executors.newSingleThreadExecutor()의 종료 전략은 무엇입니까
- 8. Boost.Thread 또는 thread :: thread?
- 9. Executors.newSingleThreadExecutor() - 대기열에있는 작업 수를 확인하는 방법
- 10. Android - ProgressDialogs 및 Thread
- 11. jquery synchronous execute
- 12. LINQ : 'Select c'와 'Select new (c ...')의 차이점
- 13. Delphi/ADO : Execute()의 결과를 얻는 방법?
- 14. Execute public String
- 15. 파이썬 오류 : execute() first
- 16. T-SQL DENY EXECUTE
- 17. Execute Command and Now()
- 18. Thread 객체의 같은 인스턴스에서 start 메서드를 두 번 호출 할 수없는 이유는 무엇입니까?
- 19. Touchevent의 android thread/handler
- 20. Thread and Form.Show()
- 21. Android Thread Exception?
- 22. 이것은 thread-safe 코드입니까?
- 23. STA thread in windowapplication
- 24. Java Thread Good Practice this?
- 25. BeginInvoke와 Thread.Start의 차이점
- 26. RoutedCommands Execute 및 PreviewExecuted 이벤트
- 27. Background thread in C#
- 28. nm와 objdump의 차이점
- 29. C++ new/new [], 어떻게 메모리를 할당합니까?
- 30. NSURLConnection start + autorelease
오 그래, 그건 생각조차하지 않았다. 감사. –