مجمّعات الخيوط: الحجم والطابور والرفض
في هذا الدرس 4 موضوعات
هذا الدرس مخطط له. يعرض المخطط أدناه الموضوعات التي سيغطيها، ولم يُنشر الدرس الكامل بعد.
نص الدروس والتمارين باللغة الإنجليزية، بينما تبقى واجهة الموقع وعناوين الدروس بالعربية.
في هذا الدرس
size a pool and predict its queueing behavior.
الموضوعات المخطط لها
ThreadPoolExecutor: core size, max size, queue, rejection policy.- Order of growth: use core threads, then enqueue, and only add threads up to max when the queue is full. An unbounded queue means max is never used.
- CPU-bound: about the number of cores. I/O-bound: more, roughly cores x (1 + wait/compute); measure.
- Use a bounded queue plus an explicit rejection policy (e.g., caller-runs, or abort and report) to create backpressure.
newCachedThreadPoolhas unbounded threads;newFixedThreadPoolhas an unbounded queue. Both can hurt under load.
تفاصيل المخطط المبدئي
عرض عملي
new ThreadPoolExecutor(8, 8, 0, TimeUnit.SECONDS,
new ArrayBlockingQueue<>(100), new ThreadPoolExecutor.CallerRunsPolicy());اختبر فهمك
With core 8, max 32, and an unbounded queue, how many threads run?
أظهر الإجابة
8; the queue never fills.
التطبيق
طبّق هذا الدرس بمختبر الوحدة وتمارينها واختبارها.
تعليم الدرس كمكتمل اختياري ويمكنك التراجع عنه في أي وقت. يبقى تقدمك محفوظًا في هذا المتصفح.