<?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 Dedyanna Cacau on Medium]]></title>
        <description><![CDATA[Stories by Dedyanna Cacau on Medium]]></description>
        <link>https://medium.com/@dedyannacacau?source=rss-5764a297b279------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*K6GUh9s4GACMJDod1s0hSw.png</url>
            <title>Stories by Dedyanna Cacau on Medium</title>
            <link>https://medium.com/@dedyannacacau?source=rss-5764a297b279------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 06 Dec 2026 07:30:39 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@dedyannacacau/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[Concurrency vs Parallelism in Java]]></title>
            <link>https://medium.com/@dedyannacacau/concurrency-vs-parallelism-in-java-exploring-virtual-threads-in-java-21-a5b5a657a72a?source=rss-5764a297b279------2</link>
            <guid isPermaLink="false">https://medium.com/p/a5b5a657a72a</guid>
            <category><![CDATA[java]]></category>
            <category><![CDATA[parallelism]]></category>
            <category><![CDATA[virtual-threads]]></category>
            <category><![CDATA[multithreading]]></category>
            <category><![CDATA[concurrency]]></category>
            <dc:creator><![CDATA[Dedyanna Cacau]]></dc:creator>
            <pubDate>Wed, 10 Sep 2025 04:03:01 GMT</pubDate>
            <atom:updated>2025-09-16T04:17:35.661Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/767/1*g98lY7EWMT2iBf29Ws8Fjw@2x.jpeg" /></figure><h4>A practical comparison with FixedThreadPool, ParallelStream, and the new Virtual Threads in Java 21</h4><h3>1. Introduction</h3><blockquote><em>Concurrency and parallelism are fundamental concepts in programming, but they are often misunderstood.</em></blockquote><ul><li><strong>Concurrency</strong>: multiple tasks making progress at the same time, sharing resources, but not necessarily executing simultaneously.</li><li><strong>Parallelism</strong>: tasks executing literally at the same time, taking advantage of multiple CPU cores.</li></ul><blockquote><em>In this post, we will compare three approaches in Java:</em></blockquote><ol><li>FixedThreadPool (limited concurrency)</li><li>ParallelStream (automatic parallelism)</li><li>Virtual Threads (new in Java 21)</li></ol><blockquote><em>And we’ll see how each of them behaves in practice.</em></blockquote><h3>2. Concurrency with FixedThreadPool</h3><p>First, let’s see an example with a fixed thread pool of 5 threads processing 20 tasks:</p><pre>try (ExecutorService executor = Executors.newFixedThreadPool(5)) {<br>    for (int i = 0; i &lt; 20; i++) {<br>        int task = i;<br>        executor.submit(() -&gt; {<br>            Thread.sleep(1000);<br>            System.out.println(&quot;Task &quot; + task + &quot; done by &quot; + Thread.currentThread().getName());<br>            return null;<br>        });<br>    }<br>}</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DFsqGwpsZK2Q6-6ffhngKA.png" /></figure><p><strong>Explanation:</strong></p><blockquote><em>Even though we submitted 20 tasks, only </em><strong><em>5 threads</em></strong><em> were created. The tasks are placed in a queue and executed as soon as a thread becomes available. This is an example of </em><strong><em>controlled concurrency</em></strong><em>.</em></blockquote><h3>3. Parallelism with ParallelStream</h3><pre>List&lt;Integer&gt; numbers = List.of(1,2,3,4,5,6,7,8,9,10);<br><br>numbers.parallelStream().forEach(n -&gt; {<br>    Thread.sleep(500);<br>    System.out.println(&quot;Processing &quot; + n + &quot; on &quot; + Thread.currentThread().getName());<br>});</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*iLAMGbqJDhADA-DDo7njug.png" /></figure><p><strong>Explanation:</strong></p><blockquote><em>With parallelStream(), Java automatically distributes the workload using the ForkJoinPool.commonPool. By default, the number of threads is equal to the number of available CPU cores.</em></blockquote><blockquote><em>This means we get </em><strong><em>real parallelism</em></strong><em>, since multiple tasks are executed simultaneously on different CPU cores. However, we have less control compared to a fixed thread pool.</em></blockquote><h3>4. Massive Concurrency with Virtual Threads (Java 21)</h3><pre>try (ExecutorService executor = Executors.newVirtualThreadPerTaskExecutor()) {<br>    for (int i = 0; i &lt; 1000; i++) {<br>        int task = i;<br>        executor.submit(() -&gt; {<br>            Thread.sleep(1000);<br>            System.out.println(&quot;Task &quot; + task + &quot; done by &quot; + Thread.currentThread());<br>            return null;<br>        });<br>    }<br>}</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*p4_4DyrCoYGZP0JEt1MJsA.png" /></figure><p><strong>Explanation:</strong></p><blockquote><em>With </em><strong><em>Virtual Threads</em></strong><em> (Project Loom), each task can run on its </em><strong><em>own lightweight thread</em></strong><em>, scheduled over a small pool of platform threads. This lets us handle </em><strong><em>thousands of concurrent tasks</em></strong><em> without the heavy memory and scheduling overhead of traditional threads.</em></blockquote><blockquote><em>Virtual Threads shine for </em><strong><em>I/O-bound</em></strong><em> workloads (HTTP calls, DB access, messaging) where tasks frequently block. The code looks like classic blocking Java, but scales like async — without callbacks or complex reactive frameworks.</em></blockquote><h3>5. Takeaways</h3><blockquote><em>Let’s recap what we saw:</em></blockquote><ul><li><strong>FixedThreadPool</strong> → <em>controlled concurrency.</em> Good when you need to limit the number of threads explicitly.</li><li><strong>ParallelStream</strong> → <em>automatic parallelism.</em> Great for CPU-bound data processing, driven by the number of CPU cores.</li><li><strong>Virtual Threads</strong> → <em>massive concurrency.</em> Ideal for I/O-heavy workloads (web servers, microservices calling multiple APIs/DBs).</li></ul><blockquote><em>👉 Rule of thumb:</em></blockquote><ul><li>CPU-bound → consider parallelStream() or a tuned thread pool.</li><li>I/O-bound with lots of waiting → <strong>Virtual Threads</strong> are the simplest way to scale.</li></ul><blockquote><strong><em>Fun fact:</em></strong></blockquote><blockquote><em>You may have noticed that the Virtual Thread IDs don’t start at #0 or #1. That’s because the JVM uses a </em><strong><em>global thread counter</em></strong><em>, which includes internal threads created before your program starts (like GC or ForkJoinPool workers). So what really matters is not the exact number, but the fact that </em><strong><em>each task is running on its own Virtual Thread</em></strong><em>.</em></blockquote><p>### Try it yourself 🚀<br>I uploaded the full code to my GitHub. <br>You can clone it here: [<a href="https://github.com/dedyannacacau/concurrency-vs-parallelism-java21">🔗 GitHub Repository</a>]</p><p>Feel free to run the examples, play with the code, and share your thoughts!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a5b5a657a72a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[From Java 11 to Java 21: Lessons Learned from a Real Migration]]></title>
            <link>https://medium.com/@dedyannacacau/from-java-11-to-java-21-lessons-learned-from-a-real-migration-2f05d3e9ecf0?source=rss-5764a297b279------2</link>
            <guid isPermaLink="false">https://medium.com/p/2f05d3e9ecf0</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[srping-boot]]></category>
            <category><![CDATA[backend-development]]></category>
            <category><![CDATA[java]]></category>
            <category><![CDATA[software-development]]></category>
            <dc:creator><![CDATA[Dedyanna Cacau]]></dc:creator>
            <pubDate>Mon, 11 Aug 2025 03:07:32 GMT</pubDate>
            <atom:updated>2025-08-11T13:24:14.838Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5vc_a57gq22eUQclVbFztw.png" /></figure><p>Recently, I had to upgrade a component from Java 11 to Java 21. At first, it seemed like a simple task — change the version and move on. But in practice, migrations often reveal much more than just code changes.</p><blockquote>In this post, I’ll share the key challenges I faced, how I solved them, and a few tips that might help you if you’re planning the same migration.</blockquote><h4>Why upgrade to Java 21?</h4><p>Java 21 is the latest LTS (Long-Term Support) release, and upgrading brings several benefits:</p><ul><li><strong>Performance improvements</strong> thanks to JVM enhancements.</li><li><strong>New language features</strong> like Pattern Matching, Records, and Virtual Threads.</li><li><strong>Long-term support</strong> until 2031, making it a safer choice for production.</li><li><strong>Security updates</strong> that keep your applications protected.</li></ul><h4>Main challenges during the migration</h4><h4>1. Dependency compatibility</h4><p>Some dependencies were not compatible with Java 21 right away. For example, older Spring Boot versions or third-party libraries might rely on deprecated APIs.</p><pre>&lt;!-- Old Spring Boot version --&gt;<br>&lt;parent&gt;<br>    &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;<br>    &lt;artifactId&gt;spring-boot-starter-parent&lt;/artifactId&gt;<br>    &lt;version&gt;2.6.3&lt;/version&gt;<br>&lt;/parent&gt;</pre><p><strong>Solution:</strong> I upgraded Spring Boot to <strong>3.x</strong>, which also meant adapting to <strong>Jakarta EE</strong> package changes (e.g., javax.* became jakarta.*).</p><h4>2. Jakarta package changes</h4><p>After moving to Spring Boot 3, classes like javax.validation.constraints.NotNull no longer worked. They had to be replaced by:</p><pre>import jakarta.validation.constraints.NotNull;</pre><p><strong>Solution:</strong> I replaced all javax.* imports with their equivalent jakarta.* imports. This required reviewing multiple classes and DTOs.</p><h4>3. Build tool updates</h4><p>If you use Maven, make sure your maven-compiler-plugin supports Java 21:</p><pre>&lt;plugin&gt;<br>    &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;<br>    &lt;artifactId&gt;maven-compiler-plugin&lt;/artifactId&gt;<br>    &lt;version&gt;3.11.0&lt;/version&gt;<br>    &lt;configuration&gt;<br>        &lt;release&gt;21&lt;/release&gt;<br>    &lt;/configuration&gt;<br>&lt;/plugin&gt;</pre><p><strong>Solution:</strong> Updated the plugin to the latest version and set the release configuration to 21.</p><h4>Lessons learned</h4><ul><li>Always <strong>check library compatibility</strong> before upgrading the JDK.</li><li>Use a <strong>separate branch</strong> for the migration to avoid blocking production fixes.</li><li>Run <strong>all automated tests</strong> early to catch hidden issues.</li><li>Take the migration as a chance to <strong>refactor outdated code</strong>.</li></ul><h4>Final tips</h4><p>If you’re planning to migrate from Java 11 to 21:</p><ol><li><strong>Plan dependencies upgrades</strong> first.</li><li>Keep an <strong>eye on Jakarta EE changes</strong>.</li><li>Test on a <strong>staging environment</strong> before production.</li><li>Document the process — future you will thank you.</li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2f05d3e9ecf0" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>