انتقل إلى المحتوى
أمين أبوزيد
درس مخطط لهMID-007-L02

شرح الخيوط الافتراضية

  • الدرس 2 من 6
  • Mid-level
في هذا الدرس 4 موضوعات

هذا الدرس مخطط له. يعرض المخطط أدناه الموضوعات التي سيغطيها، ولم يُنشر الدرس الكامل بعد.

نص الدروس والتمارين باللغة الإنجليزية، بينما تبقى واجهة الموقع وعناوين الدروس بالعربية.

في هذا الدرس

describe how virtual threads work and when they help.

الموضوعات المخطط لها

  • A virtual thread is a lightweight thread managed by the JVM, mounted on a small pool of carrier (platform) threads.
  • When it blocks on supported I/O, it unmounts and the carrier runs another virtual thread.
  • Cheap to create: one per task; do not pool them.
  • Create with Thread.ofVirtual().start(r) or Executors.newVirtualThreadPerTaskExecutor().
  • They help blocking I/O workloads; they do not make CPU work faster.
تفاصيل المخطط المبدئي

عرض عملي

java
try (var exec = Executors.newVirtualThreadPerTaskExecutor()) {
    suppliers.forEach(s -> exec.submit(() -> importPrices(s)));
}

اختبر فهمك

Should you pool virtual threads?

أظهر الإجابة

No; create one per task.

التطبيق

طبّق هذا الدرس بمختبر الوحدة وتمارينها واختبارها.

المختبر والتمارين الاختبار

تعليم الدرس كمكتمل اختياري ويمكنك التراجع عنه في أي وقت. يبقى تقدمك محفوظًا في هذا المتصفح.

اكتب للبحث في المستويات والمراحل والوحدات والدروس.