Advanced
Thread-Safe Singleton Factory Refactoring
Refactor a legacy class into a thread-safe Singleton using the Double-Checked Locking pattern.
📝 Prompt Inhoud
Analyze the provided legacy Java class which manages database connections. Identify thread-safety issues and violations of the Single Responsibility Principle. Refactor the class to implement the Singleton design pattern using the Double-Checked Locking mechanism to ensure high performance in a multi-threaded environment. Additionally, extract the connection creation logic into a Factory pattern. Provide the refactored code with detailed comments explaining the memory visibility implications of the 'volatile' keyword used in the context.