Advanced
Thread-Safe Legacy Code Refactoring
Refactor a provided monolithic legacy code snippet to eliminate race conditions and deadlocks while maintaining backward compatibility.
📝 プロンプトの内容
Analyze the following hypothetical legacy Java code snippet that manages a shared inventory counter. Identify all potential race conditions and deadlock scenarios. Propose a refactored solution using modern concurrency utilities (such as java.util.concurrent) that ensures thread safety without sacrificing performance. Additionally, explain how you would unit test the concurrency aspects of your solution.