عرض عملي: فخ سجل التدقيق مع REQUIRES_NEW
في هذا الدرس 3 موضوعات
هذا الدرس مخطط له. يعرض المخطط أدناه الموضوعات التي سيغطيها، ولم يُنشر الدرس الكامل بعد.
نص الدروس والتمارين باللغة الإنجليزية، بينما تبقى واجهة الموقع وعناوين الدروس بالعربية.
في هذا الدرس
show how REQUIRES_NEW interacts with pool size and rollbacks.
تفاصيل المخطط المبدئي
خطوة بخطوة
- An
OrderService.placecallsAuditService.logannotatedREQUIRES_NEWso the audit row survives order failure. - Show it works: order fails, audit row persists.
- Set pool size to 2 and run 5 concurrent requests: each holds one connection and waits for a second; threads time out (pool deadlock).
- Planned mistake: call the audit method from within the same class; no new transaction starts (proxy bypass). Fix: move it to another bean.
- 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.
التطبيق
طبّق هذا الدرس بمختبر الوحدة وتمارينها واختبارها.
تعليم الدرس كمكتمل اختياري ويمكنك التراجع عنه في أي وقت. يبقى تقدمك محفوظًا في هذا المتصفح.