# Migrating from Developing Asynchronous Multi-Threading Programs to Reactive Programs in Java
## 6 Implementation Details
### Implementation and Management of Components  
The Spring Framework promotes the organization of applications using a component structure, based on the design pattern of Inversion of Control/Dependency Injection [59]. The main benefit of this approach is the simplified management of dependencies and application configurations. The framework defines a set of specific stereotypes, such as _Controller_, _Service_, and _Repository_ by using annotations, to properly differentiate between each of their purposes and functionalities [27]. Figure 4: Migration Process from “javax” to “jakarta” Dependencies. User requests will be received and handled within the controller, which is the main entry point within the application. In terms of code structure and syntax, the differences at this level are minimal, with the only notable difference being the type of data used to return the computed results. The responsibility of aggregating, orchestrating, and performing the application logic belongs to the service component, which is the intermediary of all interactions between the user and the data necessary to fulfill each request. Due to the role carried out by this component, most of the defined code logic is at this level, which makes service migration the main topic under analysis to understand the differences and the necessary adaptation steps in the reactive context. Asynchronous programming structures the flow of the program as chains of asynchronous operations that use the results from the preceding level. _CompletableFuture_ is intended to store both single results from a given level as well as collections of objects. The exposed methods allow for streamlined manipulation and further processing of the results, simplifying the chaining of asynchronous operations [6]. Methods such as _supplyAsync_ and _runAsync_ are used to schedule tasks for execution in a separate thread that will not block the main one, and the result processing steps will be defined using methods such as _thenApply_, to apply a direct transformation to the result when it becomes available, and _thenCompose_, to connect the current operation with another asynchronous operation whose execution depends on the result at the current level. Context switching can be achieved both at the beginning of the operation sequence and between steps using variations such as _thenApplyAsync_, which will not restrict the execution of subsequent steps to be performed on the same thread. In addition, such methods allow the delegation of a specific thread pool to handle the processing by accepting an _ExecutorService_ as a method parameter. The reactive model is fundamentally based on managing tasks as a continuous stream of data, using two fundamental types that encapsulate and allow non-blocking manipulation of the elements. _Mono_ is used to issue at most one element, while _Flux_ can also issue multiple values, and both primitives may also issue no elements at all. The data is processed in a functional style by applying a series of transforming, filtering, or combining operators to the output streams. For scenarios requiring the transformation of each element within the stream into a different shape or format, the conversion or transformer function is applied to each element available in the stream using the _map_ operator, while _flatMap_ allows the application of a function that issues, in turn, another reactive data stream, the computation of which is dependent on the previous result, thereby also \"flattening\" the resulting stream in the process. In certain situations where data streams may not output any elements, a default value or an error can be specified using operators such as _switchIfEmpty_, while combining elements of the same stream can be achieved by applying a function using the _reduce_ operator. Excluding certain elements that do not fulfill specific processing conditions can be accomplished by applying a function that tests compliance with these conditions using the _filter_ operator.