# Automatic Refactoring Approach for Asynchronous Mechanisms with CompletableFuture
## 4 Empirical Research
\begin{table}
\begin{tabular}{c c c} \hline \hline
**Asynchronous Constructs** & **Count** & **\%** \\ \hline java.lang.Thread & 27,489 & 30.07 \\ java.util.concurrent.Executors & 13,896 & 15.20 \\ java.util.concurrent.ExecutorService & 11,664 & 12.76 \\ java.util.concurrent.Future & 7147 & 7.82 \\ java.util.concurrent.CompleteFuture & 3229 & 3.53 \\ java.util.concurrent.FutureTask & 1833 & 2.01 \\ org.springframework.scheduling.annotation.Async & 1104 & 1.21 \\ com.google.common.util.concurrent.ListenableFuture & 839 & 0.92 \\ org.reactivesstreams.Publisher & 739 & 0.81 \\ javax.swing.SwingWorker & 613 & 0.67 \\ javax.cox.current.Task & 377 & 0.41 \\ java.util.concurrent.ForkJoinTask & 333 & 0.36 \\ io.vertv.core.Future & 262 & 0.29 \\ javax.ws.rs.container.AsyncResponse & 254 & 0.17 \\ io.reactive.r.rjava3.core.Observable & 111 & 0.12 \\ javax.ejb.AsyncResult & 42 & 0.05 \\ akka.dispatch.Futures & 34 & 0.04 \\ javax.enterprise.concurrent.ManagedTask & 34 & 0.04 \\ Projects with asynchronous constructs & 34,492 & 37.74 \\ Total number of projects & 91,403 & 100.00 \\ \hline \hline \end{tabular}
\end{table} 
Table 2: Asynchronously constructed statistics. Executors, being factory classes for thread pools within JUC, indicate the potential use of ExecutorService instances to execute asynchronous tasks. Therefore, projects using Executors, ExecutorService, FutureTask, and Future might all be employing traditional asynchronous constructs. However, CompletableFuture was only used in 3.53% of the projects, indicating it has not yet achieved widespread adoption. RQ2: Does the CompletableFuture construct result in less complex asynchronous tasks compared to traditional asynchronous constructs? As is well known, concurrent programming is a challenging mode of programming [24], and the CompletableFuture class has many member methods. By invoking these methods, multiple asynchronous tasks can be controlled and combined. We are interested in whether this approach helps programmers write less complex asynchronous tasks. We constructed two datasets: Corpus-2, which includes projects with numerous CompletableFuture calls and may also contain traditional asynchronous constructs, and Corpus-3, which solely contains projects with many traditional asynchronous constructs. Both datasets were selected based on the number of stars to ensure representativeness. Corpus-2. On the BOA 2022 Jan/Java dataset, we traversed the AST's method invocation nodes to identify the top 1000 projects with the most calls to CompletableFuture's static methods for submitting asynchronous tasks. Next, we filtered the projects. Using the GitHub API, we obtained the star counts of projects and excluded those with fewer than 1000 stars. We utilized the CodeQL code analysis engine [25] for static analysis to measure asynchronous task metrics. Before analyzing with CodeQL, databases of the projects to be analyzed must be built. GitHub provides CodeQL databases for over 200,000 projects [26]; we prefer using these provided databases. If not available, we attempted to build databases locally from the source code, excluding projects that fail to build, such as Android-related projects that require additional compilation environments. Sorted by the number of CompletableFuture calls, we selected the top 20 projects that were not excluded to form corpus-2, which already contained a sufficient number of CompletableFuture calls. Corpus-3. Using the same method, we identified the top 1000 projects from the BOA dataset that had not used CompletableFuture but had the highest number of calls to the traditional asynchronous constructs' execute and submit methods. Unlike with corpus-2, we relaxed the star count requirement, excluding projects with fewer than 700 stars to include those with relatively more calls in our corpus. Ultimately, we still selected the top 20 un-excluded projects to form corpus-3. Method. We conducted our analysis using CodeQL, which uses a global data flow analysis framework.