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

إعادة محاولة المعاملات بأمان

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

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

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

في هذا الدرس

retry transient failures without causing duplicates.

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

  • Retry only transient errors: serialization failure, deadlock, optimistic lock conflict.
  • Retry the whole transaction, outside the transactional method (a new transaction per attempt).
  • Limit attempts and add backoff with jitter.
  • Make the unit of work idempotent (unique request key, upsert) or retries can double-charge.
  • Spring Retry or Resilience4j can wrap the call.
تفاصيل المخطط المبدئي

عرض عملي

java
for (int attempt = 1; ; attempt++) {
  try { return tx.execute(s -> placeOrder(cmd)); }
  catch (TransientDataAccessException e) {
    if (attempt == 3) throw e;
    sleep(backoff(attempt));
  }
}

اختبر فهمك

Why must the retry loop be outside the transaction?

أظهر الإجابة

Each attempt needs a fresh transaction; the failed one is dead.

التطبيق

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

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

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

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