ThreadPoolExecutor
/*
* <p>Thread pools address two different problems: they usually
* provide improved performance when executing large numbers of
* asynchronous tasks, due to reduced per-task invocation overhead,
* and they provide a means of bounding and managing the resources,
* including threads, consumed when executing a collection of tasks.
* Each {@code ThreadPoolExecutor} also maintains some basic
* statistics, such as the number of completed tasks.
*
* <p>To be useful across a wide range of contexts, this class
* provides many adjustable parameters and extensibility
* hooks. However, programmers are urged to use the more convenient
* {@link Executors} factory methods {@link
* Executors#newCachedThreadPool} (unbounded thread pool, with
* automatic thread reclamation), {@link Executors#newFixedThreadPool}
* (fixed size thread pool) and {@link
* Executors#newSingleThreadExecutor} (single background thread), that
* preconfigure settings for the most common usage
* scenarios.
*/
ThreadPoolExecutor
के स्रोत कोड प्रलेखन से संगामिति को प्राप्त करने का एक तरीका है। समवर्तीता प्राप्त करने में कई तरीके हैं:
Executors ढांचा अलग-अलग एपीआई प्रदान करता है। कुछ महत्वपूर्ण एपीआई नीचे सूचीबद्ध हैं।
static ExecutorService newFixedThreadPool(int nThreads)
एक धागा पूल कि धागे एक साझा असीम कतार बंद ऑपरेटिंग की एक निश्चित संख्या पुनः उपयोग कर लेता बनाता है।
static ExecutorService newCachedThreadPool()
एक थ्रेड पूल है कि नए सूत्र रूप में की जरूरत बनाता है बनाता है, लेकिन पहले से निर्माण धागे का पुन: उपयोग होगा, जब वे उपलब्ध हैं।
static ScheduledExecutorService newScheduledThreadPool(int corePoolSize)
एक थ्रेड पूल है कि किसी भी देरी के बाद चलाने के लिए आदेशों निर्धारित कर सकते हैं या समय-समय पर अमल करने के लिए बनाता है।
static ExecutorService newWorkStealingPool()
एक काम चोरी थ्रेड पूल अपने लक्ष्य समानांतरवाद स्तर के रूप में सभी उपलब्ध प्रोसेसर का उपयोग कर बनाता है।
एसई सवालों के नीचे पर एक नज़र डालें:
java Fork/Join pool, ExecutorService and CountDownLatch
How to properly use Java Executor?
स्रोत
2016-02-29 03:37:16
मेरी समझ है कि रूप में अच्छी तरह। ** स्वतंत्र ** थ्रेड और ** विभाजित/जीत ** दृष्टिकोण के लिए मल्टीथ्रेड के लिए ThreadPoolExecutor का उपयोग करें – gtgaxiola