# Automatic Refactoring Approach for Asynchronous Mechanisms with CompletableFuture
## 2 Related Work  
In this section, we first introduce concurrency-related refactoring techniques in the Java domain, then extend the discussion to research on concurrency refactoring in other platforms, and finally discuss the connections between our approach and the related work. A survey revealed that advanced concurrency libraries have not been widely applied [20]. Researchers hope to enhance the quality of existing code through software refactoring techniques, aiming for better utilization of the JUC library. [PERSON] and colleagues [9] introduced an automatic refactoring method and tool, Concurrencer, which uses JUC to refactor sequential code into concurrent code, thereby speeding up program execution. They proposed three types of refactorings: transforming synchronized locks into atomic locks, refactoring HashMap into ConcurrentHashMap, and using the Fork/Join framework for recursive tasks. Subsequently, [PERSON] and others [10] focused on the first two refactorings mentioned above and proposed a refactoring method that combines inter-procedural points-to analysis, achieving better results. In studies related to locks in the JUC library, [PERSON] and his team performed a series of works where they proposed [11] an automated transformation method that combines side-effect analysis and other static analysis techniques at the bytecode level to refactor synchronized locks into ReentrantLock and ReentrantReadWriteLock. Later, they [12] continued their in-depth research and proposed five regular expressions to represent refactoring rules, which can refactor synchronized locks into fine-grained ReentrantReadWriteLocks. In terms of automatically refactoring sequential code into concurrent code, [PERSON] and colleagues [13] conducted further research by statically assessing the number of control flow graph nodes in the bodies of two invoked methods in sequential code; if the counts are similar and there are no dependencies, the two method invocations in the sequential code are submitted to a thread pool for asynchronous execution. As reactive programming concepts gained popularity, [PERSON] and colleagues [4] refactored SwingWorker and ExecutorService constructs to support the RxJava reactive programming library. Addressing the limitations of statically identifying inefficient concurrency patterns, [PERSON] and others [5] combined dynamic analysis to find opportunities to refactor Executor pattern asynchronous code by inlining into synchronous code and using CompletableFuture compositions to release coordinator threads, thus improving the quality of asynchronous code. In research related to concurrency refactoring outside the Java platform, in the C# domain, [PERSON] and others [6] first explored the use of parallel abstractions in C# open-source programs, then presented a refactoring method and tool to transform lower-levelparallel abstractions into higher-level ones, specifically converting Thread and ThreadPool abstractions into Task abstractions and optimizing the use of the Task abstraction. They later [7] researched refactoring C# code from callback-based asynchronous code to using async/await, implementing a refactoring tool. On the Android platform, [PERSON] and colleagues [14] first conducted empirical research on the Android corpus, summarizing the underuse of AsyncTask constructs, leading to the proposal of an automatic refactoring method that extracts long-running operations into AsyncTask. Following this, he [8] addressed the misuse issues of AsyncTask, proposing a method and refactoring tool ASYNCDROID to transform incorrect use of AsyncTask into IntentServices constructs. On the JavaScript platform, [PERSON] and others [15] proposed a method and tool using the async/await keywords combined with static analysis to migrate synchronous APIs to asynchronous APIs.