{"id":119967,"date":"2023-09-22T23:05:27","date_gmt":"2023-09-22T20:05:27","guid":{"rendered":"https:\/\/examples.javacodegeeks.com\/?p=119967"},"modified":"2023-09-22T23:05:29","modified_gmt":"2023-09-22T20:05:29","slug":"comparing-java-future-completablefuture-and-rxjava-observable","status":"publish","type":"post","link":"https:\/\/examples.javacodegeeks.com\/comparing-java-future-completablefuture-and-rxjava-observable\/","title":{"rendered":"Comparing Java Future, CompletableFuture and Rxjava Observable"},"content":{"rendered":"<p>Future, CompletableFuture, and <a href=\"https:\/\/github.com\/ReactiveX\/RxJava\" target=\"_blank\" rel=\"noreferrer noopener\">RxJava<\/a> observable are mechanisms for handling asynchronous and reactive programming in Java, but they have different characteristics and use cases. In this article, we will explore the key differences between these three constructs and provide code examples to illustrate the differences between them.<\/p>\n<h2 class=\"wp-block-heading\">1. Observable from RxJava<\/h2>\n<p>RxJava is a library used for reactive programming in Java. RxJava <code>Observable<\/code> allows Java developers to work with asynchronous and event-driven code in an organized and declarative manner. It is a concept used to represent a stream of data or events that can be observed by multiple subscribers. An <code>Observable<\/code> emits items over time, and you can subscribe to it to receive those items.<\/p>\n<h3 class=\"wp-block-heading\">1.1 Key Points about Observable in RxJava<\/h3>\n<p>Below are some key points to understand about <code>Observable<\/code> in RxJava.<\/p>\n<ul class=\"wp-block-list\">\n<li><strong>Data or Event Stream<\/strong>: An <code>Observable<\/code> represents a sequence of data items or events that can be emitted over time. These items can be of any data type that can be emitted one at a time or in a batch.<\/li>\n<li><strong>Producer of Data<\/strong>: An <code>Observable<\/code> acts as the source of the data stream. It is the producer of data or events, and it can emit these items to one or more subscribers. <\/li>\n<li><strong>Lazy Execution<\/strong>: An <code>Observable<\/code> is lazy by default. This means that it doesn&#8217;t start emitting items until a subscriber subscribes to it which allows for efficient resource management.<\/li>\n<li><strong>Subscription<\/strong>: Subscribers can subscribe to an <code>Observable<\/code> to receive the emitted items or events. When a subscriber subscribes, it establishes a connection with the <code>Observable<\/code> and starts receiving data.<\/li>\n<li><strong>Error Handling<\/strong>: If an error occurs during the emission of items, an <code>Observable<\/code> can emit an <code>onError<\/code> signal that allows subscribers to handle errors in a refined manner.<\/li>\n<\/ul>\n<h3 class=\"wp-block-heading\">1.2 Example of Using an Observable in RxJava<\/h3>\n<p>To use RxJava&#8217;s <code>Observable<\/code>, First, include the RxJava library in your project by adding the necessary dependencies to your project&#8217;s build file. In a maven-based project, we can include RxJava in our <code>pom.xml<\/code> like this: <\/p>\n<pre class=\"brush:xml\">\n    &lt;dependencies&gt;\n        &lt;dependency&gt;\n            &lt;groupId&gt;io.reactivex.rxjava3&lt;\/groupId&gt;\n            &lt;artifactId&gt;rxjava&lt;\/artifactId&gt;\n            &lt;version&gt;3.1.6&lt;\/version&gt;\n        &lt;\/dependency&gt;\n    &lt;\/dependencies&gt;\n<\/pre>\n<p>Below is an example of how we can create and use an <code>Observable<\/code> in RxJava.<\/p>\n<pre class=\"brush:java\">\npublic class ObservableExample {\n\n    public static void main(String[] args) {\n        \n        \/\/ Create an Observable that emits a sequence of some great authors\n        Observable observable = Observable.create(emitter -&gt; {\n            emitter.onNext(\"Charles Dickens\");\n            emitter.onNext(\"Jonathan Swift\");\n            emitter.onNext(\"Chinua Achebe\");\n            emitter.onNext(\"William Shakespear\");\n            emitter.onNext(\"Thomas Paine\");\n            emitter.onComplete(); \/\/ Indicates that the observable has completed\n        });\n\n        \/\/ Create an Observer to subscribe to the Observable\n        Observer observer = new Observer() {\n            @Override\n            public void onSubscribe(Disposable d) {\n                System.out.println(\"Subscribed to the Observable.\");\n            }\n\n            @Override\n            public void onNext(String value) {\n                System.out.println(\"Received: \" + value);\n            }\n\n            @Override\n            public void onError(Throwable e) {\n                System.err.println(\"Error: \" + e.getMessage());\n            }\n\n            @Override\n            public void onComplete() {\n                System.out.println(\"Observable completed.\");\n            }\n        };\n\n        \/\/ Subscribe the Observer to the Observable\n        observable.subscribe(observer);\n    }\n}\n<\/pre>\n<p>In the above example, We create an <code>Observable<\/code> named <code>observable<\/code> using the <code>Observable.create()<\/code> method. Inside the <code>create<\/code> block, we manually emit five String values of some great authors using the <code>emitter.onNext()<\/code> method and then signal that the observable has completed using <code>emitter.onComplete()<\/code>.<div style=\"display:inline-block; margin: 15px 0;\"> <div id=\"adngin-JavaCodeGeeks_incontent_video-0\" style=\"display:inline-block;\"><\/div> <\/div><\/p>\n<p>Next, we created a <code>Observer<\/code> named <code>observer<\/code> that defined how we handled the emitted values and completion and error events. The <code>onSubscribe<\/code> method is called when the observer subscribes to the observable. Finally, We subscribed the <code>observer<\/code> to the <code>observable<\/code> using the <code>observable.subscribe(observer)<\/code> method. When we run this code, we will see the following output:<\/p>\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><a href=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2023\/09\/observable.png\"><img decoding=\"async\" width=\"534\" height=\"181\" src=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2023\/09\/observable.png\" alt=\"Fig 1. The output of running rxjava's Observable example in Java\" class=\"wp-image-120096\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2023\/09\/observable.png 534w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2023\/09\/observable-300x102.png 300w\" sizes=\"(max-width: 534px) 100vw, 534px\" \/><\/a><figcaption class=\"wp-element-caption\">Fig 1. The output of running rxjava&#8217;s Observable example<\/figcaption><\/figure>\n<\/div>\n<h2 class=\"wp-block-heading\">2. Future Interface<\/h2>\n<p>The <a href=\"https:\/\/examples.javacodegeeks.com\/java-futuretask-example\/\" target=\"_blank\" rel=\"noreferrer noopener\">Future<\/a> interface is part of the <code>java.util.concurrent<\/code> package and provides a way to work with computations that run concurrently or asynchronously, without blocking the main thread. The Future interface was introduced in Java 5 (Java 1.5) as part of the Java Concurrency. One of the most common implementations of the Future interface is the <code>java.util.concurrent.FutureTask<\/code> class, used to wrap callable tasks and execute them concurrently. The Future does not offer a built-in mechanism to handle callback functions or notifications upon completion. <\/p>\n<h3 class=\"wp-block-heading\">2.1 Key Aspects of the Future Interface <\/h3>\n<p>Here are some of the key aspects of the Future Interface in Java:<\/p>\n<ul class=\"wp-block-list\">\n<li><strong>Representation of a Computation<\/strong>: The primary purpose of the <code>Future<\/code> interface is to represent a task that is running asynchronously. This task can be any operation that might take some time to complete, such as database queries or complex calculations.<\/li>\n<li><strong>Non-blocking<\/strong>: The <code>Future<\/code> interface allows developers to initiate a task and then continue with other tasks or operations without waiting for the original task to finish. <\/li>\n<li><strong>Querying Task Status<\/strong>: The <code>Future<\/code> interface provides methods for checking the status of the associated task. You can use methods like <code>isDone()<\/code> to check if the task has been completed or <code>isCancelled()<\/code> method to see if it has been canceled.<\/li>\n<li><strong>Retrieving the Result<\/strong>: The <code>Future<\/code> interface allows you to retrieve the result of a computation once it&#8217;s complete. <\/li>\n<li><strong>Timeout Handling<\/strong>: The <code>Future<\/code> interface allows you to specify a maximum amount of time to wait for a computation to complete. If the task isn&#8217;t completed within the specified time, a <code>TimeoutException<\/code> is thrown.<\/li>\n<\/ul>\n<h3 class=\"wp-block-heading\">2.2 Example of Using the Future Interface<\/h3>\n<p>Below is a basic example of how to use the Future Interface in Java to perform asynchronous computations using the <code>ExecutorService<\/code>:<\/p>\n<pre class=\"brush:java\">\n\npublic class FutureExample {\n\n   public static void main(String[] args) {\n        \/\/ Create an ExecutorService with a single thread\n        ExecutorService executorService = Executors.newSingleThreadExecutor();\n\n        \/\/ Submit a task to the ExecutorService\n        Future future = executorService.submit(() -&gt; {\n            Thread.sleep(1000); \/\/ Simulate a time-consuming operation\n            return 9; \/\/ The result of the computation\n        });\n\n        \/\/ Continue with other tasks while the above task is running\n\n        \/\/ Check if the task is done\n        if (future.isDone()) {\n            try {\n                \/\/ Retrieve the result when the task is complete\n                Integer result = future.get();\n                System.out.println(\"Task completed. Result: \" + result);\n            } catch (InterruptedException | ExecutionException e) {\n                e.printStackTrace();\n            }\n        } else {\n            System.out.println(\"Task is not yet complete. Continuing with other tasks...\");\n        }\n\n        \/\/ Shutdown the ExecutorService when done\n        executorService.shutdown();\n    }\n}\n\n\n<\/pre>\n<p>In this example, we create an <code>ExecutorService<\/code> with a single thread using <code>Executors.newSingleThreadExecutor()<\/code> responsible for running our asynchronous task. we submit a task to the <code>ExecutorService<\/code> using the <code>submit()<\/code> method defined as a lambda that sleeps for 1 second and then returns the integer value 9 as a result.<\/p>\n<p>After submitting the task, we can continue with other tasks without waiting for it to complete. We use the <code>isDone()<\/code> method to check if the task is complete. If it is, we use the <code>get()<\/code> method to retrieve the result. If the task is not yet complete, we print a message indicating that and continue with other tasks. Finally, we shut down the <code>ExecutorService<\/code> to release its resources.<\/p>\n<h2 class=\"wp-block-heading\">3. The CompletableFuture Class<\/h2>\n<p><code>CompletableFuture<\/code> class is used for managing asynchronous tasks in modern Java applications. It was introduced in Java 8 as part of the Java Concurrency framework in the <code>java.util.concurrent<\/code> package. The <code>CompletableFuture<\/code> class is used to hold a value that may not be available yet. This value can be a result of a computation or an exception that occurred during the computation.<\/p>\n<h3 class=\"wp-block-heading\">3.1 Key Features of CompletableFuture <\/h3>\n<p>Listed below are some key features associated with the <code>CompletableFuture<\/code> class:<\/p>\n<ul class=\"wp-block-list\">\n<li><strong>Asynchronous Computation<\/strong>: <code>CompletableFuture<\/code> is used for tasks that can run asynchronously, without blocking the main thread of your program.<\/li>\n<li><strong>Chaining<\/strong> <strong>Operations<\/strong>: <code>CompletableFuture<\/code> has the ability to chain multiple asynchronous operations together. Developers can specify what should happen when a previous <code>CompletableFuture<\/code> completes using methods like <code>thenApply<\/code>, <code>thenCompose<\/code>, <code>thenCombine<\/code>, and more. <\/li>\n<li><strong>Exception Handling<\/strong>: <code>CompletableFuture<\/code> provides methods for handling exceptions that may occur when performing asynchronous tasks, such as <code>exceptionally<\/code>, <code>handle<\/code>, and <code>exceptionallyCompose<\/code>.<\/li>\n<\/ul>\n<h3 class=\"wp-block-heading\">3.2 Example of Using a CompletableFuture<\/h3>\n<p>Below is a simple example of how to use <code>CompletableFuture<\/code> in Java to perform asynchronous operations:<\/p>\n<pre class=\"brush:java\">\npublic class CompletableFutureExample {\n\n    public static void main(String[] args) {\n        CompletableFuture future = CompletableFuture.supplyAsync(() -&gt; 42); \/\/ Asynchronously compute 42\n\n        future.thenApply(result -&gt; result * 2) \/\/ Double the result\n                .thenAccept(finalResult -&gt; System.out.println(\"Result: \" + finalResult))\n                .exceptionally(ex -&gt; {\n                    System.err.println(\"Exception: \" + ex);\n                    return null;\n                });\n        \n\/\/ Wait for the CompletableFuture to complete\n        try {\n            future.join(); \/\/ Block until the CompletableFuture is done\n        } catch (Exception e) {\n            e.printStackTrace();\n        }\n        \n        System.out.println(\"Main thread continues to execute other tasks...\");\n    }\n}\n<\/pre>\n<p>In the above example, we create a <code>CompletableFuture<\/code> that asynchronously computes the value 42 and then chain it to double the result and print it. We used <code>future.join()<\/code> to block the main thread and wait for the <code>CompletableFuture<\/code> to complete which is not recommended in production code as it can block the main thread.<\/p>\n<h2 class=\"wp-block-heading\">4. Conclusion<\/h2>\n<p>In this article, we listed some of the key features of Future, CompletableFuture and RxJava Observable. We also showed some basic usage and examples of how to execute tasks concurrently using Future, CompletableFuture and RxJava Observable.<\/p>\n<p>In conclusion, understanding the differences between Future, CompletableFuture and RxJava Observable is crucial for effective asynchronous programming in Java. The choice between these tools depends on the requirements of your application. Use Observables when dealing with complex event-driven scenarios, Futures for simple asynchronous tasks, and CompletableFuture for more control and flexibility in managing asynchronous operations. <\/p>\n<h2 class=\"wp-block-heading\">5. Download the Source Code<\/h2>\n<p>This was an example of the difference Between Rxjava&#8217;s Observable, Future, and CompletableFuture in Java.<\/p>\n<div class=\"download\"><strong>Download<\/strong><br \/>\nYou can download the full source code of this example here: <a href=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2023\/09\/Observable_Completable_Future_Examples.zip\"><strong>Difference Between Rxjava&#8217;s Observable, Future, and CompletableFuture<\/strong><\/a><\/div>\n","protected":false},"excerpt":{"rendered":"<p>Future, CompletableFuture, and RxJava observable are mechanisms for handling asynchronous and reactive programming in Java, but they have different characteristics and use cases. In this article, we will explore the key differences between these three constructs and provide code examples to illustrate the differences between them. 1. Observable from RxJava RxJava is a library used &hellip;<\/p>\n","protected":false},"author":252,"featured_media":94233,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[721,46997,1492,46996,46995],"class_list":["post-119967","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-core-java","tag-java-concurrency","tag-java-streams","tag-multithreading","tag-reactive-programming","tag-rxjava"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Comparing Java Future, CompletableFuture and Rxjava Observable - Java Code Geeks<\/title>\n<meta name=\"description\" content=\"Explore the distinctions between future, completablefuture, and rxjava&#039;s observable in Java, comparing their usage and benefits.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/examples.javacodegeeks.com\/comparing-java-future-completablefuture-and-rxjava-observable\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Comparing Java Future, CompletableFuture and Rxjava Observable - Java Code Geeks\" \/>\n<meta property=\"og:description\" content=\"Explore the distinctions between future, completablefuture, and rxjava&#039;s observable in Java, comparing their usage and benefits.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/examples.javacodegeeks.com\/comparing-java-future-completablefuture-and-rxjava-observable\/\" \/>\n<meta property=\"og:site_name\" content=\"Examples Java Code Geeks\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/javacodegeeks\" \/>\n<meta property=\"article:author\" content=\"https:\/\/web.facebook.com\/omos.aziegbe\" \/>\n<meta property=\"article:published_time\" content=\"2023-09-22T20:05:27+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-09-22T20:05:29+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2020\/09\/java-logo.png\" \/>\n\t<meta property=\"og:image:width\" content=\"225\" \/>\n\t<meta property=\"og:image:height\" content=\"225\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Omozegie Aziegbe\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@https:\/\/twitter.com\/OAziegbe\" \/>\n<meta name=\"twitter:site\" content=\"@javacodegeeks\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Omozegie Aziegbe\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"6 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/comparing-java-future-completablefuture-and-rxjava-observable\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/comparing-java-future-completablefuture-and-rxjava-observable\/\"},\"author\":{\"name\":\"Omozegie Aziegbe\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/53e9141bb43ca17cd84b5ab586ca5199\"},\"headline\":\"Comparing Java Future, CompletableFuture and Rxjava Observable\",\"datePublished\":\"2023-09-22T20:05:27+00:00\",\"dateModified\":\"2023-09-22T20:05:29+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/comparing-java-future-completablefuture-and-rxjava-observable\/\"},\"wordCount\":1157,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#organization\"},\"image\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/comparing-java-future-completablefuture-and-rxjava-observable\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2020\/09\/java-logo.png\",\"keywords\":[\"Java Concurrency\",\"Java Streams\",\"multithreading\",\"Reactive Programming\",\"RxJava\"],\"articleSection\":[\"Core Java\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/examples.javacodegeeks.com\/comparing-java-future-completablefuture-and-rxjava-observable\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/comparing-java-future-completablefuture-and-rxjava-observable\/\",\"url\":\"https:\/\/examples.javacodegeeks.com\/comparing-java-future-completablefuture-and-rxjava-observable\/\",\"name\":\"Comparing Java Future, CompletableFuture and Rxjava Observable - Java Code Geeks\",\"isPartOf\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/comparing-java-future-completablefuture-and-rxjava-observable\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/comparing-java-future-completablefuture-and-rxjava-observable\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2020\/09\/java-logo.png\",\"datePublished\":\"2023-09-22T20:05:27+00:00\",\"dateModified\":\"2023-09-22T20:05:29+00:00\",\"description\":\"Explore the distinctions between future, completablefuture, and rxjava's observable in Java, comparing their usage and benefits.\",\"breadcrumb\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/comparing-java-future-completablefuture-and-rxjava-observable\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/examples.javacodegeeks.com\/comparing-java-future-completablefuture-and-rxjava-observable\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/comparing-java-future-completablefuture-and-rxjava-observable\/#primaryimage\",\"url\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2020\/09\/java-logo.png\",\"contentUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2020\/09\/java-logo.png\",\"width\":225,\"height\":225,\"caption\":\"anonymous class in java\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/comparing-java-future-completablefuture-and-rxjava-observable\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/examples.javacodegeeks.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Java Development\",\"item\":\"https:\/\/examples.javacodegeeks.com\/category\/java-development\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Core Java\",\"item\":\"https:\/\/examples.javacodegeeks.com\/category\/java-development\/core-java\/\"},{\"@type\":\"ListItem\",\"position\":4,\"name\":\"Comparing Java Future, CompletableFuture and Rxjava Observable\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#website\",\"url\":\"https:\/\/examples.javacodegeeks.com\/\",\"name\":\"Java Code Geeks\",\"description\":\"Java Examples and Code Snippets\",\"publisher\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#organization\"},\"alternateName\":\"JCG\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/examples.javacodegeeks.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#organization\",\"name\":\"Exelixis Media P.C.\",\"url\":\"https:\/\/examples.javacodegeeks.com\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png\",\"contentUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png\",\"width\":864,\"height\":246,\"caption\":\"Exelixis Media P.C.\"},\"image\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/javacodegeeks\",\"https:\/\/x.com\/javacodegeeks\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/53e9141bb43ca17cd84b5ab586ca5199\",\"name\":\"Omozegie Aziegbe\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2023\/05\/cropped-jcg_profile_pic-96x96.jpg\",\"contentUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2023\/05\/cropped-jcg_profile_pic-96x96.jpg\",\"caption\":\"Omozegie Aziegbe\"},\"description\":\"Omos holds a Master degree in Information Engineering with Network Management from the Robert Gordon University, Aberdeen. Omos is currently a freelance web\/application developer who is currently focused on developing Java enterprise applications with the Jakarta EE framework.\",\"sameAs\":[\"https:\/\/web.facebook.com\/omos.aziegbe\",\"https:\/\/www.linkedin.com\/in\/omosaziegbe\/\",\"https:\/\/x.com\/https:\/\/twitter.com\/OAziegbe\"],\"url\":\"https:\/\/examples.javacodegeeks.com\/author\/omozegie-aziegbe\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Comparing Java Future, CompletableFuture and Rxjava Observable - Java Code Geeks","description":"Explore the distinctions between future, completablefuture, and rxjava's observable in Java, comparing their usage and benefits.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/examples.javacodegeeks.com\/comparing-java-future-completablefuture-and-rxjava-observable\/","og_locale":"en_US","og_type":"article","og_title":"Comparing Java Future, CompletableFuture and Rxjava Observable - Java Code Geeks","og_description":"Explore the distinctions between future, completablefuture, and rxjava's observable in Java, comparing their usage and benefits.","og_url":"https:\/\/examples.javacodegeeks.com\/comparing-java-future-completablefuture-and-rxjava-observable\/","og_site_name":"Examples Java Code Geeks","article_publisher":"https:\/\/www.facebook.com\/javacodegeeks","article_author":"https:\/\/web.facebook.com\/omos.aziegbe","article_published_time":"2023-09-22T20:05:27+00:00","article_modified_time":"2023-09-22T20:05:29+00:00","og_image":[{"width":225,"height":225,"url":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2020\/09\/java-logo.png","type":"image\/png"}],"author":"Omozegie Aziegbe","twitter_card":"summary_large_image","twitter_creator":"@https:\/\/twitter.com\/OAziegbe","twitter_site":"@javacodegeeks","twitter_misc":{"Written by":"Omozegie Aziegbe","Est. reading time":"6 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/examples.javacodegeeks.com\/comparing-java-future-completablefuture-and-rxjava-observable\/#article","isPartOf":{"@id":"https:\/\/examples.javacodegeeks.com\/comparing-java-future-completablefuture-and-rxjava-observable\/"},"author":{"name":"Omozegie Aziegbe","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/53e9141bb43ca17cd84b5ab586ca5199"},"headline":"Comparing Java Future, CompletableFuture and Rxjava Observable","datePublished":"2023-09-22T20:05:27+00:00","dateModified":"2023-09-22T20:05:29+00:00","mainEntityOfPage":{"@id":"https:\/\/examples.javacodegeeks.com\/comparing-java-future-completablefuture-and-rxjava-observable\/"},"wordCount":1157,"commentCount":0,"publisher":{"@id":"https:\/\/examples.javacodegeeks.com\/#organization"},"image":{"@id":"https:\/\/examples.javacodegeeks.com\/comparing-java-future-completablefuture-and-rxjava-observable\/#primaryimage"},"thumbnailUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2020\/09\/java-logo.png","keywords":["Java Concurrency","Java Streams","multithreading","Reactive Programming","RxJava"],"articleSection":["Core Java"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/examples.javacodegeeks.com\/comparing-java-future-completablefuture-and-rxjava-observable\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/examples.javacodegeeks.com\/comparing-java-future-completablefuture-and-rxjava-observable\/","url":"https:\/\/examples.javacodegeeks.com\/comparing-java-future-completablefuture-and-rxjava-observable\/","name":"Comparing Java Future, CompletableFuture and Rxjava Observable - Java Code Geeks","isPartOf":{"@id":"https:\/\/examples.javacodegeeks.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/examples.javacodegeeks.com\/comparing-java-future-completablefuture-and-rxjava-observable\/#primaryimage"},"image":{"@id":"https:\/\/examples.javacodegeeks.com\/comparing-java-future-completablefuture-and-rxjava-observable\/#primaryimage"},"thumbnailUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2020\/09\/java-logo.png","datePublished":"2023-09-22T20:05:27+00:00","dateModified":"2023-09-22T20:05:29+00:00","description":"Explore the distinctions between future, completablefuture, and rxjava's observable in Java, comparing their usage and benefits.","breadcrumb":{"@id":"https:\/\/examples.javacodegeeks.com\/comparing-java-future-completablefuture-and-rxjava-observable\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/examples.javacodegeeks.com\/comparing-java-future-completablefuture-and-rxjava-observable\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/examples.javacodegeeks.com\/comparing-java-future-completablefuture-and-rxjava-observable\/#primaryimage","url":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2020\/09\/java-logo.png","contentUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2020\/09\/java-logo.png","width":225,"height":225,"caption":"anonymous class in java"},{"@type":"BreadcrumbList","@id":"https:\/\/examples.javacodegeeks.com\/comparing-java-future-completablefuture-and-rxjava-observable\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/examples.javacodegeeks.com\/"},{"@type":"ListItem","position":2,"name":"Java Development","item":"https:\/\/examples.javacodegeeks.com\/category\/java-development\/"},{"@type":"ListItem","position":3,"name":"Core Java","item":"https:\/\/examples.javacodegeeks.com\/category\/java-development\/core-java\/"},{"@type":"ListItem","position":4,"name":"Comparing Java Future, CompletableFuture and Rxjava Observable"}]},{"@type":"WebSite","@id":"https:\/\/examples.javacodegeeks.com\/#website","url":"https:\/\/examples.javacodegeeks.com\/","name":"Java Code Geeks","description":"Java Examples and Code Snippets","publisher":{"@id":"https:\/\/examples.javacodegeeks.com\/#organization"},"alternateName":"JCG","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/examples.javacodegeeks.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/examples.javacodegeeks.com\/#organization","name":"Exelixis Media P.C.","url":"https:\/\/examples.javacodegeeks.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/logo\/image\/","url":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","contentUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","width":864,"height":246,"caption":"Exelixis Media P.C."},"image":{"@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/javacodegeeks","https:\/\/x.com\/javacodegeeks"]},{"@type":"Person","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/53e9141bb43ca17cd84b5ab586ca5199","name":"Omozegie Aziegbe","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/image\/","url":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2023\/05\/cropped-jcg_profile_pic-96x96.jpg","contentUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2023\/05\/cropped-jcg_profile_pic-96x96.jpg","caption":"Omozegie Aziegbe"},"description":"Omos holds a Master degree in Information Engineering with Network Management from the Robert Gordon University, Aberdeen. Omos is currently a freelance web\/application developer who is currently focused on developing Java enterprise applications with the Jakarta EE framework.","sameAs":["https:\/\/web.facebook.com\/omos.aziegbe","https:\/\/www.linkedin.com\/in\/omosaziegbe\/","https:\/\/x.com\/https:\/\/twitter.com\/OAziegbe"],"url":"https:\/\/examples.javacodegeeks.com\/author\/omozegie-aziegbe\/"}]}},"_links":{"self":[{"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/119967","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/users\/252"}],"replies":[{"embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/comments?post=119967"}],"version-history":[{"count":0,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/119967\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/media\/94233"}],"wp:attachment":[{"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/media?parent=119967"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/categories?post=119967"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/tags?post=119967"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}