Concurrent access requires predictability: define who writes, when, and how conflicts are handled. Favor idempotent operations when possible. This covers patterns for safe file sharing, retry mechanisms, and contention management.
1234567891011121301 RETRIES PIC 9 VALUE 0. 01 MAX-RETRIES PIC 9 VALUE 5. 01 WAIT-TIME PIC 9 VALUE 1. PERFORM UNTIL SUCCESS OR RETRIES > MAX-RETRIES ADD 1 TO RETRIES *> attempt I/O here READ CUSTOMER-FILE IF FILE-STATUS = '22' *> record locked PERFORM WAIT-BACKOFF ELSE IF FILE-STATUS = '00' MOVE 'Y' TO SUCCESS END-IF END-PERFORM.
Implement exponential backoff to avoid thundering herds. Start with short waits and increase delay between retries. Log retry attempts for monitoring.
1234*> Use site standard: ENQ/DEQ, or DB locks PERFORM ENTER-CRITICAL PERFORM UPDATE-SHARED-STATE PERFORM LEAVE-CRITICAL.
Protect critical sections with proper locking mechanisms. Keep critical sections short to minimize contention. Always release locks in reverse order of acquisition.
12345678*> Partition by customer ID ranges IF CUSTOMER-ID >= 1 AND CUSTOMER-ID <= 100000 PERFORM PROCESS-PARTITION-1 ELSE IF CUSTOMER-ID >= 100001 AND CUSTOMER-ID <= 200000 PERFORM PROCESS-PARTITION-2 ELSE PERFORM PROCESS-PARTITION-3 END-IF.
Divide work by logical partitions to reduce contention. Each job processes different data ranges, minimizing conflicts. Use consistent partitioning rules across all programs.
123456789IF RETRIES > 0 DISPLAY 'Lock contention: ' RETRIES ' retries for customer ' CUSTOMER-ID ADD RETRIES TO TOTAL-RETRIES END-IF. IF WAIT-TIME > 5 DISPLAY 'Long wait: ' WAIT-TIME ' seconds for resource' ADD 1 TO LONG-WAIT-COUNT END-IF.
Log contention metrics for performance tuning. Track retry counts, wait times, and deadlock occurrences. Use this data to optimize locking strategies and identify bottlenecks.