<?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 Akshay Ingole on Medium]]></title>
        <description><![CDATA[Stories by Akshay Ingole on Medium]]></description>
        <link>https://medium.com/@akshay.ingole?source=rss-1c15d5a5911f------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*zKwupwPWohIuRtDa</url>
            <title>Stories by Akshay Ingole on Medium</title>
            <link>https://medium.com/@akshay.ingole?source=rss-1c15d5a5911f------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 30 Nov 2026 13:53:18 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@akshay.ingole/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[Pure Reactive vs Blocking Reactive in Java]]></title>
            <link>https://medium.com/globant/pure-reactive-vs-blocking-reactive-in-java-3f00fa110c4c?source=rss-1c15d5a5911f------2</link>
            <guid isPermaLink="false">https://medium.com/p/3f00fa110c4c</guid>
            <category><![CDATA[reactive-programming]]></category>
            <category><![CDATA[non-blocking]]></category>
            <category><![CDATA[synchronous]]></category>
            <category><![CDATA[spring-boot]]></category>
            <category><![CDATA[java8-reactive]]></category>
            <dc:creator><![CDATA[Akshay Ingole]]></dc:creator>
            <pubDate>Tue, 17 Dec 2024 07:32:23 GMT</pubDate>
            <atom:updated>2024-12-17T07:32:23.984Z</atom:updated>
            <content:encoded><![CDATA[<h4>Understanding the Differences</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/1*q8pgVVc2ANLKzs-ut7-pkQ.jpeg" /></figure><p>Reactive programming has gained significant popularity in the Java ecosystem, enabling developers to build responsive, scalable, and resilient applications. But what exactly is reactive programming? In simple terms, it’s a programming paradigm focused on asynchronous, non-blocking data streams and the propagation of change. This approach is particularly suited for handling real-time, high-throughput scenarios like web applications, streaming services, and microservices.</p><p>In this article, we’ll dive into two key approaches within the reactive programming world in Java: <strong>pure reactive</strong> and <strong>blocking reactive</strong>. By exploring their differences, strengths, and limitations, you’ll gain a clear understanding of when and why to choose one approach over the other in your projects. Whether new to reactive programming or looking to refine your knowledge, this guide has something for you. Let’s break it down step by step.</p><h3>Pure Reactive</h3><p>Pure reactive programming in Java revolves around the principles of <strong>non-blocking I/O</strong>, <strong>event-driven architecture</strong>, and efficient resource utilization. It leverages libraries like <a href="https://www.reactive-streams.org/">Reactive Streams</a> and <a href="https://projectreactor.io/">Project Reactor</a> to provide a fully non-blocking and asynchronous programming experience. This approach allows developers to handle large volumes of data and user interactions in a highly efficient and scalable manner, making it ideal for modern distributed systems and microservices.</p><p>For an example, let’s consider a small code snippet from a movie-streaming app.</p><pre>Flux&lt;Movie&gt; movieStream = movieService.getPopularMovies()<br>    .delayElements(Duration.ofSeconds(1))<br>    .flatMap(movie -&gt; videoService.getVideoStream(movie.getId()))<br>    .filter(video -&gt; video.getDuration() &gt; Duration.ofMinutes(10))<br>    .map(Video::getTitle);<br><br>movieStream.subscribe(title -&gt; System.out.println(&quot;Now streaming: &quot; + title));<br><br>Thread.sleep(10000);</pre><p>Here, we use pure reactive programming to create a stream of popular movies. We introduce a delay of 1 second between emitting each movie to simulate real-time data. Then, we use the flatMap operator to fetch the video stream for each movie asynchronously. We apply further transformations, such as filtering videos with a duration longer than 10 minutes and extracting their titles. Finally, we subscribe to the movie stream and print the titles. The non-blocking nature of pure reactive programming allows for seamless streaming and real-time updates.</p><h3>Blocking Reactive</h3><p>Blocking reactive programming still adheres to reactive principles but allows for blocking I/O and synchronous operations. This approach is often used when integrating with legacy code or interacting with blocking APIs. Instead of comparing it with the Stream API, we can focus on the explicit use of the .block() method on reactive functions to achieve blocking behavior.</p><p>Let’s see an example, and consider a real-world scenario in the movie streaming App where blocking reactive programming can be useful:</p><pre>List&lt;Movie&gt; movies = movieService.getPopularMovies().collectList().block();<br>List&lt;Video&gt; videos = new ArrayList&lt;&gt;();<br><br>for (Movie movie : movies) {<br>    videos.add(videoService.getVideo(movie.getId()).block());<br>}<br><br>List&lt;Video&gt; longVideos = new ArrayList&lt;&gt;();<br><br>for (Video video : videos) {<br>    if (video.getDuration() &gt; Duration.ofMinutes(10)) {<br>        longVideos.add(video);<br>    }<br>}<br><br>for (Video video : longVideos) {<br>    System.out.println(&quot;Now streaming: &quot; + video.getTitle());<br>}</pre><p>In this example, we use blocking reactive programming to fetch popular movies and their corresponding videos synchronously. We first collect the list of movies using collectList().block(). Then, we iterate through the list of movies and retrieve videos one by one using .block() to wait for each video to be fetched. We then filter the videos based on duration and store the long videos in a separate list. Finally, we iterate through the long videos and print their titles. While blocking reactive programming simplifies the code structure, it may lead to decreased responsiveness if used extensively.</p><h3>Differences between Pure Reactive and Blocking Reactive</h3><p>The core difference between pure reactive and blocking reactive lies in their design and execution models. Pure reactive programming emphasizes non-blocking I/O, event-driven communication, and asynchronous processing. It excels in scenarios that require high concurrency, scalability, and efficient resource utilization.</p><p>On the other hand, blocking reactive programming allows for synchronous operations and may be more suitable for integrating with legacy code or interacting with blocking APIs. However, excessive blocking can hinder responsiveness and scalability.</p><h3>Purpose and Use Cases</h3><p>Pure reactive programming shines in high-throughput systems, real-time applications, and microservices architectures. It enables developers to handle large amounts of concurrent requests efficiently while maintaining responsiveness. By leveraging the asynchronous nature of pure reactive programming, applications can scale and handle a significant number of concurrent users.</p><p>On the other hand, blocking reactive programming can be useful when integrating with blocking libraries or when working with a small number of synchronous operations. It provides a simpler development model in certain scenarios but should be used judiciously to avoid blocking bottlenecks.</p><h3>Conclusion</h3><p>Understanding the differences between pure reactive and blocking reactive programming is crucial when developing Java applications. While pure reactive programming excels in scalability, throughput, and resource utilization, blocking reactive programming still has its place in specific use cases. By considering the requirements of your application and the trade-offs of each approach, you can make an informed decision on which paradigm to choose.</p><p>Reactive programming continues to evolve, and staying updated with the latest trends and advancements is essential. By leveraging the power of reactive programming, you can build highly performant and responsive applications that meet the demands of modern software development.</p><h3><strong>Reference Links:</strong></h3><ul><li><a href="https://www.reactive-streams.org/">Reactive Streams</a>: The official website of Reactive Streams, which provides a specification for asynchronous stream processing with non-blocking backpressure.</li><li><a href="https://projectreactor.io/">Project Reactor</a>: The official website of Project Reactor, a popular reactive programming library for Java that implements the Reactive Streams specification.</li><li><a href="https://docs.oracle.com/en/java/javase/15/docs/api/java.base/java/util/stream/package-summary.html">Java Streams API</a>: The official documentation for the Java Streams API, which enables functional-style operations on streams of elements.</li><li><a href="https://www.appsdeveloperblog.com/introduction-to-reactive-streams-in-java//">Introduction to Reactive Programming in Java</a>: A comprehensive guide on reactive programming in Java.</li><li><a href="https://spring.io/reactive">Reactive Programming with Spring Framework</a>: The official Spring Framework documentation on reactive programming, which provides support for reactive programming in Java applications.</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3f00fa110c4c" width="1" height="1" alt=""><hr><p><a href="https://medium.com/globant/pure-reactive-vs-blocking-reactive-in-java-3f00fa110c4c">Pure Reactive vs Blocking Reactive in Java</a> was originally published in <a href="https://medium.com/globant">Globant</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Memory mapped files and MappedByteBuffers in Java]]></title>
            <link>https://medium.com/globant/memory-mapped-files-and-mappedbytebuffers-in-java-4e5819605b20?source=rss-1c15d5a5911f------2</link>
            <guid isPermaLink="false">https://medium.com/p/4e5819605b20</guid>
            <dc:creator><![CDATA[Akshay Ingole]]></dc:creator>
            <pubDate>Mon, 12 Dec 2022 12:55:36 GMT</pubDate>
            <atom:updated>2022-12-12T12:55:36.896Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/0*u0lUOCGUWiOfxq9I" /></figure><p>In this short article, we’ll be looking at the memory<strong>-</strong>mapped file MappedByteBufferin the java.nio package. This utility can be quite useful for efficient file reads.</p><h3><strong>Memory-mapped files</strong></h3><p>A memory-mapped file is a segment of virtual memory that has been assigned a direct byte-for-byte correlation with some portion of a file.</p><ul><li>Reading and writing in the memory-mapped file is generally done by the operating system to write content into a disk.</li><li>A memory-mapped file contains the contents of a file in virtual memory. This mapping between a file and memory space enables an application, including multiple processes, to modify the file by reading and writing directly to the memory.</li><li>Memory-Mapped Files in Java is a rather new Java concept for many programmers and developers, though it’s been there since JDK 1.4 along with package ‘ java.nio ’.</li><li>Java IO has been considerably fast after the introduction of NIO, and memory-mapped file offers the fastest IO operation possible in Java, <br>that’s why high-performance Java applications should use memory-mapped files for persisting data.</li><li>Memory Mapped is already quite popular in the high-frequency trading space, where the electronic trading system needs to be super fast and one-way latency to exchange has to be on the sub-microsecond level.</li></ul><p>There are two types of memory-mapped files:</p><ul><li><strong>Persisted memory-mapped files</strong>: Persisted files are associated with a disk source file. The data is saved to the source file on the disk when the last process has finished working with the file. These memory-mapped files are suitable for working with extremely large source files.</li><li><strong>Non-persisted memory-mapped files</strong>: Non-persisted files are memory-mapped files that are not associated with a file on a disk. When the last process has finished working with the file, the data is lost, and the file is reclaimed by garbage collection. These files are suitable for creating shared memory for inter-process communications (IPC).</li></ul><h3><strong>Benefits of Memory Mapped Files</strong></h3><p>The principal benefits of memory mapping are efficiency, faster file access, the ability to share memory between applications, automatic memory management, and more points described below</p><ul><li>Accessing files via memory map is faster than using I/O functions such as fread and fwrite. Data are read and written using the virtual memory capabilities built into the operating system rather than having to allocate, copy into, and then deallocate data buffers owned by the process.</li><li>As the user process deal with the mapped memory space, page faults will be generated automatically to bring in the file data from the disk.</li><li>If the user modifies the mapped memory space, the affected page is automatically marked as dirty and will be subsequently flushed to the disk to update the file.</li><li>The virtual memory subsystem of the operating system will perform intelligent caching of the pages, automatically managing memory according to system load.</li><li>The data is always page-aligned, and no buffer copying is ever needed.<br>Very large files can be mapped without consuming large amounts of memory to copy the data.</li></ul><h3><strong>Example</strong> of memory-mapped file</h3><p>The following illustration shows how multiple processes can have multiple and overlapping views of the same memory-mapped file at the same time.<br>It shows multiple and overlapped views of a memory-mapped file:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/317/0*eBP2xvKH2wkKp1aI.png" /></figure><p><strong>MappedByteBuffer </strong>will also not be visible to other programs that have mapped the same file; instead, they will cause private copies of the modified portions of the buffer to be created.</p><pre>import java.io.RandomAccessFile;<br>import java.nio.MappedByteBuffer;<br>import java.nio.channels.FileChannel;<br> <br>public class MemoryMappedFile <br>{<br>  static int length = 0x8FFFFFF;  <br> <br>  public static void main(String[] args) throws Exception <br>  {<br>    try(RandomAccessFile file = new RandomAccessFile(&quot;test.dat&quot;, &quot;rw&quot;)) <br>    {<br>      MappedByteBuffer out = file.getChannel()<br>                    .map(FileChannel.MapMode.READ_WRITE, 0, length);<br>       <br>      for (int i = 0; i &lt; length; i++) <br>      {<br>        out.put((byte) &#39;x&#39;);<br>      }<br>       <br>      System.out.println(&quot;Finished writing&quot;);<br>    }<br>  }<br>}</pre><p>The file created with the above program is 128 MB long, which is probably larger than the space your OS will allow. The file appears accessible all at once because only portions of it are brought into memory, and other parts are swapped out. This way, a very large file (up to 2 GB) can easily be modified.</p><h3>Advantages and disadvantages<strong> of Memory Mapped files</strong></h3><p>There are several advantages and disadvantages of memory-mapped files:</p><ul><li>Possibly, the main advantage of Memory Mapped IO is performance, which is important to build high-performance systems like for electronic trading.</li><li>Memory Mapped Files are way faster than standard file access via normal IO.</li><li>Another significant advantage of memory-mapped IO is that it allows you to load a potentially larger file that is not otherwise accessible.</li><li>The disadvantage of memory-mapped IO is that it potentially complicates your cache controller, as device accesses behave differently from normal memory accesses.</li></ul><h3><strong>Conclusion</strong></h3><p>In this article, we learned these points:</p><ul><li>Memory Mapped Files are way faster than standard file access via normal IO.</li><li>Multiple processes can have multiple and overlapping views of the same memory-mapped file.</li><li>Types of memory-mapped files.</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4e5819605b20" width="1" height="1" alt=""><hr><p><a href="https://medium.com/globant/memory-mapped-files-and-mappedbytebuffers-in-java-4e5819605b20">Memory mapped files and MappedByteBuffers in Java</a> was originally published in <a href="https://medium.com/globant">Globant</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Getting Started with Lombok]]></title>
            <link>https://medium.com/globant/getting-started-with-lombok-eede343549df?source=rss-1c15d5a5911f------2</link>
            <guid isPermaLink="false">https://medium.com/p/eede343549df</guid>
            <category><![CDATA[lombok]]></category>
            <category><![CDATA[lombok-anotation]]></category>
            <category><![CDATA[project-lombok]]></category>
            <category><![CDATA[lombok-setup-steps]]></category>
            <category><![CDATA[lombok-features]]></category>
            <dc:creator><![CDATA[Akshay Ingole]]></dc:creator>
            <pubDate>Wed, 04 May 2022 13:27:25 GMT</pubDate>
            <atom:updated>2022-05-04T13:27:25.402Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>Getting Started with Lombok</strong></p><p>Java is the most popular object-oriented programming language but it has some drawbacks. The major drawback is to write lots of <strong>boilerplate</strong> code. To overcome this drawback, project <strong>Lombok</strong> comes into existence. It is a tool that spices up our Java application.</p><p><strong>What is project Lombok?</strong></p><ul><li>The project Lombok is a popular and widely used Java library that is used to minimize or remove the boilerplate code. It saves time and effort. Just by using the annotations.</li><li>we can save space and readability of the source code. It is automatically plugging into IDEs and build tools to spice up our Java application.</li></ul><p><strong>Why project Lombok?</strong></p><ul><li>Suppose, we are developing a Java application for which a POJO file is required that has several private fields. For these fields, we have to generate getters and setters accessor methods to provide access. Generating getters and setters for each field increases the line of code.</li><li>Moreover, adding a constructor and a toString() technique will cause much more lines of code and mess. What about when we are utilizing Java objects that need to be closed after use, so we need to code a finally-block or use try-with-resources to ensure that the object closing occurs. Adding a finally-block boilerplate to close objects can add a significant amount of clutter to the code.</li><li>Hence, we deal with lots of boilerplate code.</li><li>To overcome the same problem, the project Lombok comes into existence.</li></ul><p><strong>Features of Lombok Project</strong> :<br>1. It reduces the boilerplate code.<br>2. It replaces boilerplate code with easy-to-use annotations.<br>3. It makes code easier to read and less error-prone.<br>4. By using Lombok the developers becomes more productive.<br>5. It works well with all popular IDEs.<br>6. Provide annotation for checking null values.<br>7. Easy cleanup<br>8. Locking safely<br>9. Effortless logging</p><p><strong>Purpose to Use Lombok Project:<br></strong>Lombok is used to reduce boilerplate code automatically by using Lombok annotations.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*xei_MJc3VW4mUAKx.jpg" /></figure><ul><li>The<strong> @Data</strong> Lombok produces getters and setters for every one of the non-static class fields and a class constructor.</li><li>The <strong>@AllArgsConstructor</strong> annotation generates a constructor with all fields that are declared.</li><li>The <strong>@NoArgsConstructor</strong> annotation simply generates the constructor without any argument.</li><li>The library <strong>@NonNull</strong> annotation that can be used to generate a null check on a setter field.</li><li>The <strong>@Getter</strong> and <strong>@Sette</strong>r annotation generating getters and setters can be laborious work if there are several private fields in the POJO file.</li></ul><p><strong>Example :</strong></p><ol><li>with All annotations</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/685/1*eT5Lcez-ISTsWUB5Fb9btQ.png" /><figcaption><strong>image: Declaration of Lombok annotation</strong></figcaption></figure><ul><li>Using above <strong>Lombok </strong>annotations will generates the boiler plate code (getters, setters, toString(), constructor) automatically, which happens at compile time, so developer no need to write code manually for the setters, getters, overriding toString(), equals(), hashcode(), generating with arguments and default constructors etc.</li></ul><p>2.With @Data annotations and there internal implementation.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/921/1*mirPhVzF-FrPE_jsiixPqw.png" /><figcaption>@Data annotation example</figcaption></figure><p>By simply adding the @data annotation you get all this for free:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/264/0*Yorze8IkA5kpkYli.png" /></figure><p><strong>Setup Lombok in Your Ides :</strong><br><a href="https://projectlombok.org/setup/eclipse">https://projectlombok.org/setup/eclipse</a><br><a href="https://projectlombok.org/setup/intellij">https://projectlombok.org/setup/intellij</a></p><p><strong>Using Lombok in Java projects :<br>Using Gradle :<br></strong>In order to add lombok to the classpath of a Java Project with Gradle the following dependency has to be added:</p><pre>dependencies <strong>{</strong><br>    compileOnly<strong>(&#39;org.projectlombok:lombok:1.16.20&#39;)</strong><br><strong>}</strong></pre><p><strong>Using Maven:<br></strong>In order to add lombok to the classpath of a Java Project with Apache Maven the following dependency has to be added:</p><pre><strong>&lt;dependency&gt;</strong><br>    <strong>&lt;groupId&gt;</strong>org.projectlombok<strong>&lt;/groupId&gt;</strong><br>    <strong>&lt;artifactId&gt;</strong>lombok<strong>&lt;/artifactId&gt;</strong><br>    <strong>&lt;version&gt;</strong>1.16.20<strong>&lt;/version&gt;</strong><br><strong>&lt;/dependency&gt;</strong></pre><p><strong>Doing it manually<br></strong>The lombok library can also be downloaded directly from here: <a href="https://projectlombok.org/download.html">https://projectlombok.org/download.html</a> and be added to the classpath.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*M7tFvFUV6IgAqaTm86-23Q.png" /></figure><p><strong>Conclusion :</strong></p><ul><li>There are still some other features we haven’t presented in this article. We can take a deeper dive into the feature overview for more details and use cases.</li><li>Furthermore, most functions we’ve shown have a number of customization options that we may find handy. The available built-in configuration system could also help us with that.</li><li>Now that we can give Lombok a chance to get into our Java development tool set, we can boost our productivity.</li></ul><blockquote><strong>Referances:</strong><br><a href="https://projectlombok.org/features/all">https://projectlombok.org/features/all</a><br><a href="https://projectlombok.org/setup/eclipse">https://projectlombok.org/setup/eclipse</a><br><a href="https://projectlombok.org/download">https://projectlombok.org/download</a></blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=eede343549df" width="1" height="1" alt=""><hr><p><a href="https://medium.com/globant/getting-started-with-lombok-eede343549df">Getting Started with Lombok</a> was originally published in <a href="https://medium.com/globant">Globant</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>