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

عرض عملي: فخ سجل التدقيق مع REQUIRES_NEW

  • الدرس 7 من 7
  • Mid-level
في هذا الدرس 3 موضوعات

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

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

في هذا الدرس

show how REQUIRES_NEW interacts with pool size and rollbacks.

تفاصيل المخطط المبدئي

خطوة بخطوة

  1. An OrderService.place calls AuditService.log annotated REQUIRES_NEW so the audit row survives order failure.
  2. Show it works: order fails, audit row persists.
  3. Set pool size to 2 and run 5 concurrent requests: each holds one connection and waits for a second; threads time out (pool deadlock).
  4. Planned mistake: call the audit method from within the same class; no new transaction starts (proxy bypass). Fix: move it to another bean.
  5. Fix the pool problem: record audit events after commit (@TransactionalEventListener(AFTER_COMMIT) or an outbox table) instead of nesting.

اختبر فهمك

What is a safer way to keep an audit row independent of the order outcome?

أظهر الإجابة

Write it outside the outer transaction, for example after commit or via an outbox.

التطبيق

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

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

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

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