<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Gowtham Periyasamy on Medium]]></title>
        <description><![CDATA[Stories by Gowtham Periyasamy on Medium]]></description>
        <link>https://medium.com/@gowthamperiyasamy04?source=rss-606f024fd650------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*ymKKVYWK2AAls4Am</url>
            <title>Stories by Gowtham Periyasamy on Medium</title>
            <link>https://medium.com/@gowthamperiyasamy04?source=rss-606f024fd650------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 20 Nov 2026 05:49:32 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@gowthamperiyasamy04/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Java CompletableFuture Explained with a Simple Example]]></title>
            <link>https://medium.com/@gowthamperiyasamy04/java-completablefuture-explained-with-a-simple-example-19c6f6fb606a?source=rss-606f024fd650------2</link>
            <guid isPermaLink="false">https://medium.com/p/19c6f6fb606a</guid>
            <category><![CDATA[backend-development]]></category>
            <category><![CDATA[java]]></category>
            <category><![CDATA[microservices]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Gowtham Periyasamy]]></dc:creator>
            <pubDate>Sun, 01 Nov 2026 13:03:17 GMT</pubDate>
            <atom:updated>2026-11-01T13:03:17.235Z</atom:updated>
            <content:encoded><![CDATA[<p>In Java , We often need to perform multiple tasks, such as calling REST APIs, fetching database records, or communicating with different microservices.</p><p>If these tasks are executed sequentially, the total response time can increase.</p><p>Java provides CompletableFuture , introduced in Java 8 , to help us execute tasks asynchronously and combine their results.</p><h3><strong>What is CompletableFuture?</strong></h3><p>CompletableFuture is a class in Java that represents the result of an asynchronous computation. It allows us to execute tasks without waiting for each task to finish before starting another one.</p><p><strong>Example:</strong></p><pre>import java.util.concurrent.completableFuture;<br><br>public class CompletableFutureExample<br>{<br>  public static void main(String [] args)<br>  {<br>    CompletableFuture&lt;String&gt; future = CompletableFuture.supplyAsync(() -&gt; <br>   {<br>     return &quot;Hello from CompletableFuture!&quot;;<br>   });<br>  <br>     System.out.println(future.join());<br>   }<br>}</pre><p><strong>Output:</strong></p><p><em>Hello from CompletableFuture!</em></p><p><em>In this example:</em></p><p><em>supplyAsync() executes the task asynchronously.</em></p><p><em>join() waits for the result and returns it.</em></p><h3>Combining multiple tasks</h3><p>Consider a banking application that needs to fetch customer details and account information from two independent services.</p><pre>CompletableFuture&lt;String&gt; customer= CompletableFuture.supplyAsync(() -&gt; &quot;Customer Details&quot;);<br><br>CompletableFuture&lt;String&gt; account = CompletableFuture.supplyAsync(() -&gt; &quot;Account Details&quot;);<br><br>CompletableFuture&lt;String&gt; result = customer.thenCombine(account , (c,a) -&gt; c + &quot; | &quot; + a);<br><br>System.out.println(result.join());</pre><p><strong>Output:</strong></p><p>Customer Details | Account Details</p><p>Here, thenCombine() method combines the result of two independent asynchronous tasks.</p><h3>Conclusion:</h3><p>CompletableFuture is useful for building efficient Java applications, especially when multiple independent operations can run concurrently. The key methods to remember are :</p><blockquote><em>supplyAsync() : executes a task that returns a result.</em></blockquote><blockquote><em>runAsync(): executes a task without returning a result.</em></blockquote><blockquote><em>thenApply() : transforms a result.</em></blockquote><blockquote><em>thenCombine(): combines two results.</em></blockquote><blockquote><em>exceptionally() : handle failures with a fallback result.</em></blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=19c6f6fb606a" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>