<?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 Anil R on Medium]]></title>
        <description><![CDATA[Stories by Anil R on Medium]]></description>
        <link>https://medium.com/@anilr9?source=rss-3fb1ee832f50------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*G0sskrGqkBaDtSbf9IRR7g.jpeg</url>
            <title>Stories by Anil R on Medium</title>
            <link>https://medium.com/@anilr9?source=rss-3fb1ee832f50------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 20 Nov 2026 04:43:58 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@anilr9/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[Stop Switching Between 10 Different JSON Tools — Here’s What I Built Instead]]></title>
            <link>https://anilr9.medium.com/stop-switching-between-10-different-json-tools-heres-what-i-built-instead-2bffe027b124?source=rss-3fb1ee832f50------2</link>
            <guid isPermaLink="false">https://medium.com/p/2bffe027b124</guid>
            <category><![CDATA[json]]></category>
            <category><![CDATA[java]]></category>
            <category><![CDATA[software-development]]></category>
            <dc:creator><![CDATA[Anil R]]></dc:creator>
            <pubDate>Fri, 24 Jul 2026 03:57:56 GMT</pubDate>
            <atom:updated>2026-08-02T04:54:49.052Z</atom:updated>
            <content:encoded><![CDATA[<p>If you’re a developer, you’ve probably done this more times than you’d like to admit.</p><p><a href="https://www.jsonacademy.com/"><strong>https://www.jsonacademy.com</strong></a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nUHbE7uWd73ybUHI27h9zg.png" /></figure><p>You receive a JSON response from an API, copy it into a formatter to make it readable, then head to another website to validate it. A few minutes later, you need to compare two JSON files, decode a JWT token, or convert the data into CSV. Before you know it, you have five browser tabs open just to complete one task.</p><p>I’ve been there too.</p><p>After doing this repeatedly, I started wondering why there wasn’t a single place where I could do all of these things without constantly switching between websites.</p><p>That’s what led me to build <strong>JSON Academy</strong>.</p><p><a href="https://www.jsonacademy.com/"><strong>https://www.jsonacademy.com/</strong></a></p><p>The goal wasn’t to create “another JSON formatter.” It was to build a workspace where developers can handle their everyday JSON tasks without breaking their workflow.</p><h3>Why I Built It</h3><p>Most online JSON tools do one thing really well.</p><p>Need to format JSON? One website.</p><p>Need to validate it? Another website.</p><p>Need to compare two files? Open another tab.</p><p>Need to decode a JWT? Yet another website.</p><p>Individually, these tools are great. But together, they create a fragmented workflow that wastes time.</p><p>I wanted something that felt more like a lightweight developer workspace instead of a collection of disconnected utilities.</p><h3>The Tools Available Today</h3><p>JSON Academy currently includes ten tools that cover many of the tasks developers deal with every day.</p><h3>JSON Formatter</h3><p>Messy API response?</p><p>Paste it in, and it instantly becomes clean, readable, and properly indented.</p><h3>JSON Validator</h3><p>A missing comma or bracket can be frustrating to find.</p><p>The validator quickly checks whether your JSON is valid before you spend time debugging your code.</p><h3>JSON Minifier</h3><p>Need compact JSON for production or sharing?</p><p>The minifier removes unnecessary whitespace while keeping your data intact.</p><h3>JSON to CSV Converter</h3><p>Sometimes JSON isn’t the best format to work with.</p><p>This tool converts JSON into CSV, making it easy to open in Excel, Google Sheets, or any spreadsheet application.</p><h3>JSON Tree Viewer</h3><p>Large JSON objects can become difficult to navigate.</p><p>The tree view lets you expand and collapse nested objects so you can understand complex data structures much more easily.</p><h3>JSON Diff Checker</h3><p>Ever tried comparing two large JSON files manually?</p><p>It’s painful.</p><p>The Diff Checker highlights exactly what changed, making debugging and testing much faster.</p><h3>JSONPath Extractor</h3><p>Instead of scrolling through hundreds of lines looking for a value, you can use JSONPath expressions to extract exactly what you need.</p><p>It’s especially useful when working with deeply nested API responses.</p><h3>JWT Decoder</h3><p>If you work with authentication or APIs, you’ve probably needed to inspect a JWT token.</p><p>Paste it in, and the decoder displays the header and payload instantly.</p><h3>JSON Escape &amp; Unescape</h3><p>When JSON needs to be embedded inside strings or code, escaping characters becomes necessary.</p><p>This tool handles that conversion in both directions.</p><h3>SQL Formatter</h3><p>Although JSON is the primary focus, developers often work with SQL as well.</p><p>The SQL Formatter makes long, unreadable queries much easier to understand.</p><h3>The Feature I Personally Use the Most</h3><p>The tools themselves are useful, but my favorite feature isn’t actually one of them.</p><p>It’s the <strong>workspace system</strong>.</p><p>Most online tools give you a single editor.</p><p>As soon as you paste something new, your previous work is gone.</p><p>JSON Academy works a little differently.</p><h3>Multiple Workspaces</h3><p>You can open multiple tabs inside the same tool.</p><p>For example, when comparing API responses from Development, Staging, and Production, I simply open three tabs instead of juggling multiple browser windows.</p><p>It feels much closer to working in VS Code than using a traditional online utility.</p><h3>Rename Your Tabs</h3><p>Instead of “Tab 1” and “Tab 2,” you can give each workspace a meaningful name.</p><p>For example:</p><ul><li>User API</li><li>Orders Response</li><li>Production Config</li><li>Test Payload</li></ul><p>It sounds like a small feature, but it makes staying organized much easier.</p><h3>Your Data Stays There</h3><p>One thing that always annoyed me about online tools was losing everything after switching pages.</p><p>In JSON Academy, your workspaces remain available while you’re using the tool.</p><p>You don’t have to keep pasting the same JSON over and over again.</p><p>(The data resets only when you intentionally reload the page.)</p><h3>Search Large Outputs</h3><p>If you’ve ever worked with a 5,000-line JSON response, you know how difficult it can be to find one specific key.</p><p>That’s why every tool includes search functionality for the output.</p><p>Instead of scrolling endlessly, you can jump directly to what you’re looking for.</p><h3>Who Is It For?</h3><p>I built JSON Academy with developers in mind, but I’ve found it useful for many different roles:</p><ul><li>Backend Developers</li><li>Frontend Developers</li><li>Full-Stack Engineers</li><li>QA Engineers</li><li>DevOps Engineers</li><li>API Testers</li><li>Students learning JSON</li><li>Anyone working with structured data</li></ul><h3>What’s Next?</h3><p>I’m continuously improving the platform and adding new tools based on feedback from the developer community.</p><p>If there’s a JSON utility you use regularly that isn’t available yet, I’d genuinely love to hear about it.</p><h3>Give It a Try</h3><p>If you spend your day working with APIs, configuration files, or JSON responses, I hope JSON Academy can make your workflow a little smoother.</p><p>You can explore all the tools here:</p><p><a href="https://www.jsonacademy.com/"><strong>https://www.jsonacademy.com/</strong></a></p><p>If you try it, let me know what you think. Feedback from other developers is what will help shape where the project goes next.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2bffe027b124" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[My Journey with MapStruct in Spring Boot — Setup, Struggles, and Solutions]]></title>
            <link>https://anilr9.medium.com/my-journey-with-mapstruct-in-spring-boot-setup-struggles-and-solutions-6f98e03367ae?source=rss-3fb1ee832f50------2</link>
            <guid isPermaLink="false">https://medium.com/p/6f98e03367ae</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[java]]></category>
            <category><![CDATA[microservices]]></category>
            <category><![CDATA[coding]]></category>
            <category><![CDATA[software-development]]></category>
            <dc:creator><![CDATA[Anil R]]></dc:creator>
            <pubDate>Thu, 06 Nov 2025 21:39:40 GMT</pubDate>
            <atom:updated>2025-11-06T21:39:40.417Z</atom:updated>
            <content:encoded><![CDATA[<p>If you’ve ever used Jackson’s ObjectMapper to clone objects in a Spring Boot project, you’ll know it <em>works</em> — but it’s not the cleanest or most efficient solution.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4iWitKkEep-j02ZMfNj5ZA.png" /></figure><p>I used to do this all the time:</p><pre>Request clonedRequest = objectMapper.readValue(<br>    objectMapper.writeValueAsString(request),<br>    Request.class<br>);</pre><p>It got the job done, but it always felt heavy and a bit hacky. Every time I saw that serialization dance, I wondered — is there a better, faster, and more type-safe way?</p><p>That’s when I stumbled upon <strong>MapStruct</strong>.</p><h3>Why MapStruct?</h3><p>MapStruct is a compile-time code generator that helps you map between Java objects — quickly and safely. It’s especially great when you need to transform or clone objects between DTOs and entities.</p><p>The key benefit?<br> It generates actual Java code at compile time (no reflection, no runtime overhead), so it’s <em>super fast</em> and clean to debug.</p><p>Naturally, I decided to replace my JSON-based cloning with a neat little MapStruct mapper.</p><h3>Step 1: Setting It Up</h3><p>I started with a simple class:</p><pre>@Data<br>public class Request {<br>    private String id;<br>    private String name;<br>}</pre><p>And then created a mapper:</p><pre>@Mapper<br>public interface RequestMapper {<br>    Request clone(Request request);<br>}</pre><p>I added MapStruct to my Maven dependencies and configured the compiler plugin:</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;source&gt;21&lt;/source&gt;<br>    &lt;target&gt;21&lt;/target&gt;<br>    &lt;annotationProcessorPaths&gt;<br>      &lt;path&gt;<br>        &lt;groupId&gt;org.mapstruct&lt;/groupId&gt;<br>        &lt;artifactId&gt;mapstruct-processor&lt;/artifactId&gt;<br>        &lt;version&gt;1.6.3&lt;/version&gt;<br>      &lt;/path&gt;<br>    &lt;/annotationProcessorPaths&gt;<br>  &lt;/configuration&gt;<br>&lt;/plugin&gt;</pre><p>I ran mvn clean install — and it worked!<br> But the moment I tried to run the application in IntelliJ with debug mode…</p><h3>The First Issue — “Cannot Find Symbol”</h3><p>Suddenly, I was hit with strange errors like:</p><pre>cannot find symbol class EventBuilder</pre><p>At first, I thought my code was broken.<br> Turns out, it wasn’t me — it was the build order.</p><p>By adding MapStruct’s annotation processor, I had unknowingly disrupted <strong>Lombok’s annotation processing</strong>. IntelliJ (and even Maven in some cases) couldn’t find the Lombok-generated methods and builders anymore.</p><h3>Solution #1 — Add Lombok Back to the Party</h3><p>The fix was simple but crucial: I needed to explicitly include both <strong>Lombok</strong> and <strong>MapStruct</strong> in the annotationProcessorPaths.</p><p>Here’s the corrected configuration:</p><pre>&lt;annotationProcessorPaths&gt;<br>  &lt;path&gt;<br>    &lt;groupId&gt;org.projectlombok&lt;/groupId&gt;<br>    &lt;artifactId&gt;lombok&lt;/artifactId&gt;<br>    &lt;version&gt;1.18.34&lt;/version&gt;<br>  &lt;/path&gt;<br>  &lt;path&gt;<br>    &lt;groupId&gt;org.mapstruct&lt;/groupId&gt;<br>    &lt;artifactId&gt;mapstruct-processor&lt;/artifactId&gt;<br>    &lt;version&gt;1.6.3&lt;/version&gt;<br>  &lt;/path&gt;<br>&lt;/annotationProcessorPaths&gt;</pre><p>Then, I cleaned and rebuilt the project. The build succeeded again — progress!</p><p>But when I actually tested the mapper, something strange happened…</p><h3>The Second Issue — All Fields Were null</h3><p>I called my mapper like this:</p><pre>Request r = new Request();<br>r.setId(&quot;123&quot;);<br>r.setName(&quot;Test&quot;);<br><br>Request cloned = requestMapper.clone(r);<br>System.out.println(cloned);</pre><p>And guess what I got?<br>All null values. Every property was empty.</p><p>When I checked the generated code inside target/generated-sources/annotations/RequestMapperImpl.java, I found this:</p><pre>@Override<br>public Request clone(Request request) {<br>    if (request == null) {<br>        return null;<br>    }<br><br>Request request1 = new Request();<br>    return request1;<br>}</pre><p>So MapStruct was generating a brand-new object but wasn’t copying <em>anything</em>.</p><p>At this point, I was scratching my head. My Request class had @Data, so getters and setters definitely existed… right?</p><h3>The Root Cause — Annotation Processor Order Again</h3><p>After some digging, I discovered that the <strong>order</strong> of annotation processors matters. MapStruct was running <em>before</em> Lombok, which meant Lombok hadn’t yet generated the getters and setters — so from MapStruct’s perspective, the class had no accessible properties.</p><p>That was the “aha!” moment.</p><h3>The Final Fix — Lombok First, MapStruct Next</h3><p>I reordered the annotation processor paths in Maven so Lombok comes <strong>first</strong>:</p><pre>&lt;annotationProcessorPaths&gt;<br>  &lt;!-- Lombok must come before MapStruct --&gt;<br>  &lt;path&gt;<br>    &lt;groupId&gt;org.projectlombok&lt;/groupId&gt;<br>    &lt;artifactId&gt;lombok&lt;/artifactId&gt;<br>    &lt;version&gt;1.18.34&lt;/version&gt;<br>  &lt;/path&gt;<br>  &lt;path&gt;<br>    &lt;groupId&gt;org.mapstruct&lt;/groupId&gt;<br>    &lt;artifactId&gt;mapstruct-processor&lt;/artifactId&gt;<br>    &lt;version&gt;1.6.3&lt;/version&gt;<br>  &lt;/path&gt;<br>&lt;/annotationProcessorPaths&gt;</pre><p>Then ran:</p><pre>mvn clean compile</pre><p>And finally… the generated mapper looked perfect:</p><pre>@Override<br>public Request clone(Request request) {<br>    if (request == null) {<br>        return null;<br>    }<br><br>Request request1 = new Request();<br>    request1.setId(request.getId());<br>    request1.setName(request.getName());<br>    return request1;<br>}</pre><p>Everything worked beautifully after that. 🎉</p><h3>IntelliJ Setup Tips</h3><p>To make sure IntelliJ recognizes the generated code:</p><ol><li>Go to <strong>Settings → Build, Execution, Deployment → Compiler → Annotation Processors</strong></li><li>Check ✅ <em>Enable annotation processing</em></li><li>Select <em>Obtain processors from project classpath</em></li><li>Rebuild and, if needed, <strong>Invalidate Caches / Restart</strong></li></ol><p>Once done, the IDE picks up the generated files correctly.</p><h3>Key Points to Remember</h3><ul><li><strong>MapStruct is incredibly fast and type-safe</strong> — a huge upgrade over JSON-based cloning.</li><li><strong>Annotation processing order matters!</strong> Lombok should always run before MapStruct.</li><li>A successful mvn clean install doesn’t guarantee IntelliJ is happy — make sure annotation processing is enabled.</li><li>Clean builds and cache invalidation can fix a lot of mysterious “cannot find symbol” issues.</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6f98e03367ae" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Step-by-Step Guide to Using Virtual Threads in Spring Boot]]></title>
            <link>https://medium.com/codex/step-by-step-guide-to-using-virtual-threads-in-spring-boot-71b91b54570f?source=rss-3fb1ee832f50------2</link>
            <guid isPermaLink="false">https://medium.com/p/71b91b54570f</guid>
            <category><![CDATA[java]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[coding]]></category>
            <dc:creator><![CDATA[Anil R]]></dc:creator>
            <pubDate>Wed, 05 Nov 2025 19:09:21 GMT</pubDate>
            <atom:updated>2025-11-11T07:39:09.109Z</atom:updated>
            <content:encoded><![CDATA[<p>Java 21 brought an exciting feature called <strong>Virtual Threads</strong>, and if you’re working on a Spring Boot app, this is a game-changer. Virtual Threads make it super easy to handle thousands of concurrent tasks without worrying about heavy thread pools. In this guide, we’ll walk through everything from the basics to advanced usage, including async tasks, logging, and lifecycle management.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mhsukS7q6yD8NcERFunHZg.png" /></figure><h3>Understanding Virtual Threads</h3><p>Traditional Java threads, called <strong>platform threads</strong>, are tied to the OS. They work fine for a few tasks, but if your app has hundreds or thousands of concurrent operations, creating threads can quickly become expensive and resource-heavy.</p><p><strong>Virtual Threads</strong> are different. They are managed by the JVM, not the OS, so they are lightweight and cheap to create. You can think of them as tiny workers that can handle I/O-bound tasks efficiently. The best part? You can write normal synchronous code, and it just works.</p><p>Imagine platform threads as heavy-duty workers, and virtual threads as nimble assistants ready to handle multiple small jobs without breaking a sweat. They’re perfect for APIs, database calls, or any task that involves waiting for external systems.</p><h3>A Simple Virtual Thread Example</h3><p>Here’s a minimal example to get a feel for virtual threads:</p><pre>public class VirtualThreadExample {<br>    public static void main(String[] args) throws InterruptedException {<br>        Thread.startVirtualThread(() -&gt; <br>            System.out.println(&quot;Running in virtual thread: &quot; + Thread.currentThread())<br>        );<br>Thread.sleep(100); // Wait for the virtual thread to finish<br>    }<br>}</pre><p>You’ll see output like:</p><pre>Running in virtual thread: VirtualThread[#1]/runnable</pre><p>That’s all it takes to spin up a lightweight thread in Java 21!</p><h3>Using Virtual Threads with ExecutorService</h3><p>If you want to run multiple tasks, you can combine virtual threads with an executor:</p><pre>import java.util.concurrent.*;<br><br>public class VirtualThreadExecutorExample {<br>    public static void main(String[] args) {<br>        try (ExecutorService executor = Executors.newVirtualThreadPerTaskExecutor()) {<br>            for (int i = 0; i &lt; 5; i++) {<br>                executor.submit(() -&gt; System.out.println(Thread.currentThread()));<br>            }<br>        }<br>    }<br>}</pre><p>This approach is scalable, lightweight, and perfect for high-concurrency scenarios.</p><h3>Integrating Virtual Threads in Spring Boot</h3><p>Spring Boot plays nicely with virtual threads. You can define an executor that uses virtual threads for async tasks:</p><pre>import org.springframework.context.annotation.Bean;<br>import org.springframework.context.annotation.Configuration;<br>import org.springframework.core.task.TaskExecutor;<br>import org.springframework.core.task.support.TaskExecutorAdapter;<br>import java.util.concurrent.Executors;<br><br>@Configuration<br>public class VirtualThreadConfig {<br>    @Bean<br>    public TaskExecutor syncTaskExecutor() {<br>        return new TaskExecutorAdapter(<br>            Executors.newThreadPerTaskExecutor(<br>                Thread.ofVirtual().name(&quot;async-&quot;, 0).factory()<br>            )<br>        );<br>    }<br>}</pre><p>This way, any method annotated with @Async(&quot;asyncTaskExecutor&quot;) runs in a virtual thread. Naming the threads helps when you’re debugging or checking logs.</p><h3>Keeping Logs Consistent with MDC</h3><p>When you run tasks asynchronously, logging context can get lost. That’s where <strong>MDC (Mapped Diagnostic Context)</strong> comes in. You can use a TaskDecorator to make sure your logging context carries over to the virtual thread:</p><pre>import org.slf4j.MDC;<br>import org.springframework.core.task.TaskDecorator;<br>import java.util.Map;<br><br>public class MDCTaskDecorator implements TaskDecorator {<br>    @Override<br>    public Runnable decorate(Runnable runnable) {<br>        Map&lt;String, String&gt; contextMap = MDC.getCopyOfContextMap();<br>        return () -&gt; {<br>            try {<br>                if (contextMap != null) MDC.setContextMap(contextMap);<br>                runnable.run();<br>            } finally {<br>                MDC.clear();<br>            }<br>        };<br>    }<br>}</pre><p>Register it in Spring:</p><pre>@Bean<br>public MDCTaskDecorator mdcTaskDecorator() {<br>    return new MDCTaskDecorator();<br>}</pre><p>And use it in your executor:</p><pre>@Bean<br>public TaskExecutorAdapter asyncTaskExecutor(MDCTaskDecorator mdcTaskDecorator) {<br>    ExecutorService virtualExecutor = Executors.newThreadPerTaskExecutor(<br>        Thread.ofVirtual().name(&quot;async-&quot;, 0).factory()<br>    );<br><br>return new TaskExecutorAdapter(task -&gt;<br>        virtualExecutor.execute(mdcTaskDecorator.decorate(task))<br>    );<br>}</pre><h3>Managing Executor Lifecycle</h3><p>A common mistake is creating an ExecutorService and never shutting it down. That can lead to resource leaks. Luckily, Spring makes this easy:</p><pre>@Bean(destroyMethod = &quot;shutdown&quot;)<br>public ExecutorService asyncExecutorService() {<br>    return Executors.newThreadPerTaskExecutor(Thread.ofVirtual().name(&quot;async-&quot;, 0).factory());<br>}<br><br>@Bean<br>public TaskExecutorAdapter asyncTaskExecutor(<br>        ExecutorService asyncExecutorService,<br>        TaskDecorator mdcTaskDecorator) {<br>    return new TaskExecutorAdapter(task -&gt;<br>        asyncExecutorService.execute(mdcTaskDecorator.decorate(task))<br>    );<br>}</pre><p>Spring will automatically call shutdown() when the application stops, keeping things clean.</p><h3>Using @Async with Virtual Threads</h3><p>Here’s how you can use your virtual-thread executor in a service:</p><pre>@Service<br>public class AsyncService {<br><br>@Async(&quot;asyncTaskExecutor&quot;)<br>    public void sendSms(String to, String message) {<br>        System.out.println(&quot;Thread: &quot; + Thread.currentThread());<br>        // Simulate a blocking call<br>        try { Thread.sleep(500); } catch (InterruptedException ignored) {}<br>        // Call API here<br>    }<br>}</pre><p>This setup lets you handle lots of concurrent tasks efficiently without worrying about thread pools or queue sizes.</p><h3>Key Takeaways</h3><ul><li><strong>Virtual Threads</strong> are lightweight, JVM-managed threads perfect for high-concurrency, I/O-bound tasks.</li><li>You can integrate them seamlessly in Spring Boot using TaskExecutorAdapter and @Async.</li><li>Preserve your logging context across async tasks with an MDCTaskDecorator.</li><li>Always manage the executor lifecycle with destroyMethod or @PreDestroy to avoid resource leaks.</li><li>Virtual threads reduce the need for complex pool configuration while allowing your app to scale easily.</li></ul><p>With virtual threads, writing scalable, concurrent Spring Boot applications becomes simpler and more maintainable — without sacrificing the readability of synchronous code.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=71b91b54570f" width="1" height="1" alt=""><hr><p><a href="https://medium.com/codex/step-by-step-guide-to-using-virtual-threads-in-spring-boot-71b91b54570f">Step-by-Step Guide to Using Virtual Threads in Spring Boot</a> was originally published in <a href="https://medium.com/codex">CodeX</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Java String Pool & Heap Memory]]></title>
            <link>https://anilr9.medium.com/java-string-pool-heap-memory-32113bb70b49?source=rss-3fb1ee832f50------2</link>
            <guid isPermaLink="false">https://medium.com/p/32113bb70b49</guid>
            <category><![CDATA[java]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[technology]]></category>
            <category><![CDATA[software-engineering]]></category>
            <dc:creator><![CDATA[Anil R]]></dc:creator>
            <pubDate>Tue, 12 Aug 2025 15:28:42 GMT</pubDate>
            <atom:updated>2025-08-12T15:28:42.139Z</atom:updated>
            <content:encoded><![CDATA[<p>If you’ve been writing Java for a while, you’ve probably seen String name = &quot;Hello&quot;; and not thought much about what’s going on under the hood.<br> But did you know that Java <em>does something very clever</em> with Strings behind the scenes to save memory and boost performance?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IxhuABjWDAoMDaIPt3Y9oQ.png" /></figure><p>That’s where the <strong>String Pool</strong> and <strong>Heap Memory</strong> come in.<br> Let’s take a walk from beginner basics to JVM-level insights so you can understand exactly what’s happening.</p><h3>Java’s Memory Model in a Nutshell</h3><p>Before we talk about the String Pool, let’s get our mental map of Java’s memory straight.</p><p>When a Java program runs, the JVM carves up memory into a few key areas:</p><ul><li><strong>Heap Memory</strong> → Where all objects live (Strings, custom objects, arrays, etc.).</li><li><strong>Stack Memory</strong> → Where method calls and local variables are stored temporarily.</li><li><strong>Method Area</strong> → Stores class-level data, method code, and (in older versions) interned strings.</li><li><strong>MetaSpace</strong> (Java 8+) → Replaces PermGen for storing class metadata.</li></ul><p><strong>Key point</strong>: The <strong>String Pool</strong> lives in a special area <em>related to</em> the Heap, not somewhere completely separate.</p><h3>What is the String Pool?</h3><p>The String Pool (or <strong>interned String pool</strong>) is a special storage area where Java stores <strong>unique String literals</strong>.</p><h4>Why?</h4><p>Because Strings are <strong>immutable</strong> — once created, they can’t be changed.<br> That means if multiple parts of your program use &quot;Hello&quot;, the JVM doesn’t need to create 10 copies. It can store just one copy in the pool and reuse it.</p><h3>Example: String Literal Reuse</h3><pre>public class StringPoolDemo {<br>    public static void main(String[] args) {<br>        String a = &quot;Java&quot;;<br>        String b = &quot;Java&quot;;<br>        <br>        System.out.println(a == b);<br>    }<br>}</pre><p>Both a and b point to <strong>the same</strong> &quot;Java&quot; object in the String Pool.</p><h3>Heap Memory vs String Pool</h3><p>Here’s the tricky bit — <strong>the String Pool is actually inside the Heap</strong> (in modern Java versions).</p><h3>Case 1 — String Literal</h3><pre>String s1 = &quot;Hello&quot;; // Goes into the String Pool</pre><h3>Case 2 — new String()</h3><pre>String s2 = new String(&quot;Hello&quot;); // Always creates a NEW object in the Heap</pre><p>Even though the literal &quot;Hello&quot; is in the pool, new String() forces the JVM to make another copy in regular heap memory.</p><h3>intern() Method</h3><p>If you have a String that’s not from the pool but you want it there, you call:</p><pre>String str1 = new String(&quot;PoolMe&quot;);<br>String str2 = str1.intern();<br><br>System.out.println(str1 == str2); // false - different references<br>System.out.println(&quot;PoolMe&quot; == str2); // true - from the pool</pre><p>intern() checks if the string already exists in the pool:</p><ul><li>If yes → returns the pooled reference.</li><li>If no → adds it to the pool and returns that reference.</li></ul><h3>Version-Wise Changes</h3><p>Back in Java 6 and earlier, the String Pool was stored in <strong>PermGen space</strong>, a fixed-size memory region. This meant that if you interned too many Strings, you could run out of space and get an OutOfMemoryError.</p><p>In Java 7, the pool was moved into the <strong>Heap</strong>. This was a big improvement because the heap is larger and managed by garbage collection, so unused pooled strings could be cleaned up.</p><p>From Java 8 onwards, class metadata was moved out of PermGen into <strong>MetaSpace</strong>, but the String Pool stayed in the Heap. This gave more flexibility and reduced the chance of memory errors related to interning.</p><p>By Java 11 and newer versions, the JVM also introduced smarter optimizations, allowing some constant strings from class files to be shared automatically.</p><h3>Examples</h3><h3>Pool Reuse</h3><pre>String x = &quot;Code&quot;;<br>String y = &quot;Code&quot;;<br>System.out.println(x == y); // true</pre><h3>intern()</h3><pre>String a = new String(&quot;Java&quot;);<br>String b = a.intern();<br>String c = &quot;Java&quot;;<br><br>System.out.println(a == b); // false<br>System.out.println(b == c); // true</pre><h3>Measuring Memory Impact</h3><p>You can run the below and watch memory in <strong>VisualVM</strong> or <strong>jconsole</strong>.</p><pre>import java.util.ArrayList;<br>import java.util.List;<br><br>public class PoolMemoryTest {<br>    public static void main(String[] args) {<br>        List&lt;String&gt; list = new ArrayList&lt;&gt;();<br>        for (int i = 0; i &lt; 100000; i++) {<br>            list.add((&quot;Str&quot; + i).intern()); // Try removing .intern()<br>        }<br>        System.out.println(&quot;Done&quot;);<br>    }<br>}</pre><p>Observe how <strong>intern()</strong> affects heap size.</p><h3>Common Misconceptions</h3><ul><li><strong>“String Pool is not in the Heap”</strong> — False for Java 7+, it’s in the Heap.</li><li><strong>“intern() always improves performance”</strong> — Not true. Interning too many unique strings can waste memory.</li><li><strong>“Using </strong><strong>new String() is harmless&quot;</strong> — It can create unnecessary duplicates.</li></ul><h3>Best Practices</h3><ul><li>Use <strong>string literals</strong> when possible.</li><li>Use <strong>StringBuilder</strong> or <strong>StringBuffer</strong> for building strings in loops.</li><li>Only use <strong>intern()</strong> when profiling shows memory benefits.</li></ul><h3>Real-World Usage</h3><p>In enterprise apps that load millions of repeating strings (like country codes, status values), using the pool can:</p><ul><li>Reduce heap usage.</li><li>Speed up equality checks (== instead of .equals() in some cases).</li></ul><h3>Summary</h3><p>The String Pool is one of those JVM optimizations that “just works” for most developers — but if you understand it deeply, you can make smarter performance decisions.<br> From Java 6’s PermGen days to Java 21’s optimized heap, this feature has evolved to keep your applications lean and efficient.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=32113bb70b49" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Java Serialization and Deserialization]]></title>
            <link>https://anilr9.medium.com/java-serialization-and-deserialization-475aa615e48f?source=rss-3fb1ee832f50------2</link>
            <guid isPermaLink="false">https://medium.com/p/475aa615e48f</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[java]]></category>
            <category><![CDATA[technology]]></category>
            <dc:creator><![CDATA[Anil R]]></dc:creator>
            <pubDate>Tue, 12 Aug 2025 12:58:38 GMT</pubDate>
            <atom:updated>2025-08-12T12:58:38.674Z</atom:updated>
            <content:encoded><![CDATA[<p>Whether you’re saving user sessions to a file or sending objects over the internet, Java serialization and deserialization come in handy. These are fundamental concepts every Java developer should know — but they can feel a bit confusing at first. Don’t worry — we’ll break it down clearly with code examples, use cases, and even some gotchas to avoid.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zaQJOhmESrQAIDZ12j8ftA.png" /></figure><h3>What Is Serialization in Java?</h3><p><strong>Serialization</strong> is the process of converting a Java object into a byte stream — meaning you can write it to a file, send it over a network, or store it in memory.</p><p>Think of it as turning your object into a flat format that can be saved or transmitted.</p><pre>Object → Byte Stream</pre><h3>What Is Deserialization?</h3><p><strong>Deserialization</strong> is the reverse — it converts the byte stream back into a Java object.</p><pre>Byte Stream → Object</pre><p>Serialization and deserialization go hand in hand.</p><h3>Why Do We Use Serialization?</h3><p>Some common use cases:</p><ul><li><strong>Saving object state</strong> (e.g., saving game progress or user sessions)</li><li><strong>Caching objects</strong> for faster retrieval</li><li><strong>Sending objects across the network</strong> (e.g., in RMI, sockets, or distributed systems)</li><li><strong>Storing data in files or databases</strong></li></ul><h3>How to Serialize an Object in Java</h3><p>To serialize a Java object, it must:</p><ol><li>Implement the java.io.Serializable interface (a <em>marker interface</em> — it has no methods).</li><li>Use ObjectOutputStream to write the object.</li></ol><h3>Example:</h3><pre>import java.io.FileOutputStream;<br>import java.io.IOException;<br>import java.io.ObjectOutputStream;<br>import java.io.Serializable;<br><br>class Person implements Serializable {<br>    private String name;<br>    private int age;<br>    <br>    public Person(String name, int age) {<br>        this.name = name;<br>        this.age = age;<br>    }<br>}<br>public class SerializeExample {<br>    public static void main(String[] args) {<br>        Person person = new Person(&quot;Alice&quot;, 30);<br>        try (ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(&quot;person.ser&quot;))) {<br>            oos.writeObject(person);<br>            System.out.println(&quot;Person object serialized to person.ser&quot;);<br>        } catch (IOException e) {<br>            e.printStackTrace();<br>        }<br>    }<br>}</pre><h3>How to Deserialize an Object</h3><p>To read that object back, we deserialize it using ObjectInputStream.</p><h3>Example:</h3><pre>import java.io.FileInputStream;<br>import java.io.IOException;<br>import java.io.ObjectInputStream;<br><br>public class DeserializeExample {<br>    public static void main(String[] args) {<br>        try (ObjectInputStream ois = new ObjectInputStream(new FileInputStream(&quot;person.ser&quot;))) {<br>            Person person = (Person) ois.readObject();<br>            System.out.println(&quot;Deserialized Person: &quot; + person);<br>        } catch (IOException | ClassNotFoundException e) {<br>            e.printStackTrace();<br>        }<br>    }<br>}</pre><h3>What is serialVersionUID and Why Does It Matter?</h3><p>Every serialized object has a <strong>serialVersionUID</strong> — a unique identifier to ensure class compatibility during deserialization.</p><p>If the class definition changes (e.g., a new field is added), deserialization will fail unless you define a serialVersionUID manually.</p><h3>Example:</h3><pre>private static final long serialVersionUID = 1L;</pre><p>Best practice: <strong>Always declare it manually</strong> to avoid InvalidClassException.</p><h3>What Is the transient Keyword?</h3><p>Sometimes, you don’t want a field to be serialized — maybe it’s sensitive data like a password, or something not serializable like a database connection.</p><p>Use the transient keyword to exclude it.</p><h3>Example:</h3><pre>private transient String password;</pre><p>When deserialized, password will be null (or default value for its type).</p><h3>Custom Serialization: Externalizable</h3><p>If you want <strong>full control</strong> over what gets serialized and how, implement the Externalizable interface instead of Serializable.</p><p>You must implement two methods:</p><ul><li>writeExternal(ObjectOutput out)</li><li>readExternal(ObjectInput in)</li></ul><h3>Example:</h3><pre>class CustomPerson implements Externalizable {<br>    private String name;<br>    private int age;<br><br>public CustomPerson() {}<br>    public void writeExternal(ObjectOutput out) throws IOException {<br>        out.writeObject(name);<br>        out.writeInt(age);<br>    }<br>    public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {<br>        name = (String) in.readObject();<br>        age = in.readInt();<br>    }<br>}</pre><p>Use this only if you need fine-grained control — for most cases, Serializable is enough.</p><h3>Best Practices</h3><ul><li>Always declare serialVersionUID.</li><li>Avoid serializing sensitive data (use transient).</li><li>Test backward compatibility after modifying classes.</li><li>Don’t serialize objects with open resources (like file handles or sockets).</li><li>Always check for exceptions — serialization can silently fail.</li></ul><h3>Common Pitfalls</h3><ul><li>Forgetting to implement Serializable.</li><li>Changing class structure without updating serialVersionUID.</li><li>Deserializing untrusted data (can lead to <strong>security vulnerabilities</strong>).</li></ul><h3>Summary</h3><p>Java Serialization and Deserialization are powerful tools — especially when you’re building stateful, persistent, or distributed systems. But they come with trade-offs. For many modern apps, formats like JSON or Protocol Buffers are better suited for cross-platform communication.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=475aa615e48f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Understanding yield in Java]]></title>
            <link>https://anilr9.medium.com/understanding-yield-in-java-8a9f058e34cd?source=rss-3fb1ee832f50------2</link>
            <guid isPermaLink="false">https://medium.com/p/8a9f058e34cd</guid>
            <category><![CDATA[java]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[technology]]></category>
            <dc:creator><![CDATA[Anil R]]></dc:creator>
            <pubDate>Fri, 08 Aug 2025 13:16:40 GMT</pubDate>
            <atom:updated>2025-08-08T13:16:40.213Z</atom:updated>
            <content:encoded><![CDATA[<p>Java has come a long way over the years, continuously evolving to help developers write cleaner, more expressive code. One of the small but powerful additions in recent versions is the yield keyword.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*twRUHZkXaZgG9kXyGu7p3g.png" /></figure><p>If you’ve stumbled upon it and thought, <em>“Wait, what does </em><em>yield even do in Java?”</em> — you&#39;re not alone. Let&#39;s break it down, understand its purpose, and see how it can help us write better code.</p><h3>What Is yield in Java?</h3><p>The yield keyword was introduced as part of <strong>Java 13</strong> (preview) and officially finalized in <strong>Java 14</strong>. It plays a specific role in the <strong>new </strong><strong>switch expressions</strong> — a modern alternative to the traditional switch statement.</p><p>In short:</p><blockquote><em>yield is used to </em><strong><em>return a value</em></strong><em> from a </em><strong><em>case block</em></strong><em> inside a </em><em>switch </em><strong><em>expression</em></strong><em>.</em></blockquote><p>This is different from the old-style switch statement, which didn’t directly return values and required more boilerplate code.</p><h3>Why Was yield Needed?</h3><p>Before Java 14, developers used switch for control flow but not for returning values directly. With the introduction of <strong>switch expressions</strong>, Java needed a way to <strong>produce a result</strong> from each case. That’s where yield comes in.</p><h3>Syntax: How yield Works in Switch Expressions</h3><p>Here’s a basic structure:</p><pre>String result = switch (value) {<br>    case 1 -&gt; &quot;One&quot;;<br>    case 2 -&gt; {<br>        System.out.println(&quot;Processing case 2...&quot;);<br>        yield &quot;Two&quot;;<br>    }<br>    default -&gt; &quot;Other&quot;;<br>};</pre><h4>Explanation:</h4><ul><li>The arrow -&gt; syntax is used for expressions.</li><li>If a case needs multiple statements (like logging or logic), you use <strong>curly braces</strong> {} and <strong>yield</strong> to return a value.</li></ul><h3>Before and After: Code Comparison</h3><h3>Traditional switch (Before yield)</h3><pre>String dayType;<br>switch (day) {<br>    case &quot;Saturday&quot;:<br>    case &quot;Sunday&quot;:<br>        dayType = &quot;Weekend&quot;;<br>        break;<br>    default:<br>        dayType = &quot;Weekday&quot;;<br>        break;<br>}</pre><h3>New switch Expression with yield</h3><pre>String dayType = switch (day) {<br>    case &quot;Saturday&quot;, &quot;Sunday&quot; -&gt; &quot;Weekend&quot;;<br>    default -&gt; &quot;Weekday&quot;;<br>};</pre><h4>With more logic using yield:</h4><pre>String dayType = switch (day) {<br>    case &quot;Saturday&quot;, &quot;Sunday&quot; -&gt; {<br>        System.out.println(&quot;It&#39;s the weekend!&quot;);<br>        yield &quot;Weekend&quot;;<br>    }<br>    default -&gt; {<br>        System.out.println(&quot;Back to work...&quot;);<br>        yield &quot;Weekday&quot;;<br>    }<br>};</pre><p><strong>Key benefits:</strong></p><ul><li>More concise</li><li>Easier to read</li><li>Directly returns a value</li><li>No need for mutable variables outside the switch</li></ul><h3>Real-World Use Case: Mapping HTTP Status Codes</h3><p>Let’s say you want to map HTTP status codes to human-readable messages:</p><pre>String message = switch (statusCode) {<br>    case 200 -&gt; &quot;OK&quot;;<br>    case 404 -&gt; &quot;Not Found&quot;;<br>    case 500 -&gt; {<br>        logError(&quot;Internal Server Error&quot;);<br>        yield &quot;Server Error&quot;;<br>    }<br>    default -&gt; &quot;Unknown Status&quot;;<br>};</pre><p>This keeps your logic compact, readable, and expressive — something that was harder to achieve with older switch syntax.</p><h3>Common Pitfalls &amp; Misunderstandings</h3><ul><li><strong>yield is only used inside switch expressions</strong>, not in loops (unlike Python or Kotlin).</li><li>You need <strong>curly braces</strong> {} when using yield inside a case.</li><li>Don’t confuse yield with return — return exits a method; yield just gives a value for the current case.</li></ul><p><strong>Incorrect usage:</strong></p><pre>String x = switch (value) {<br>    case 1:<br>        yield &quot;One&quot;; // Missing braces around the case block<br>};</pre><p><strong>Corrected:</strong></p><pre>String x = switch (value) {<br>    case 1 -&gt; {<br>        yield &quot;One&quot;; <br>    }<br>};</pre><h3>Summary</h3><p>The yield keyword may seem minor, but it plays a vital role in writing modern, elegant Java code with switch expressions. It:</p><ul><li>Enables switch expressions to return values</li><li>Simplifies logic that previously required verbose variable assignments</li><li>Encourages functional-style programming in Java</li></ul><p>As Java continues to evolve, features like yield help us write <strong>cleaner, more expressive</strong>, and <strong>less error-prone</strong> code.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8a9f058e34cd" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Mastering GCP cbt: From Beginner to Pro]]></title>
            <link>https://anilr9.medium.com/mastering-gcp-cbt-from-beginner-to-pro-bd4e5be3807b?source=rss-3fb1ee832f50------2</link>
            <guid isPermaLink="false">https://medium.com/p/bd4e5be3807b</guid>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[gcp]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[cloud-bigtable]]></category>
            <dc:creator><![CDATA[Anil R]]></dc:creator>
            <pubDate>Fri, 18 Jul 2025 15:23:01 GMT</pubDate>
            <atom:updated>2025-07-18T15:23:01.390Z</atom:updated>
            <content:encoded><![CDATA[<p>Google Cloud Bigtable is a high-performance NoSQL database service for large analytical and operational workloads. If you ever need to interact with Bigtable quickly from the command line, the cbt CLI tool is your go-to utility. Whether you&#39;re just starting or looking to script advanced data manipulations, this guide will walk you through everything from the basics to professional techniques.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/832/1*9ls5_D6jJxQicUFuB6eD3Q.png" /></figure><h3>Getting Started with cbt</h3><h4>What is cbt?</h4><p>cbt is the official command-line interface for interacting with Bigtable. It&#39;s ideal for:</p><ul><li>Reading and writing data</li><li>Managing tables and column families</li><li>Troubleshooting</li></ul><h4>Step 1: Installation</h4><p>Install the Google Cloud SDK first:</p><pre>brew install --cask google-cloud-sdk  #macOS</pre><p>Then install cbt:</p><pre>gcloud components install cbt</pre><h4>Step 2: Authentication &amp; Config</h4><p>Create a .cbtrc file in your home directory with this structure:</p><pre>project = your-gcp-project-id<br>instance = your-bigtable-instance-id<br>creds = /path/to/your-service-account.json</pre><h4>Step 3: Basic Commands</h4><p><strong>Create a table:</strong></p><pre>cbt createtable user_data</pre><p><strong>Add a column family:</strong></p><pre>cbt createfamily user_data profile</pre><p><strong>Insert data:</strong></p><pre>cbt set user_data row1 profile:name=Alice</pre><p><strong>Read it back:</strong></p><pre>cbt lookup user_data row1</pre><h3>Working with Data</h3><h4>Row Key Design Matters</h4><p>Design your row keys carefully for performance. Good keys:</p><ul><li>Are evenly distributed</li><li>Avoid hot-spotting (e.g., timestamps in front)</li></ul><h4>Filters and Scanning</h4><p><strong>Read rows with regex row key filter:</strong></p><pre>cbt read customer_orders regex=&quot;.*#7868.*&quot;</pre><p><strong>Only specific columns:</strong></p><pre>cbt read customer_orders --columns=profile:email</pre><p><strong>Limit results:</strong></p><pre>cbt read user_data count=5</pre><p><strong>Use prefix filtering:</strong></p><pre>cbt read user_data prefix=&quot;user_2025&quot;</pre><h4>Timestamps and Versions</h4><p>Bigtable stores versions by timestamp. <strong>View all versions of a cell:</strong></p><pre>cbt lookup user_data row1 cells-per-column=5</pre><h4>Real Example: Find All Opt-Outs in July 2025</h4><pre>cbt read customer_order_notification regex=&quot;.*#1234567890#.*&quot; \<br>| awk &#39;/opt_out:opt_out_flag *@ 2025\/07/ {print $0; getline; print $0}&#39;</pre><h3>Automation and Scripting</h3><h4>Bash + cbt: Scriptable Power</h4><p>Want to extract only the opt-out flags?</p><pre>cbt read customer_order_notification regex=&quot;.*#7868488239#.*&quot; \<br>| awk &#39;/opt_out:opt_out_flag/ {getline; print $1}&#39;</pre><h4>Python + cbt: Data Processing</h4><pre>import subprocess, re<br>output = subprocess.check_output([<br>    &quot;cbt&quot;, &quot;read&quot;, &quot;order_notification&quot;,<br>    &quot;regex=.*#1234567890#.*&quot;,<br>    &quot;--cells-per-column=10&quot;<br>], text=True)<br><br>entries = []<br>lines = output.splitlines()<br>for i, line in enumerate(lines):<br>    if &#39;opt_out:opt_out_flag&#39; in line and &#39;@ 2025/07&#39; in line:<br>        entries.append((line, lines[i+1]))<br>for meta, value in entries:<br>    print(meta)<br>    print(value)</pre><h3>Troubleshooting Tips</h3><ul><li><strong>Authentication errors?</strong> Check your creds path in .cbtrc</li><li><strong>Missing rows?</strong> Ensure row key regex or prefix is correct</li><li><strong>Empty values?</strong> Try increasing --cells-per-column</li></ul><h3>cbt Command Cheat Sheet</h3><p><strong>List all tables in an instance:</strong></p><pre>cbt ls</pre><p><strong>Create a new table:</strong></p><pre>cbt createtable my_table</pre><p><strong>Create a column family in a table:</strong></p><pre>cbt createfamily my_table my_family</pre><p><strong>List column families in a table:</strong></p><pre>cbt listcolumnfamilies my_table</pre><p><strong>Delete a table:</strong></p><pre>cbt deletetable my_table</pre><p><strong>Delete a single row from a table:</strong></p><pre>cbt deleterow my_table row_key</pre><p><strong>Insert a single cell value into a row:</strong></p><pre>cbt set my_table row1 my_family:my_column=value</pre><p><strong>Read a single row (with default settings):</strong></p><pre>cbt lookup my_table row1</pre><p><strong>Read multiple rows using prefix filter:</strong></p><pre>cbt read my_table prefix=&quot;row_prefix&quot;</pre><p><strong>Read rows using regex on row key:</strong></p><pre>cbt read my_table regex=&quot;.*pattern.*&quot;</pre><p><strong>Read rows with selected columns only:</strong></p><pre>cbt read my_table --columns=my_family:my_column</pre><p><strong>Read a specific number of rows:</strong></p><pre>cbt read my_table count=10</pre><p><strong>Read multiple versions of cells per column:</strong></p><pre>cbt lookup my_table row1 cells-per-column=5</pre><p><strong>Delete a specific cell in a row:</strong></p><pre>cbt deletecell my_table row1 my_family:my_column</pre><p><strong>Get help for any command:</strong></p><pre>cbt help [command]</pre><h3>Summary</h3><ul><li>cbt is great for debugging and small data tasks.</li><li>For large-scale operations, prefer <strong>Dataflow</strong>, <strong>HBase client</strong>, or <strong>Bigtable client libraries</strong>.</li><li>Use awk, grep, and scripting to unlock powerful command-line data workflows.</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bd4e5be3807b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Does Google Cloud Pub/Sub Use a Load Balancer When Calling Spring Boot Endpoints?]]></title>
            <link>https://anilr9.medium.com/does-google-cloud-pub-sub-use-a-load-balancer-when-calling-spring-boot-endpoints-5be8092e477a?source=rss-3fb1ee832f50------2</link>
            <guid isPermaLink="false">https://medium.com/p/5be8092e477a</guid>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[gcp]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Anil R]]></dc:creator>
            <pubDate>Thu, 10 Jul 2025 18:13:53 GMT</pubDate>
            <atom:updated>2025-07-10T18:13:53.274Z</atom:updated>
            <content:encoded><![CDATA[<p>If you’re integrating <strong>Google Cloud Pub/Sub</strong> with a <strong>Spring Boot backend</strong>, you might wonder:<br> <strong>Does the traffic go through a Load Balancer, or does Pub/Sub just call your endpoint directly?</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0u3aDJAh7RqOkl5Y1eEkHw.png" /></figure><h3>A Quick Look at Pub/Sub</h3><p><strong>Google Cloud Pub/Sub</strong> is a powerful messaging system used to decouple services. It enables asynchronous communication between producers and consumers using <strong>topics</strong> and <strong>subscriptions</strong>.</p><p>There are two ways for your service (like a Spring Boot app) to receive messages:</p><ul><li><strong>Pull</strong>: Your service pulls messages from Pub/Sub.</li><li><strong>Push</strong>: Pub/Sub pushes messages to a registered HTTPS endpoint.</li></ul><p>This choice greatly influences whether a <strong>Load Balancer</strong> gets involved.</p><h3>Subscription Types: The Key to Understanding Flow</h3><p>Let’s explore the difference between <strong>Push</strong> and <strong>Pull</strong> — and how each affects networking.</p><h3>1. Push Subscription (Pub/Sub ➝ Spring Boot)</h3><p>Pub/Sub delivers messages <strong>directly to a URL</strong> you provide. That URL could:</p><ul><li>Be a public IP or domain of your app</li><li>Be routed through a <strong>Load Balancer</strong></li><li>Be something like a <strong>Cloud Run service URL</strong></li></ul><h4>A Direct Public Endpoint (No LB)</h4><pre>https://my-spring-app.example.com/pubsub/receive</pre><p>In this case:</p><ul><li>Pub/Sub <strong>sends HTTP POST directly</strong> to this endpoint.</li><li>No Load Balancer is needed or used unless configured.</li></ul><p><strong>Good for</strong> simple setups, prototypes, or when security/firewall rules are open.</p><h4>An Endpoint Behind a Load Balancer</h4><pre>https://api.mycompany.com/spring/pubsub/receive</pre><ul><li>This domain resolves to a <strong>GCP Load Balancer</strong>.</li><li>Pub/Sub sends the request to the <strong>Load Balancer</strong>, which routes it to the actual backend (Spring Boot app on GKE/GCE/etc).</li></ul><p><strong>Good for</strong> production-grade apps where you need:</p><ul><li>SSL termination</li><li>Centralized routing</li><li>Traffic management and logging</li></ul><h3>2. Pull Subscription (Spring Boot ➝ Pub/Sub)</h3><p>With pull subscriptions:</p><ul><li>Your Spring Boot service periodically <strong>polls</strong> Pub/Sub and fetches messages.</li><li>Since your app is the <strong>caller</strong>, no Load Balancer is needed.</li></ul><p>Example:</p><pre>SubscriptionAdminClient subscriptionAdminClient = SubscriptionAdminClient.create();<br>PullRequest pullRequest = PullRequest.newBuilder()<br>    .setSubscription(&quot;projects/myproject/subscriptions/my-subscription&quot;)<br>    .setMaxMessages(10)<br>    .build();</pre><p><strong>Good for</strong> internal apps, batch processing, or services running in private networks.</p><h3>Real-World Deployment Scenarios</h3><p>Let’s walk through how this plays out with different GCP environments.</p><h3>Cloud Run</h3><ul><li>Cloud Run gives you a secure HTTPS URL.</li><li>You can set this as your <strong>push endpoint</strong> in Pub/Sub.</li><li>No Load Balancer needed unless you <strong>customize routing</strong> (e.g., vanity domain with HTTPS + LB).</li></ul><pre>https://my-service-abc.run.app/pubsub/handler</pre><h3>GKE (Google Kubernetes Engine)</h3><ul><li>Your app runs in a pod.</li><li>If you expose it via an <strong>Ingress</strong>, it typically sits behind a GCP Load Balancer.</li><li>In this case, yes — <strong>Pub/Sub hits the LB first</strong>, then the pod.</li></ul><h3>Compute Engine</h3><ul><li>If you deploy Spring Boot on a VM:</li><li>Direct public IP: Pub/Sub calls the app directly.</li><li>Through LB: Pub/Sub traffic routes via the Load Balancer.</li></ul><h3>Example: Setting a Push Subscription</h3><pre>gcloud pubsub subscriptions create my-sub \<br>  --topic=my-topic \<br>  --push-endpoint=https://api.mycompany.com/spring/pubsub/receive \<br>  --push-auth-service-account=pubsub-invoker@myproject.iam.gserviceaccount.com</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5be8092e477a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Mastering Parameterized Logging in Java & Spring Boot: Best Practices and Pitfalls]]></title>
            <link>https://anilr9.medium.com/mastering-parameterized-logging-in-java-spring-boot-best-practices-and-pitfalls-bb781ceec7c8?source=rss-3fb1ee832f50------2</link>
            <guid isPermaLink="false">https://medium.com/p/bb781ceec7c8</guid>
            <category><![CDATA[spring]]></category>
            <category><![CDATA[java]]></category>
            <category><![CDATA[spring-boot]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Anil R]]></dc:creator>
            <pubDate>Mon, 07 Jul 2025 20:03:51 GMT</pubDate>
            <atom:updated>2025-07-07T20:03:51.060Z</atom:updated>
            <content:encoded><![CDATA[<p>When you’re building Spring Boot applications in Java, logging isn’t just a nice-to-have — it’s essential. Whether you’re debugging an issue in production or tracing how a request flows through your services, good logging can save hours of head-scratching.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KCAGIBzkng7dcfnRxIaRmA.png" /></figure><p>But not all logging is created equal.</p><h3>What is Parameterized Logging?</h3><p>In simple terms, <strong>parameterized logging</strong> allows you to insert variables into log messages without string concatenation. Instead of writing:</p><pre>log.info(&quot;User ID: &quot; + userId);</pre><p>You write:</p><pre>log.info(&quot;User ID: {}&quot;, userId);</pre><p>It may look like a small change — but under the hood, it’s much more efficient.</p><h3>How Does It Work?</h3><p>Under the hood, parameterized logging in <strong>SLF4J (Simple Logging Facade for Java)</strong> replaces {} placeholders with your object values <em>only if</em> the log level is enabled. This means if logging is turned off at that level (e.g., debug logs are disabled in production), the object’s toString() won’t even be called.</p><p>This is what makes parameterized logging <em>lazy</em> and efficient.</p><blockquote><em>SLF4J is just a facade — it works with backends like </em><strong><em>Logback</em></strong><em>, </em><strong><em>Log4j2</em></strong><em>, or </em><strong><em>java.util.logging</em></strong><em>. Spring Boot uses </em><strong><em>Logback</em></strong><em> by default.</em></blockquote><h3>Usage Examples</h3><h3>Bad Logging: String Concatenation</h3><pre>log.debug(&quot;Order: &quot; + order);  // Not efficient</pre><p>Even if debug is disabled, this still creates the full string before passing it to the logger.</p><h3>Bad Logging: Incorrect use of comma</h3><pre>log.info(&quot;Order placed: &quot;, order);  // Won’t log &#39;order&#39; properly</pre><p>This syntax is invalid in SLF4J. The second argument is ignored or causes runtime issues.</p><h3>Good Logging: Parameterized</h3><pre>log.info(&quot;Order placed: {}&quot;, order);</pre><p>This logs exactly what you expect — and only when needed.</p><h3>Logging multiple values</h3><pre>log.debug(&quot;User {} placed order {} for ${}&quot;, userId, orderId, amount);</pre><h3>Using Parameterized Logging in Spring Boot</h3><p>Spring Boot developers often use <strong>Lombok’s </strong><strong>@Slf4j annotation</strong> to inject a logger automatically:</p><pre>import lombok.extern.slf4j.Slf4j;<br><br>@Slf4j<br>@RestController<br>public class OrderController {<br>    @GetMapping(&quot;/orders/{id}&quot;)<br>    public ResponseEntity&lt;?&gt; getOrder(@PathVariable String id) {<br>        log.info(&quot;Fetching order with ID: {}&quot;, id);<br>    }<br>}</pre><h3>Best Practices</h3><p>Here are some real-world tips to keep your logs clean and useful:</p><h3>1. Use Correct Log Levels</h3><ul><li>trace – very fine-grained, usually not enabled</li><li>debug – internal details, useful during development</li><li>info – high-level application flow</li><li>warn – unexpected but non-fatal issues</li><li>error – serious problems</li></ul><h3>2. Avoid Logging Sensitive Data</h3><pre>log.info(&quot;User password: {}&quot;, password);</pre><p>Use log masking or omit such fields altogether.</p><h3>3. Add Business Context</h3><p>Instead of:</p><pre>log.info(&quot;Transaction processed&quot;);</pre><p>Use:</p><pre>log.info(&quot;Transaction {} processed for customer {}&quot;, txnId, customerId);</pre><h3>4. Use Structured Logging</h3><p>If you’re integrating with log aggregators like ELK or Datadog, structured logs (e.g., JSON) are easier to search and filter.</p><h3>5. Log Exceptions Properly</h3><pre>log.error(&quot;Payment failed&quot;, ex);</pre><p>Don’t just do:</p><pre>log.error(&quot;Payment failed: {}&quot;, ex.getMessage());</pre><h3>Real-World Example: Logging a Service Method</h3><pre>@Slf4j<br>@Service<br>public class PaymentService {<br><br>    public void processPayment(PaymentRequest request) {<br>        log.info(&quot;Processing payment for user: {}&quot;, request.getUserId());<br>        try {<br>            log.debug(&quot;Payment details: {}&quot;, request);<br>        } catch (PaymentException ex) {<br>            log.error(&quot;Payment failed for user {}&quot;, request.getUserId(), ex);<br>        }<br>    }<br>}</pre><h3>Configuring Logging in application.yml</h3><p>You can control logging levels easily:</p><pre>logging:<br>  level:<br>    root: INFO<br>    com.example.myapp: DEBUG</pre><p>This way, you get detailed logs where you want them — without cluttering everything else.</p><h3>Summary</h3><p>Good logging is like good documentation — it tells the story of what your app is doing, when, and why. And parameterized logging helps you tell that story <strong>cleanly, efficiently, and safely</strong>.</p><p>So next time you’re tempted to slap a + in a log message, pause and remember those magical {} brackets. Your future self (and your logs) will thank you.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bb781ceec7c8" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Understanding @Service in Spring Boot: A Complete Guide with Examples]]></title>
            <link>https://anilr9.medium.com/understanding-service-in-spring-boot-a-complete-guide-with-examples-b08825e8ccd8?source=rss-3fb1ee832f50------2</link>
            <guid isPermaLink="false">https://medium.com/p/b08825e8ccd8</guid>
            <category><![CDATA[spring]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[spring-boot]]></category>
            <category><![CDATA[software-development]]></category>
            <dc:creator><![CDATA[Anil R]]></dc:creator>
            <pubDate>Thu, 26 Jun 2025 15:10:03 GMT</pubDate>
            <atom:updated>2025-06-26T15:10:03.365Z</atom:updated>
            <content:encoded><![CDATA[<p>When working with Spring Boot, you often hear terms like Controller, Service, Repository — and behind each of these is a key Spring annotation that plays a specific role.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0u3aDJAh7RqOkl5Y1eEkHw.png" /></figure><h3>Where Does @Service Fit in Spring Boot?</h3><p>Spring Boot applications usually follow a layered architecture:</p><ul><li><strong>Controller layer</strong>: Handles HTTP requests and routes them to the correct services.</li><li><strong>Service layer</strong>: Contains business logic — how things work in your app.</li><li><strong>Repository layer</strong>: Talks to the database.</li></ul><p>Think of it this way:</p><blockquote><em>A controller </em>asks<em> the service,<br> “Hey, how should I process this request?”<br> The service answers using its logic, and maybe calls the repository to get or save data.</em></blockquote><p>So, where does @Service fit? Right in the business logic layer.</p><h3>What is @Service?</h3><p>@Service is a Spring annotation that marks a class as a <strong>service provider</strong>. It’s a specialized version of @Component, which means it gets picked up by Spring’s component scanning and registered as a <strong>bean</strong>.</p><p>Why use @Service instead of @Component?</p><p>While they function the same technically, using @Service makes your intention clear:</p><blockquote><em>“This class contains business logic, not just utility code.”</em></blockquote><p>It’s about readability and proper design.</p><h3>What Happens Behind the Scenes?</h3><p>When you mark a class with @Service, Spring:</p><ul><li>Detects it during component scanning (thanks to @SpringBootApplication or @ComponentScan)</li><li>Instantiates it as a bean</li><li>Manages its lifecycle</li><li>Makes it available for dependency injection anywhere in the app</li></ul><p>You don’t need to do anything extra — just annotate your service class and Spring takes care of the rest.</p><h3>Let’s Build a Real Example</h3><h3>Step 1: Create a Service Class</h3><pre>import org.springframework.stereotype.Service;<br><br>@Service<br>public class OrderService {<br>    public double calculateTotal(double price, int quantity) {<br>        return price * quantity;<br>    }<br>    public String placeOrder(String item, int quantity) {<br>        return &quot;Order placed: &quot; + quantity + &quot; x &quot; + item;<br>    }<br>}</pre><h3>Step 2: Inject the Service into a Controller</h3><pre>import org.springframework.beans.factory.annotation.Autowired;<br>import org.springframework.web.bind.annotation.*;<br><br>@RestController<br>@RequestMapping(&quot;/orders&quot;)<br>public class OrderController {<br>    private final OrderService orderService;<br>    @Autowired  // Constructor injection<br>    public OrderController(OrderService orderService) {<br>        this.orderService = orderService;<br>    }<br>    @GetMapping(&quot;/total&quot;)<br>    public double getTotal(@RequestParam double price, @RequestParam int qty) {<br>        return orderService.calculateTotal(price, qty);<br>    }<br>    @PostMapping(&quot;/place&quot;)<br>    public String placeOrder(@RequestParam String item, @RequestParam int qty) {<br>        return orderService.placeOrder(item, qty);<br>    }<br>}</pre><p>That’s it! When you call /orders/total?price=10.0&amp;qty=3, you’ll get 30.0.<br> Spring has injected the OrderService bean into the controller automatically.</p><h3>Best Practices When Using @Service</h3><p>Here are a few tried-and-true tips to keep your service layer clean and effective:</p><ul><li><strong>Keep your services focused</strong>: A service should do one thing well. Avoid massive “God” services.</li><li><strong>Keep them stateless</strong>: Services should not store user/session data — pass everything needed via method parameters.</li><li><strong>Use constructor injection</strong>: It’s more testable and safe than field injection.</li><li><strong>Avoid database logic</strong>: Delegate that to a repository. Services should orchestrate logic, not manage database calls directly.</li><li><strong>Keep controllers thin</strong>: Don’t write logic in controllers — just route to the correct service methods.</li></ul><h3>Common Pitfalls to Watch For</h3><h3>Mistake 1: Forgetting the Annotation</h3><pre>public class OrderService {<br>    // Forgot @Service<br>}</pre><p>Spring won’t pick this class up. You’ll get an error like:</p><blockquote><em>No qualifying bean of type...</em></blockquote><h3>Mistake 2: Field Injection</h3><pre>@Autowired<br>private OrderService orderService;</pre><p>While this works, it’s harder to test and can’t be final. Instead, use constructor injection:</p><pre>@Autowired<br>public OrderController(OrderService orderService) {<br>    this.orderService = orderService;<br>}</pre><p>Cleaner and safer.</p><h3>Mistake 3: Doing Everything in the Controller</h3><pre>@GetMapping(&quot;/discount&quot;)<br>public double getDiscount(@RequestParam double total) {<br>    return total * 0.1;<br>}</pre><p>Move this to a service instead:</p><pre>public double calculateDiscount(double total) {<br>    return total * 0.1;<br>}</pre><h3>How is @Service Different from @Component or @Repository?</h3><p>Even though @Service, @Component, and @Repository are all <strong>Spring stereotypes</strong> and behave the same in terms of bean registration, they have <strong>different intentions</strong>:</p><ul><li>Use @Component for general-purpose beans (utilities, helpers).</li><li>Use @Service for business logic.</li><li>Use @Repository for data access (plus it enables exception translation).</li></ul><p>The idea is: annotate classes based on their role — not just because it “works”.</p><h3>Recap: Why Use @Service?</h3><p>Let’s summarize what you now know:</p><ul><li>@Service is a specialization of @Component, used for business logic classes.</li><li>It helps Spring detect and manage your service classes.</li><li>It improves readability and design clarity.</li><li>It works beautifully with @Autowired (especially constructor-based).</li><li>It’s a key part of clean, maintainable, layered architecture.</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b08825e8ccd8" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>