<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Machine coding Master</title>
    <description>The latest articles on DEV Community by Machine coding Master (@machinecodingmaster).</description>
    <link>https://dev.to/machinecodingmaster</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3894844%2F09f3cafa-c542-4beb-8efa-72045647d766.png</url>
      <title>DEV Community: Machine coding Master</title>
      <link>https://dev.to/machinecodingmaster</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/machinecodingmaster"/>
    <language>en</language>
    <item>
      <title>Stop Claude Code Token Burn: Constrain CLI Agent Loops with Gradle Test Filters</title>
      <dc:creator>Machine coding Master</dc:creator>
      <pubDate>Thu, 16 Jul 2026 05:26:38 +0000</pubDate>
      <link>https://dev.to/machinecodingmaster/stop-claude-code-token-burn-constrain-cli-agent-loops-with-gradle-test-filters-dmi</link>
      <guid>https://dev.to/machinecodingmaster/stop-claude-code-token-burn-constrain-cli-agent-loops-with-gradle-test-filters-dmi</guid>
      <description>&lt;h2&gt;
  
  
  Stop Claude Code Token Burn: Constrain CLI Agent Loops with Gradle Test Filters
&lt;/h2&gt;

&lt;p&gt;If you are letting the new &lt;code&gt;claude&lt;/code&gt; CLI agent loose on your enterprise Java codebase without strict guardrails, you are essentially writing Anthropic a blank check. Left unchecked, Claude's autonomous test-debug-fix loops will happily execute your entire multi-module Gradle test suite fifty times over just to fix a single &lt;code&gt;NullPointerException&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why Most Developers Get This Wrong
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Blanket Agent Execution:&lt;/strong&gt; Running generic prompts like &lt;code&gt;claude write "refactor legacy payment gateway"&lt;/code&gt; and allowing the agent to run standard &lt;code&gt;./gradlew test&lt;/code&gt; on every iteration, burning millions of context tokens on unrelated modules.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Ignoring Incremental Compiles:&lt;/strong&gt; Failing to restrict Claude's context to the specific subproject, forcing the agent to parse compilation errors from unrelated modules.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;No Token Guardrails:&lt;/strong&gt; Not setting hard limits on token budgets or max iteration loops, resulting in $50 bills for a single refactoring task.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  The Right Way
&lt;/h2&gt;

&lt;p&gt;Constrain the agent's feedback loop by injecting tight Gradle target filters and strict token budgets directly into its execution context.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Targeted Test Execution:&lt;/strong&gt; Force Claude to run highly specific test targets (e.g., &lt;code&gt;./gradlew :payment-service:test --tests "com.api.PaymentGatewaySpec"&lt;/code&gt;) instead of broad suite runs.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Strict Step Budgets:&lt;/strong&gt; Use the &lt;code&gt;--max-steps&lt;/code&gt; flag in the &lt;code&gt;claude&lt;/code&gt; CLI configuration to auto-terminate runaway loops before they spiral.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Incremental Feedback Loops:&lt;/strong&gt; Feed &lt;em&gt;only&lt;/em&gt; compiler stdout/stderr back to the agent using &lt;code&gt;--no-daemon&lt;/code&gt; and &lt;code&gt;--continuous&lt;/code&gt; flags to prevent massive log dumps from bloating the context window.&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;Want to go deeper? &lt;a href="https://javalld.com" rel="noopener noreferrer"&gt;javalld.com&lt;/a&gt; — machine coding interview problems with working Java code and full execution traces.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Show Me The Code (or Example)
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# Run targeted refactoring with strict budget and filtered test execution&lt;/span&gt;
claude write &lt;span class="s2"&gt;"Refactor deprecated Spring Security config in :auth-service"&lt;/span&gt; &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--max-steps&lt;/span&gt; 5 &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--cmd-allowlist&lt;/span&gt; &lt;span class="s2"&gt;"./gradlew"&lt;/span&gt; &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--eval&lt;/span&gt; &lt;span class="s2"&gt;"
    ./gradlew :auth-service:compileJava &amp;amp;&amp;amp; &lt;/span&gt;&lt;span class="se"&gt;\&lt;/span&gt;&lt;span class="s2"&gt;
    ./gradlew :auth-service:test --tests 'com.auth.SecurityConfigSpec'
  "&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Key Takeaways
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Scope is King:&lt;/strong&gt; Never let an AI agent run a root-level &lt;code&gt;./gradlew test&lt;/code&gt;; always isolate the subproject and target class.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Limit the Steps:&lt;/strong&gt; Hard-cap your CLI agent's loop execution at 5 steps to force a manual review before token burn compounds.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Clean Contexts:&lt;/strong&gt; Keep build logs clean; pipe only failures to the agent to avoid polluting the prompt context with thousands of lines of successful Gradle task outputs.&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>java</category>
      <category>productivity</category>
      <category>ai</category>
      <category>llm</category>
    </item>
    <item>
      <title>Thread Confinement in Java: Master High-Performance Concurrency in LLD Interviews</title>
      <dc:creator>Machine coding Master</dc:creator>
      <pubDate>Wed, 15 Jul 2026 05:15:39 +0000</pubDate>
      <link>https://dev.to/machinecodingmaster/thread-confinement-in-java-master-high-performance-concurrency-in-lld-interviews-30jm</link>
      <guid>https://dev.to/machinecodingmaster/thread-confinement-in-java-master-high-performance-concurrency-in-lld-interviews-30jm</guid>
      <description>&lt;h2&gt;
  
  
  Thread Confinement in Java: Master High-Performance Concurrency in LLD Interviews
&lt;/h2&gt;

&lt;p&gt;In LLD and machine coding interviews, candidates often default to heavy synchronization primitives like &lt;code&gt;synchronized&lt;/code&gt; or &lt;code&gt;ReentrantLock&lt;/code&gt; at the first sight of multi-threaded requirements. However, the fastest synchronization is the one you don't use, and mastering thread confinement is the secret to writing blazingly fast, lock-free concurrent systems.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Shameless plug: &lt;a href="https://javalld.com" rel="noopener noreferrer"&gt;javalld.com&lt;/a&gt; has full LLD implementations with step-by-step execution traces — free to use while prepping.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  The Mistake Most Candidates Make
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;strong&gt;Over-synchronizing shared state:&lt;/strong&gt; Defaulting to global locks which introduces thread contention, context-switching overhead, and potential deadlocks.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Leaking mutable references:&lt;/strong&gt; Passing local, mutable objects to background threads without realizing they are exposing internal state to concurrent modification.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Ignoring JVM stack safety:&lt;/strong&gt; Forgetting that local variables are inherently thread-safe because they reside on the thread's private stack.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  The Right Approach
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;strong&gt;Core mental model:&lt;/strong&gt; Keep mutable state strictly confined to the lifecycle of a single thread so that concurrent access is mathematically impossible.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Key entities/classes:&lt;/strong&gt; &lt;code&gt;ThreadLocal&lt;/code&gt;, &lt;code&gt;SimpleFormatter&lt;/code&gt; (non-thread-safe utilities), and local stack variables.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Why it beats the naive approach:&lt;/strong&gt; It completely eliminates coordination overhead and cache-coherence traffic across CPU cores, maximizing throughput.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  The Key Insight (Code)
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;ThreadConfinedFormatter&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// ThreadLocal confines the unsafe SimpleDateFormat to a single thread&lt;/span&gt;
    &lt;span class="kd"&gt;private&lt;/span&gt; &lt;span class="kd"&gt;static&lt;/span&gt; &lt;span class="kd"&gt;final&lt;/span&gt; &lt;span class="nc"&gt;ThreadLocal&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;SimpleDateFormat&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;dateParser&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; 
        &lt;span class="nc"&gt;ThreadLocal&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;withInitial&lt;/span&gt;&lt;span class="o"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;SimpleDateFormat&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"yyyy-MM-dd"&lt;/span&gt;&lt;span class="o"&gt;));&lt;/span&gt;

    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="nf"&gt;format&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Date&lt;/span&gt; &lt;span class="n"&gt;date&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="c1"&gt;// No locks or synchronized blocks needed&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;dateParser&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;get&lt;/span&gt;&lt;span class="o"&gt;().&lt;/span&gt;&lt;span class="na"&gt;format&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;date&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Key Takeaways
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;strong&gt;Zero-Overhead Thread Safety:&lt;/strong&gt; If an object never leaves the boundaries of a single thread, you get absolute thread safety for free without any CPU lock overhead.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Stack Confinement is Your Friend:&lt;/strong&gt; Prefer local variables over instance variables; local variables reside on the thread's private execution stack and are naturally confined.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Prevent Memory Leaks:&lt;/strong&gt; When using &lt;code&gt;ThreadLocal&lt;/code&gt; in managed environments (like application servers with thread pools), always call &lt;code&gt;.remove()&lt;/code&gt; to prevent classloader memory leaks.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Full working implementation with execution trace available at &lt;a href="https://javalld.com/learn/thread-confinement" rel="noopener noreferrer"&gt;https://javalld.com/learn/thread-confinement&lt;/a&gt;&lt;/p&gt;

</description>
      <category>java</category>
      <category>concurrency</category>
      <category>design</category>
      <category>interview</category>
    </item>
    <item>
      <title>Stop Guessing JVM Bugs: Connect Claude Code to Spring Boot via Local MCP Actuator Servers</title>
      <dc:creator>Machine coding Master</dc:creator>
      <pubDate>Tue, 14 Jul 2026 05:15:05 +0000</pubDate>
      <link>https://dev.to/machinecodingmaster/stop-guessing-jvm-bugs-connect-claude-code-to-spring-boot-via-local-mcp-actuator-servers-2jfl</link>
      <guid>https://dev.to/machinecodingmaster/stop-guessing-jvm-bugs-connect-claude-code-to-spring-boot-via-local-mcp-actuator-servers-2jfl</guid>
      <description>&lt;h2&gt;
  
  
  Stop Guessing JVM Bugs: Connect Claude Code to Spring Boot via Local MCP Actuator Servers
&lt;/h2&gt;

&lt;p&gt;In 2026, if you are still manually digging through heap dumps or copy-pasting stack traces into a browser chat window to debug a failing Spring Boot app, you are wasting valuable engineering hours. By connecting Claude Code directly to your running JVM via a local Model Context Protocol (MCP) server mapped to Actuator endpoints, you let your AI terminal agent diagnose, patch, and verify runtime state in real-time.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why Most Developers Get This Wrong
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;strong&gt;Static Analysis Delusion:&lt;/strong&gt; They expect Claude to fix runtime memory leaks or thread blocks by looking &lt;em&gt;only&lt;/em&gt; at static source code without seeing the actual JVM state.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Manual Context-Switching:&lt;/strong&gt; They waste time copy-pasting raw JSON payloads from &lt;code&gt;/actuator/metrics&lt;/code&gt; or &lt;code&gt;/actuator/threaddump&lt;/code&gt; into an LLM UI, stripping out vital execution context.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Over-Privileged Agents:&lt;/strong&gt; They expose production JMX or Actuator ports to external cloud LLMs instead of keeping the MCP host bound strictly to &lt;code&gt;localhost&lt;/code&gt; with read-only runtime access.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  The Right Way
&lt;/h2&gt;

&lt;p&gt;Bridge your local CLI agent directly to the running application context using a custom local MCP server that wraps the Spring Boot Actuator REST API.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;strong&gt;Local MCP Bridge:&lt;/strong&gt; Spin up an MCP server that exposes tools like &lt;code&gt;get_thread_dump&lt;/code&gt;, &lt;code&gt;get_active_beans&lt;/code&gt;, and &lt;code&gt;query_metrics&lt;/code&gt; to Claude Code.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Claude Code CLI Tooling:&lt;/strong&gt; Run &lt;code&gt;claude&lt;/code&gt; locally and register the local Actuator MCP server in your agent configuration.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Agentic Auto-Patching Loops:&lt;/strong&gt; Let Claude diagnose a live issue (like a DB connection pool exhaustion), modify the &lt;code&gt;application.yml&lt;/code&gt; or Java source, trigger a hot-reload, and immediately re-query Actuator to verify the fix.&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;I built &lt;a href="https://javalld.com" rel="noopener noreferrer"&gt;javalld.com&lt;/a&gt; while prepping for senior roles — complete LLD problems with execution traces, not just theory.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Show Me The Code (or Example)
&lt;/h2&gt;

&lt;p&gt;Configure your local Claude Code environment to register the Spring Boot Actuator MCP bridge:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="err"&gt;//&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt;~/.config/claude-code/mcp-config.json&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"mcpServers"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"springboot-actuator"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"command"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"npx"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"args"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"-y"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"@mcp/server-springboot-actuator"&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"env"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"ACTUATOR_BASE_URL"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"http://localhost:8080/actuator"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"ACTUATOR_TOKEN"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"local-dev-secret-token"&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, you can simply run:&lt;br&gt;
&lt;code&gt;claude "Why is my database connection pool starving? Check the current HikariCP metrics and fix the config."&lt;/code&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Key Takeaways
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;strong&gt;Zero-Friction Debugging:&lt;/strong&gt; No more manual log scraping; Claude queries live JVM state (like &lt;code&gt;HikariPool&lt;/code&gt; metrics) on demand.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Local-First Security:&lt;/strong&gt; MCP keeps your live system data local, eliminating security risks of sending raw enterprise telemetry to cloud-hosted LLM endpoints.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Tightened Feedback Loops:&lt;/strong&gt; Combining Claude Code's file-writing capabilities with live Actuator verification turns hours of debugging into a 30-second automated cycle.&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>java</category>
      <category>productivity</category>
      <category>ai</category>
      <category>llm</category>
    </item>
    <item>
      <title>Java &amp; AI: What Developers Need to Know</title>
      <dc:creator>Machine coding Master</dc:creator>
      <pubDate>Mon, 13 Jul 2026 05:54:05 +0000</pubDate>
      <link>https://dev.to/machinecodingmaster/java-ai-what-developers-need-to-know-2aia</link>
      <guid>https://dev.to/machinecodingmaster/java-ai-what-developers-need-to-know-2aia</guid>
      <description>&lt;h2&gt;
  
  
  Beyond ReAct: Orchestrating LLM-Guided MCTS Agent Planning with Java Virtual Threads
&lt;/h2&gt;

&lt;p&gt;Naive ReAct loops fail the moment your agent encounters multi-step tool dependencies where an early mistake ruins the entire execution chain. In 2026, enterprise-grade AI agents are shifting to search-based reasoning (o1/o3-style planning) using Monte Carlo Tree Search (MCTS) to evaluate alternative tool paths before committing to execution.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why Most Developers Get This Wrong
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Treating LLMs as deterministic routers:&lt;/strong&gt; Relying on single-step LLM tool calls without state backtracking leads to cascading errors and astronomical API costs.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Platform bottlenecking:&lt;/strong&gt; Running parallel path rollouts (simulations) using heavy OS-backed thread pools that choke under high I/O concurrency.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Ignoring transactional rollbacks:&lt;/strong&gt; Executing destructive tool actions (like database writes) during the "simulation" phase without a robust compensation mechanism.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  The Right Way
&lt;/h2&gt;

&lt;p&gt;We must treat tool execution as a state-space search problem, leveraging Java virtual threads to execute parallel rollout simulations and using fast, structured LLMs (like &lt;code&gt;gpt-4o-mini&lt;/code&gt;) as heuristic evaluators.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Virtual Thread Rollouts:&lt;/strong&gt; Use &lt;code&gt;StructuredTaskScope&lt;/code&gt; to spawn thousands of virtual threads that concurrently simulate different tool paths without blocking OS threads.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Heuristic Node Evaluation:&lt;/strong&gt; Prompt the LLM to return a structured confidence score (0.0 to 1.0) and next-step actions, serving as the MCTS "rollout policy".&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Saga Pattern for Tools:&lt;/strong&gt; Wrap tool executions in a transactional interface supporting &lt;code&gt;execute()&lt;/code&gt; and &lt;code&gt;compensate()&lt;/code&gt; to allow safe backtracking during search.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Show Me The Code
&lt;/h2&gt;

&lt;p&gt;This high-performance Java snippet uses Virtual Threads to run parallel MCTS rollouts and evaluate candidate states concurrently:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;MCTSPlanner&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;private&lt;/span&gt; &lt;span class="kd"&gt;final&lt;/span&gt; &lt;span class="nc"&gt;LLMEvaluator&lt;/span&gt; &lt;span class="n"&gt;llmEvaluator&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;LLMEvaluator&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt; &lt;span class="c1"&gt;// Wraps GPT-4o-mini structured output&lt;/span&gt;

    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="nc"&gt;SearchNode&lt;/span&gt; &lt;span class="nf"&gt;evaluateParallelRollouts&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;List&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;SearchNode&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;candidates&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="kd"&gt;throws&lt;/span&gt; &lt;span class="nc"&gt;Exception&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;try&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;scope&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;StructuredTaskScope&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;ShutdownOnFailure&lt;/span&gt;&lt;span class="o"&gt;())&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
            &lt;span class="nc"&gt;List&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;StructuredTaskScope&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;Subtask&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Double&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;tasks&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;candidates&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;stream&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt;
                &lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;map&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;node&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;scope&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;fork&lt;/span&gt;&lt;span class="o"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;llmEvaluator&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;evaluateState&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;node&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;getState&lt;/span&gt;&lt;span class="o"&gt;())))&lt;/span&gt;
                &lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;toList&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;

            &lt;span class="n"&gt;scope&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;join&lt;/span&gt;&lt;span class="o"&gt;().&lt;/span&gt;&lt;span class="na"&gt;throwIfFailed&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt; &lt;span class="c1"&gt;// Blocks virtual thread, not OS thread&lt;/span&gt;

            &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="n"&gt;candidates&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;size&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="o"&gt;++)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
                &lt;span class="n"&gt;candidates&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;get&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="o"&gt;).&lt;/span&gt;&lt;span class="na"&gt;updateValue&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;tasks&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;get&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="o"&gt;).&lt;/span&gt;&lt;span class="na"&gt;get&lt;/span&gt;&lt;span class="o"&gt;());&lt;/span&gt;
            &lt;span class="o"&gt;}&lt;/span&gt;
        &lt;span class="o"&gt;}&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nf"&gt;selectBestNode&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;candidates&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Key Takeaways
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;ReAct is dead for complex workflows:&lt;/strong&gt; MCTS with backtracking is the new standard for reliable multi-step agent reasoning.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Java is the secret weapon:&lt;/strong&gt; Virtual Threads make Java the ideal platform for I/O-heavy MCTS rollouts, vastly outperforming Node.js or Python.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Sandbox your tools:&lt;/strong&gt; Never run raw tools during search; implement a virtual sandbox or transactional rollbacks to prevent side effects during simulations.&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;I built &lt;a href="https://javalld.com" rel="noopener noreferrer"&gt;javalld.com&lt;/a&gt; while prepping for senior roles — complete LLD problems with execution traces, not just theory.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;---JSON&lt;br&gt;
{"title": "Beyond ReAct: Orchestrating LLM-Guided MCTS Agent Planning with Java Virtual Threads", "tags": ["java", "concurrency", "ai", "llm"]}&lt;br&gt;
---END---&lt;/p&gt;

</description>
      <category>java</category>
      <category>programming</category>
      <category>ai</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Stop Paying Full Price: Orchestrate Claude's 50% Off Batch API with Spring Batch and Virtual Threads</title>
      <dc:creator>Machine coding Master</dc:creator>
      <pubDate>Sun, 12 Jul 2026 05:42:54 +0000</pubDate>
      <link>https://dev.to/machinecodingmaster/stop-paying-full-price-orchestrate-claudes-50-off-batch-api-with-spring-batch-and-virtual-threads-3imi</link>
      <guid>https://dev.to/machinecodingmaster/stop-paying-full-price-orchestrate-claudes-50-off-batch-api-with-spring-batch-and-virtual-threads-3imi</guid>
      <description>&lt;h2&gt;
  
  
  Stop Paying Full Price: Orchestrate Claude's 50% Off Batch API with Spring Batch and Virtual Threads
&lt;/h2&gt;

&lt;p&gt;In 2026, firing synchronous API calls to Claude 3.5 Sonnet for offline workloads like data labeling or document summarization is a fireable offense for your cloud budget. If your processing doesn't require sub-second human interaction, you must route it through Anthropic’s 50%-off Batch API using a robust, self-healing orchestration pipeline.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why Most Developers Get This Wrong
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;strong&gt;The "Thread-Per-Request" Trap:&lt;/strong&gt; Spawning OS-level threads or blocking WebClient pools while waiting up to 24 hours for Anthropic's batch execution to complete, wasting massive memory.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Fragile State Management:&lt;/strong&gt; Writing custom, half-baked database polling logic to check batch statuses (&lt;code&gt;canceling&lt;/code&gt;, &lt;code&gt;processing&lt;/code&gt;, &lt;code&gt;ended&lt;/code&gt;) instead of leveraging a proven state machine.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Ignoring Rate Limits:&lt;/strong&gt; Flooding the Batch API creation endpoint without chunking, hitting rate limits before the actual asynchronous execution even begins.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  The Right Way
&lt;/h2&gt;

&lt;p&gt;Combine the declarative chunk-processing of Spring Batch 5.x with the lightweight, non-blocking polling of Java 21+ Virtual Threads to manage the lifecycle of Anthropic's asynchronous batch jobs.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  Use &lt;code&gt;TaskExecutor&lt;/code&gt; configured with &lt;code&gt;Executors.newVirtualThreadPerTaskExecutor()&lt;/code&gt; in your Spring Batch step configuration to handle non-blocking, asynchronous polling of the Claude Batch API endpoint (&lt;code&gt;/v1/messages/batches&lt;/code&gt;).&lt;/li&gt;
&lt;li&gt;  Persist batch job IDs (&lt;code&gt;msg_batch_xxxxxxxx&lt;/code&gt;) directly in the Spring Batch metadata database (&lt;code&gt;BATCH_JOB_EXECUTION_PARAMS&lt;/code&gt;) to ensure seamless resume-on-failure capabilities.&lt;/li&gt;
&lt;li&gt;  Implement an exponential backoff polling strategy using Virtual Threads (&lt;code&gt;Thread.sleep()&lt;/code&gt;) that yields the carrier thread, keeping your memory footprint at near-zero during the 24-hour SLA window.&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;Want to go deeper? &lt;a href="https://javalld.com" rel="noopener noreferrer"&gt;javalld.com&lt;/a&gt; — machine coding interview problems with working Java code and full execution traces.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Show Me The Code (or Example)
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="nd"&gt;@Bean&lt;/span&gt;
&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="nc"&gt;Step&lt;/span&gt; &lt;span class="nf"&gt;pollClaudeBatchStep&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;JobRepository&lt;/span&gt; &lt;span class="n"&gt;jobRepository&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;PlatformTransactionManager&lt;/span&gt; &lt;span class="n"&gt;txManager&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nf"&gt;StepBuilder&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"pollClaudeBatchStep"&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;jobRepository&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;
        &lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;tasklet&lt;/span&gt;&lt;span class="o"&gt;((&lt;/span&gt;&lt;span class="n"&gt;contribution&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;chunkContext&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
            &lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;batchId&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;String&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="n"&gt;chunkContext&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;getStepContext&lt;/span&gt;&lt;span class="o"&gt;().&lt;/span&gt;&lt;span class="na"&gt;getJobParameters&lt;/span&gt;&lt;span class="o"&gt;().&lt;/span&gt;&lt;span class="na"&gt;get&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"claudeBatchId"&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
            &lt;span class="k"&gt;while&lt;/span&gt; &lt;span class="o"&gt;(!&lt;/span&gt;&lt;span class="n"&gt;isBatchComplete&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;batchId&lt;/span&gt;&lt;span class="o"&gt;))&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
                &lt;span class="c1"&gt;// Virtual thread yields gracefully here without blocking OS threads&lt;/span&gt;
                &lt;span class="nc"&gt;Thread&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;sleep&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Duration&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;ofMinutes&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="o"&gt;));&lt;/span&gt; 
            &lt;span class="o"&gt;}&lt;/span&gt;
            &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nc"&gt;RepeatStatus&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;FINISHED&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
        &lt;span class="o"&gt;},&lt;/span&gt; &lt;span class="n"&gt;txManager&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;
        &lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;taskExecutor&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Executors&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;newVirtualThreadPerTaskExecutor&lt;/span&gt;&lt;span class="o"&gt;())&lt;/span&gt; 
        &lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;build&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Key Takeaways
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;strong&gt;50% Cost Reduction:&lt;/strong&gt; Shifting non-real-time LLM requests to Claude’s &lt;code&gt;/v1/messages/batches&lt;/code&gt; instantly cuts your API bill in half.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Resource Efficiency:&lt;/strong&gt; Virtual threads turn idle waiting time into zero-overhead operations, allowing a single JVM to monitor thousands of concurrent Claude batches.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Enterprise Reliability:&lt;/strong&gt; Spring Batch provides the transactional integrity, restartability, and execution history needed to manage long-running AI workflows at scale.&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>java</category>
      <category>concurrency</category>
      <category>ai</category>
      <category>llm</category>
    </item>
    <item>
      <title>Java &amp; AI: What Developers Need to Know</title>
      <dc:creator>Machine coding Master</dc:creator>
      <pubDate>Sat, 11 Jul 2026 05:27:01 +0000</pubDate>
      <link>https://dev.to/machinecodingmaster/java-ai-what-developers-need-to-know-5556</link>
      <guid>https://dev.to/machinecodingmaster/java-ai-what-developers-need-to-know-5556</guid>
      <description>&lt;h2&gt;
  
  
  Stop Relying on Pure Vector Similarity: Build Self-Querying Retrievers with Spring AI Filter Expressions
&lt;/h2&gt;

&lt;p&gt;Pure vector similarity search is a lazy shortcut that inevitably fails in production because math doesn't understand your business rules. In 2026, production-grade RAG systems require deterministic metadata filtering driven dynamically by LLMs, not just naive cosine similarity.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why Most Developers Get This Wrong
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;strong&gt;Over-relying on embeddings:&lt;/strong&gt; Trying to encode scalar values like pricing, timestamps, or tenant IDs into a high-dimensional vector space is a fool's errand.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Hardcoded filters:&lt;/strong&gt; Writing static metadata filters in Java completely defeats the purpose of a dynamic natural language interface.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Ignoring the database AST:&lt;/strong&gt; Manually parsing user intent with regex or custom string manipulation instead of leveraging a structured Abstract Syntax Tree (AST).&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  The Right Way
&lt;/h2&gt;

&lt;p&gt;Use a Self-Querying Retriever pattern where an LLM translates natural language into a structured Spring AI &lt;code&gt;Filter.Expression&lt;/code&gt; AST.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;strong&gt;Dynamic Translation:&lt;/strong&gt; Prompt your LLM (like GPT-4o) to output a clean JSON representation of the query's metadata constraints.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;AST Mapping:&lt;/strong&gt; Parse that JSON directly into Spring AI's native &lt;code&gt;Filter.Expression&lt;/code&gt; using the &lt;code&gt;FilterExpressionBuilder&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Hybrid Execution:&lt;/strong&gt; Pass this AST to your &lt;code&gt;VectorStore&lt;/code&gt; (like PgVector or Milvus) to execute hard metadata filtering at the database level before calculating vector similarity.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Show Me The Code
&lt;/h2&gt;

&lt;p&gt;Here is how you programmatically build and apply dynamic metadata filters using Spring AI:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="nc"&gt;FilterExpressionBuilder&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;FilterExpressionBuilder&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
&lt;span class="nc"&gt;Filter&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;Expression&lt;/span&gt; &lt;span class="n"&gt;metadataFilter&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;and&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;
    &lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;eq&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"status"&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"ACTIVE"&lt;/span&gt;&lt;span class="o"&gt;),&lt;/span&gt;
    &lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;gte&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"rating"&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="mf"&gt;4.5&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;
&lt;span class="o"&gt;);&lt;/span&gt;

&lt;span class="nc"&gt;SearchRequest&lt;/span&gt; &lt;span class="n"&gt;request&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;SearchRequest&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;builder&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt;
    &lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;query&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Spring AI performance optimization"&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;
    &lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;topK&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;
    &lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;similarityThreshold&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="mf"&gt;0.8&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;
    &lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;filterExpression&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;metadataFilter&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;
    &lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;build&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;

&lt;span class="nc"&gt;List&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Document&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;results&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;vectorStore&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;similaritySearch&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;request&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Key Takeaways
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;strong&gt;Stop wasting tokens:&lt;/strong&gt; Pre-filtering via metadata reduces the vector search space, making your similarity search both faster and significantly cheaper.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Spring AI AST is king:&lt;/strong&gt; The &lt;code&gt;Filter.Expression&lt;/code&gt; API abstracts database-specific syntax, keeping your Java code portable across PgVector, Milvus, and Qdrant.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;LLMs are parsers, not just generators:&lt;/strong&gt; Use LLMs to extract structured filter JSON from user queries to feed your backend, rather than letting them guess raw vector matches.&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Heads up:&lt;/strong&gt; if you want to see these patterns applied to real interview problems, &lt;a href="https://javalld.com" rel="noopener noreferrer"&gt;javalld.com&lt;/a&gt; has full machine coding solutions with traces.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;---JSON&lt;br&gt;
{"title": "Stop Relying on Pure Vector Similarity: Build Self-Querying Retrievers with Spring AI Filter Expressions", "tags": ["java", "ai", "llm", "systemdesign"]}&lt;br&gt;
---END---&lt;/p&gt;

</description>
      <category>java</category>
      <category>programming</category>
      <category>ai</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Mastering Java Concurrency LLD: Why You Need Semaphores for Rate Limiting</title>
      <dc:creator>Machine coding Master</dc:creator>
      <pubDate>Fri, 10 Jul 2026 06:28:22 +0000</pubDate>
      <link>https://dev.to/machinecodingmaster/mastering-java-concurrency-lld-why-you-need-semaphores-for-rate-limiting-4a7</link>
      <guid>https://dev.to/machinecodingmaster/mastering-java-concurrency-lld-why-you-need-semaphores-for-rate-limiting-4a7</guid>
      <description>&lt;h2&gt;
  
  
  Mastering Java Concurrency LLD: Why You Need Semaphores for Rate Limiting
&lt;/h2&gt;

&lt;p&gt;During my time at Apple and Amazon, I saw countless LLD interviews fall apart because candidates didn't know how to throttle resource access. If you are asked to design a Connection Pool or a Rate Limiter in a machine coding round, reaching for standard locks is often a trap.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Mistake Most Candidates Make
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Using heavy locks:&lt;/strong&gt; Relying on &lt;code&gt;synchronized&lt;/code&gt; blocks that block everything, destroying throughput and causing thread starvation.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Manual signaling wheels:&lt;/strong&gt; Manually managing thread sleep/wake cycles with &lt;code&gt;wait()&lt;/code&gt; and &lt;code&gt;notify()&lt;/code&gt;, which is highly error-prone and leads to deadlocks.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Confusing Mutex with Semaphore:&lt;/strong&gt; Using a binary lock when the system needs to allow a controlled number of concurrent resource users.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  The Right Approach
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Core mental model:&lt;/strong&gt; Think of a Semaphore as a bouncer at a club—it only lets a fixed number of guests (threads) inside at any given time.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Key entities/classes:&lt;/strong&gt; &lt;code&gt;java.util.concurrent.Semaphore&lt;/code&gt;, &lt;code&gt;acquire()&lt;/code&gt;, and &lt;code&gt;release()&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Why it beats the naive approach:&lt;/strong&gt; It natively handles thread queuing and signaling under the hood without brittle, manual state checks.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  The Key Insight (Code)
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;ConnectionPool&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;private&lt;/span&gt; &lt;span class="kd"&gt;final&lt;/span&gt; &lt;span class="nc"&gt;Semaphore&lt;/span&gt; &lt;span class="n"&gt;bouncer&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Semaphore&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// Max 10 connections&lt;/span&gt;

    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="nc"&gt;Connection&lt;/span&gt; &lt;span class="nf"&gt;getConnection&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="kd"&gt;throws&lt;/span&gt; &lt;span class="nc"&gt;InterruptedException&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;bouncer&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;acquire&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt; &lt;span class="c1"&gt;// Blocks if count is 0&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nf"&gt;fetchActualConnection&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;

    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;releaseConnection&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Connection&lt;/span&gt; &lt;span class="n"&gt;conn&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;returnToPool&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;conn&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
        &lt;span class="n"&gt;bouncer&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;release&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt; &lt;span class="c1"&gt;// Increments count, wakes up waiting thread&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Key Takeaways
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Permit-based throttling:&lt;/strong&gt; Semaphores maintain a set of permits; &lt;code&gt;acquire()&lt;/code&gt; decrements and blocks when 0, while &lt;code&gt;release()&lt;/code&gt; increments the count.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;No thread ownership:&lt;/strong&gt; Unlike locks, any thread can call &lt;code&gt;release()&lt;/code&gt;, making them highly flexible for producer-consumer handoffs.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Perfect for bounds:&lt;/strong&gt; Always use them when you need to enforce hard limits on physical resources like database connections or API rate limiters.&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;Shameless plug: &lt;a href="https://javalld.com" rel="noopener noreferrer"&gt;javalld.com&lt;/a&gt; has full LLD implementations with step-by-step execution traces — free to use while prepping.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Full working implementation with execution trace available at &lt;a href="https://javalld.com/learn/semaphore-pool" rel="noopener noreferrer"&gt;https://javalld.com/learn/semaphore-pool&lt;/a&gt;&lt;/p&gt;

</description>
      <category>java</category>
      <category>concurrency</category>
      <category>interview</category>
      <category>systemdesign</category>
    </item>
    <item>
      <title>Java Concurrency LLD: Master ReentrantLock and Condition for Precise Thread Signaling</title>
      <dc:creator>Machine coding Master</dc:creator>
      <pubDate>Wed, 08 Jul 2026 05:36:59 +0000</pubDate>
      <link>https://dev.to/machinecodingmaster/java-concurrency-lld-master-reentrantlock-and-condition-for-precise-thread-signaling-8n7</link>
      <guid>https://dev.to/machinecodingmaster/java-concurrency-lld-master-reentrantlock-and-condition-for-precise-thread-signaling-8n7</guid>
      <description>&lt;h2&gt;
  
  
  Java Concurrency LLD: Master ReentrantLock and Condition for Precise Thread Signaling
&lt;/h2&gt;

&lt;p&gt;In senior Java LLD interviews, designing thread-safe components like a bounded buffer or rate limiter requires precise thread signaling. If you are still relying on &lt;code&gt;synchronized&lt;/code&gt; blocks and &lt;code&gt;Object.wait()&lt;/code&gt;, you are likely failing the concurrency bar at Big Tech.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;I built &lt;a href="https://javalld.com" rel="noopener noreferrer"&gt;javalld.com&lt;/a&gt; while prepping for senior roles — complete LLD problems with execution traces, not just theory.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  The Mistake Most Candidates Make
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;strong&gt;Using intrinsic locks with &lt;code&gt;Object.wait()&lt;/code&gt;:&lt;/strong&gt; This forces all threads (producers and consumers) into a single wait-set, requiring a broad &lt;code&gt;notifyAll()&lt;/code&gt; that causes massive thread contention.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Ignoring spurious wakeups:&lt;/strong&gt; Failing to re-evaluate the state condition in a loop when using time-bound wait methods.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Lacking time precision:&lt;/strong&gt; Relying on &lt;code&gt;Thread.sleep()&lt;/code&gt; or imprecise millisecond wait timeouts, which degrades system throughput under heavy load.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  The Right Approach
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;strong&gt;Core mental model:&lt;/strong&gt; Decouple the mutual exclusion lock from conditional signaling by using dedicated wait-sets for distinct business conditions.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Key entities/classes:&lt;/strong&gt; &lt;code&gt;ReentrantLock&lt;/code&gt;, &lt;code&gt;Condition&lt;/code&gt;, &lt;code&gt;TimeUnit&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Why it beats the naive approach:&lt;/strong&gt; It eliminates spurious wakeup bugs and allows you to target and wake up only the exact subset of threads that can actually make progress.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  The Key Insight (Code)
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kd"&gt;private&lt;/span&gt; &lt;span class="kd"&gt;final&lt;/span&gt; &lt;span class="nc"&gt;ReentrantLock&lt;/span&gt; &lt;span class="n"&gt;lock&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;ReentrantLock&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
&lt;span class="kd"&gt;private&lt;/span&gt; &lt;span class="kd"&gt;final&lt;/span&gt; &lt;span class="nc"&gt;Condition&lt;/span&gt; &lt;span class="n"&gt;notEmpty&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;lock&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;newCondition&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;

&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="nc"&gt;Object&lt;/span&gt; &lt;span class="nf"&gt;poll&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;long&lt;/span&gt; &lt;span class="n"&gt;timeout&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;TimeUnit&lt;/span&gt; &lt;span class="n"&gt;unit&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="kd"&gt;throws&lt;/span&gt; &lt;span class="nc"&gt;InterruptedException&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;lock&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;lock&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
    &lt;span class="k"&gt;try&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="kt"&gt;long&lt;/span&gt; &lt;span class="n"&gt;nanos&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;unit&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;toNanos&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;timeout&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
        &lt;span class="k"&gt;while&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;queue&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;isEmpty&lt;/span&gt;&lt;span class="o"&gt;())&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
            &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;nanos&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;=&lt;/span&gt; &lt;span class="mi"&gt;0L&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// Timeout reached safely&lt;/span&gt;
            &lt;span class="n"&gt;nanos&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;notEmpty&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;awaitNanos&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;nanos&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// Spurious wakeup safe&lt;/span&gt;
        &lt;span class="o"&gt;}&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;queue&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;poll&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt; &lt;span class="k"&gt;finally&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;lock&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;unlock&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Key Takeaways
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;strong&gt;Multiple Conditions per Lock:&lt;/strong&gt; &lt;code&gt;ReentrantLock&lt;/code&gt; allows creating separate &lt;code&gt;Condition&lt;/code&gt; instances (e.g., &lt;code&gt;notFull&lt;/code&gt; and &lt;code&gt;notEmpty&lt;/code&gt;) to signal specific thread groups.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Time-Remaining Tracking:&lt;/strong&gt; &lt;code&gt;Condition.awaitNanos(nanos)&lt;/code&gt; returns the remaining time, letting you safely loop and resume waiting without losing track of the original timeout.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Targeted Signaling:&lt;/strong&gt; Calling &lt;code&gt;condition.signal()&lt;/code&gt; wakes up exactly one thread waiting on that specific condition, eliminating the CPU overhead of global &lt;code&gt;notifyAll()&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Full working implementation with execution trace available at &lt;a href="https://javalld.com/learn/condition-await" rel="noopener noreferrer"&gt;https://javalld.com/learn/condition-await&lt;/a&gt;&lt;/p&gt;

</description>
      <category>java</category>
      <category>concurrency</category>
      <category>interview</category>
      <category>design</category>
    </item>
    <item>
      <title>Taming LLM Tail Latency: Dynamic Request Hedging with Java's JEP 480 Structured Concurrency</title>
      <dc:creator>Machine coding Master</dc:creator>
      <pubDate>Tue, 07 Jul 2026 06:30:29 +0000</pubDate>
      <link>https://dev.to/machinecodingmaster/taming-llm-tail-latency-dynamic-request-hedging-with-javas-jep-480-structured-concurrency-img</link>
      <guid>https://dev.to/machinecodingmaster/taming-llm-tail-latency-dynamic-request-hedging-with-javas-jep-480-structured-concurrency-img</guid>
      <description>&lt;h2&gt;
  
  
  Taming LLM Tail Latency: Dynamic Request Hedging with Java's JEP 480 Structured Concurrency
&lt;/h2&gt;

&lt;p&gt;In 2026, relying on unpredictable third-party LLM APIs means your p99.9 latency is completely at the mercy of upstream cold starts and token-generation hiccups. If you aren't actively hedging your requests using Java's modern concurrency primitives, you are burning your SLA budgets for no reason.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why Most Developers Get This Wrong
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Unmanaged Asynchrony:&lt;/strong&gt; Spawning unmanaged &lt;code&gt;CompletableFuture&lt;/code&gt; instances that leak threads and ignore task cancellation when the primary request finally succeeds.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Static Timeout Guesses:&lt;/strong&gt; Using hardcoded timeouts instead of dynamic, histogram-based p90 thresholds, leading to either uselessly late hedges or massive, self-inflicted DDoS on downstream endpoints.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Orphaned Sockets:&lt;/strong&gt; Failing to propagate cancellation signals down the HTTP client stack, leaving orphaned network connections consuming socket pools.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  The Right Way
&lt;/h2&gt;

&lt;p&gt;The gold standard is dynamic request hedging: firing a secondary, "hedged" request only if the primary fails to respond within a dynamic p90 window, managed cleanly via JEP 480's &lt;code&gt;StructuredTaskScope&lt;/code&gt;.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Leverage ShutdownOnSuccess:&lt;/strong&gt; Use &lt;code&gt;StructuredTaskScope.ShutdownOnSuccess&lt;/code&gt; to automatically cancel the slower sibling task the millisecond the faster one completes.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Dynamic Delay Injection:&lt;/strong&gt; Calculate the hedging delay dynamically using a sliding-window percentile (e.g., p90 of the last 1,000 LLM calls) rather than hardcoding a static &lt;code&gt;sleep&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Virtual Thread Backing:&lt;/strong&gt; Run your scopes on virtual threads to handle the extra concurrency overhead without risk of thread-pool starvation.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Show Me The Code
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="nf"&gt;hedgeLLMRequest&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;prompt&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;Duration&lt;/span&gt; &lt;span class="n"&gt;dynamicP90&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="kd"&gt;throws&lt;/span&gt; &lt;span class="nc"&gt;Exception&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;try&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;scope&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;StructuredTaskScope&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;ShutdownOnSuccess&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;String&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;())&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="c1"&gt;// Primary task starts immediately&lt;/span&gt;
        &lt;span class="n"&gt;scope&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;fork&lt;/span&gt;&lt;span class="o"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;callLLM&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;prompt&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"primary-provider"&lt;/span&gt;&lt;span class="o"&gt;));&lt;/span&gt;

        &lt;span class="c1"&gt;// Hedged task forks only after the dynamic p90 threshold&lt;/span&gt;
        &lt;span class="n"&gt;scope&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;fork&lt;/span&gt;&lt;span class="o"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
            &lt;span class="nc"&gt;Thread&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;sleep&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;dynamicP90&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
            &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nf"&gt;callLLM&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;prompt&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"backup-provider"&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
        &lt;span class="o"&gt;});&lt;/span&gt;

        &lt;span class="n"&gt;scope&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;join&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt; &lt;span class="c1"&gt;// Blocks until the first task completes successfully&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;scope&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;result&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt; &lt;span class="c1"&gt;// Returns fastest result, automatically cancelling the other&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Key Takeaways
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Deterministic Lifetimes:&lt;/strong&gt; JEP 480 &lt;code&gt;StructuredTaskScope&lt;/code&gt; turns complex, leak-prone asynchronous coordination into clean, block-scoped, deterministic code.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Resource Hygiene:&lt;/strong&gt; Always pair hedging with an HTTP client that respects thread interruption to ensure cancelled tasks immediately close underlying TCP sockets.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Tail-Latency Killer:&lt;/strong&gt; Dynamic hedging is your ultimate weapon against the chaotic, non-deterministic latency profiles of modern AI agent architectures.&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;If you're prepping for interviews, I've been building &lt;a href="https://javalld.com" rel="noopener noreferrer"&gt;javalld.com&lt;/a&gt; — real machine coding problems with full execution traces.&lt;/p&gt;
&lt;/blockquote&gt;

</description>
      <category>java</category>
      <category>concurrency</category>
      <category>systemdesign</category>
      <category>llm</category>
    </item>
    <item>
      <title>Java &amp; AI: What Developers Need to Know</title>
      <dc:creator>Machine coding Master</dc:creator>
      <pubDate>Sun, 05 Jul 2026 06:25:01 +0000</pubDate>
      <link>https://dev.to/machinecodingmaster/java-ai-what-developers-need-to-know-1en0</link>
      <guid>https://dev.to/machinecodingmaster/java-ai-what-developers-need-to-know-1en0</guid>
      <description>&lt;h2&gt;
  
  
  Stop the ReAct Chaos: Building Deterministic Multi-Agent Cycles with Spring AI Graph
&lt;/h2&gt;

&lt;p&gt;If you are still letting LLMs freely decide their next execution step in an unconstrained ReAct loop, you are burning cloud budget on infinite loops and non-deterministic failures. In 2026, enterprise-grade AI requires the strict guardrails of stateful, cyclic graphs where transitions are governed by code, not LLM vibes.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why Most Developers Get This Wrong
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;strong&gt;Naive ReAct Loops:&lt;/strong&gt; Relying entirely on prompt-based tool calling to determine flow, which inevitably derails after 3-4 turns.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Stateless Agents:&lt;/strong&gt; Passing massive, unmanaged chat histories back and forth instead of maintaining a single, thread-safe state object.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Lack of Edge Controls:&lt;/strong&gt; Failing to hardcode conditional transitions, letting the LLM hallucinate its way into non-existent API endpoints.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  The Right Way
&lt;/h2&gt;

&lt;p&gt;The solution is to model your multi-agent system as a deterministic, cyclic graph where the LLM only executes node-level tasks, while Java code controls the state transitions.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;strong&gt;Define an Immutable State:&lt;/strong&gt; Use Java &lt;code&gt;record&lt;/code&gt; types to represent the thread-safe state passed between nodes.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Explicit Nodes and Edges:&lt;/strong&gt; Map agents (e.g., Writer, Critic) to discrete nodes and use conditional routers to decide the next transition.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Spring AI Graph API:&lt;/strong&gt; Leverage Spring AI 1.2.0's &lt;code&gt;StatefulGraph&lt;/code&gt; to manage state persistence and concurrent transitions out-of-the-box.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Model Specialization:&lt;/strong&gt; Use fast, cheap models (like Llama 3.3) for routing decisions, and reasoning models (like Claude 3.5 Sonnet) only for complex node tasks.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Show Me The Code (or Example)
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Define stateful graph with immutable State record&lt;/span&gt;
&lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;workflow&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;StatefulGraph&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;AgentState&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;()&lt;/span&gt;
    &lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;addNode&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"writer"&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;state&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;writerAgent&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;call&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;state&lt;/span&gt;&lt;span class="o"&gt;))&lt;/span&gt;
    &lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;addNode&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"critic"&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;state&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;criticAgent&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;call&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;state&lt;/span&gt;&lt;span class="o"&gt;))&lt;/span&gt;
    &lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;addEdge&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="no"&gt;START&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"writer"&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;
    &lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;addEdge&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"writer"&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"critic"&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;
    &lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;addConditionalEdge&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"critic"&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;state&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;state&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;isApproved&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;?&lt;/span&gt; &lt;span class="no"&gt;END&lt;/span&gt; &lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="s"&gt;"writer"&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// Deterministic cycle&lt;/span&gt;
    &lt;span class="o"&gt;});&lt;/span&gt;

&lt;span class="nc"&gt;AgentState&lt;/span&gt; &lt;span class="n"&gt;finalState&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;workflow&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;compile&lt;/span&gt;&lt;span class="o"&gt;().&lt;/span&gt;&lt;span class="na"&gt;execute&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;AgentState&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Draft context"&lt;/span&gt;&lt;span class="o"&gt;));&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Key Takeaways
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;strong&gt;Control the Flow, Not the Agent:&lt;/strong&gt; Keep LLMs inside the nodes; your Java code must own the edges.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Thread-Safety is Native:&lt;/strong&gt; Spring AI Graph manages state transitions safely across concurrent JVM threads, eliminating manual synchronization.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Fewer Tokens, Better Accuracy:&lt;/strong&gt; Deterministic routing cuts out the prompt overhead of ReAct, saving up to 40% in token costs.&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Heads up:&lt;/strong&gt; if you want to see these patterns applied to real interview problems, &lt;a href="https://javalld.com" rel="noopener noreferrer"&gt;javalld.com&lt;/a&gt; has full machine coding solutions with traces.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;---JSON&lt;br&gt;
{"title": "Stop the ReAct Chaos: Building Deterministic Multi-Agent Cycles with Spring AI Graph", "tags": ["java", "ai", "llm", "design"]}&lt;br&gt;
---END---&lt;/p&gt;

</description>
      <category>java</category>
      <category>programming</category>
      <category>ai</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Your Agent Loop Just Cost $1,000: Instrumenting Spring AI with OpenTelemetry GenAI Conventions</title>
      <dc:creator>Machine coding Master</dc:creator>
      <pubDate>Sat, 04 Jul 2026 06:00:01 +0000</pubDate>
      <link>https://dev.to/machinecodingmaster/your-agent-loop-just-cost-1000-instrumenting-spring-ai-with-opentelemetry-genai-conventions-511b</link>
      <guid>https://dev.to/machinecodingmaster/your-agent-loop-just-cost-1000-instrumenting-spring-ai-with-opentelemetry-genai-conventions-511b</guid>
      <description>&lt;h2&gt;
  
  
  Your Agent Loop Just Cost $1,000: Instrumenting Spring AI with OpenTelemetry GenAI Conventions
&lt;/h2&gt;

&lt;p&gt;In 2026, deploying multi-agent systems without strict observability is a fast track to explaining a five-figure cloud bill to your CTO. If you aren't tracing token consumption down to the individual agent step using standardized telemetry, you are flying blind in production.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why Most Developers Get This Wrong
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Relying on custom JSON log-parsing hacks:&lt;/strong&gt; Developers waste weeks writing custom log parsers to extract token counts, which inevitably break when model providers update their payload schemas.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Treating agent loops as generic HTTP dependencies:&lt;/strong&gt; Standard HTTP span metrics only tell you &lt;em&gt;that&lt;/em&gt; a call happened; they hide the critical recursive tool-calling chains that spiral into infinite loops.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Ignoring OTel standards:&lt;/strong&gt; Building proprietary metric schemas instead of adopting the standardized OpenTelemetry GenAI Semantic Conventions creates massive vendor lock-in.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  The Right Way
&lt;/h2&gt;

&lt;p&gt;Standardize your observability stack by binding Spring AI's native Micrometer Observation API directly to OpenTelemetry's GenAI semantic conventions to capture token-level metrics automatically.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Use standardized attributes:&lt;/strong&gt; Map model executions to standard OTel attributes like &lt;code&gt;gen_ai.request.model&lt;/code&gt;, &lt;code&gt;gen_ai.usage.prompt_tokens&lt;/code&gt;, and &lt;code&gt;gen_ai.usage.completion_tokens&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Correlate spans with Trace Context:&lt;/strong&gt; Propagate W3C trace headers through your vector database queries, tool executions, and LLM calls to visualize the entire agent lifecycle in one trace.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Enforce runtime budget limits:&lt;/strong&gt; Intercept the &lt;code&gt;Observation&lt;/code&gt; lifecycle to dynamically kill trace contexts when an agent's cumulative token cost exceeds a predefined threshold.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Show Me The Code
&lt;/h2&gt;

&lt;p&gt;Configure Spring AI's &lt;code&gt;ChatClient&lt;/code&gt; with native observation support and custom token-tracking advisors:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="nd"&gt;@Configuration&lt;/span&gt;
&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;ObservabilityConfig&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;

    &lt;span class="nd"&gt;@Bean&lt;/span&gt;
    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="nc"&gt;ChatClient&lt;/span&gt; &lt;span class="nf"&gt;chatClient&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;ChatModel&lt;/span&gt; &lt;span class="n"&gt;chatModel&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;ObservationRegistry&lt;/span&gt; &lt;span class="n"&gt;registry&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nc"&gt;ChatClient&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;builder&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;chatModel&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;
            &lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;observationRegistry&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;registry&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;
            &lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;defaultAdvisors&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;
                &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nf"&gt;SimpleLoggerAdvisor&lt;/span&gt;&lt;span class="o"&gt;(),&lt;/span&gt;
                &lt;span class="c1"&gt;// Native Spring AI advisor capturing OTel GenAI conventions&lt;/span&gt;
                &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nf"&gt;TokenUsageTrackingAdvisor&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt; 
            &lt;span class="o"&gt;)&lt;/span&gt;
            &lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;build&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Key Takeaways
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Stop reinventing the wheel:&lt;/strong&gt; Let Spring AI's integration with Micrometer map directly to OpenTelemetry's standard &lt;code&gt;gen_ai.*&lt;/code&gt; semantic attributes.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Alert on token burn rates:&lt;/strong&gt; Set up real-time alerting on the rate of &lt;code&gt;gen_ai.client.token.usage&lt;/code&gt; metrics to catch rogue agent loops before they drain your budget.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Trace the entire chain:&lt;/strong&gt; Ensure your vector stores (e.g., PgVector) and custom tools are instrumented so you can pinpoint whether high latency stems from the model or your retrieval step.&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Heads up:&lt;/strong&gt; if you want to see these patterns applied to real interview problems, &lt;a href="https://javalld.com" rel="noopener noreferrer"&gt;javalld.com&lt;/a&gt; has full machine coding solutions with traces.&lt;/p&gt;
&lt;/blockquote&gt;

</description>
      <category>java</category>
      <category>ai</category>
      <category>llm</category>
      <category>systemdesign</category>
    </item>
    <item>
      <title>Stop Over-Serializing gRPC: Zero-Copy Microservice-to-Sidecar IPC with Project Panama</title>
      <dc:creator>Machine coding Master</dc:creator>
      <pubDate>Fri, 03 Jul 2026 06:09:55 +0000</pubDate>
      <link>https://dev.to/machinecodingmaster/stop-over-serializing-grpc-zero-copy-microservice-to-sidecar-ipc-with-project-panama-3k72</link>
      <guid>https://dev.to/machinecodingmaster/stop-over-serializing-grpc-zero-copy-microservice-to-sidecar-ipc-with-project-panama-3k72</guid>
      <description>&lt;h2&gt;
  
  
  Stop Over-Serializing gRPC: Zero-Copy Microservice-to-Sidecar IPC with Project Panama
&lt;/h2&gt;

&lt;p&gt;Now that Virtual Threads have completely eliminated our I/O bottlenecks in 2026, the biggest tax on your microservice CPU is no longer network transit—it's serialization. If your Java service is burning massive CPU cycles translating POJOs to Protobuf just to talk to a local Envoy or Linkerd sidecar over localhost, you are wasting infrastructure spend.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Heads up:&lt;/strong&gt; if you want to see these patterns applied to real interview problems, &lt;a href="https://javalld.com" rel="noopener noreferrer"&gt;javalld.com&lt;/a&gt; has full machine coding solutions with traces.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Why Most Developers Get This Wrong
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Defaulting to Loopback TCP:&lt;/strong&gt; Relying on gRPC over localhost loopback, which forces useless serialization/deserialization cycles and kernel-space copying for local IPC.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Relying on Legacy Hacks:&lt;/strong&gt; Using brittle, insecure &lt;code&gt;sun.misc.Unsafe&lt;/code&gt; or unstable JNI wrappers to access shared memory, both of which break on modern JDKs.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Ignoring the CPU Bottleneck:&lt;/strong&gt; Optimizing network I/O when the actual bottleneck is the CPU overhead of Protobuf marshaling inside your service-mesh sidecar architecture.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  The Right Way
&lt;/h2&gt;

&lt;p&gt;Bypass the network stack entirely by using Project Panama's Foreign Function &amp;amp; Memory API (JEP 454) to map POSIX shared memory (&lt;code&gt;shm_open&lt;/code&gt;) directly into Java &lt;code&gt;MemorySegment&lt;/code&gt; instances.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Deterministic Off-Heap Lifecycle:&lt;/strong&gt; Manage off-heap memory safely without GC overhead using &lt;code&gt;Arena.ofShared()&lt;/code&gt; or &lt;code&gt;Arena.ofConfined()&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Zero-Copy Data Transfer:&lt;/strong&gt; Write structured, schema-defined binary data directly to raw memory using &lt;code&gt;VarHandle&lt;/code&gt; accessors instead of generating intermediate Protobuf objects.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Native POSIX Binding:&lt;/strong&gt; Bind directly to &lt;code&gt;shm_open&lt;/code&gt; and &lt;code&gt;mmap&lt;/code&gt; using Panama’s &lt;code&gt;Linker&lt;/code&gt; and &lt;code&gt;SymbolLookup&lt;/code&gt; for bare-metal performance.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Ring-Buffer Synchronization:&lt;/strong&gt; Coordinate read/write offsets between your Java process and the sidecar using atomic memory offsets.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Show Me The Code (or Example)
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Mapping POSIX Shared Memory using JEP 454 (Project Panama)&lt;/span&gt;
&lt;span class="k"&gt;try&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Arena&lt;/span&gt; &lt;span class="n"&gt;arena&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Arena&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;ofShared&lt;/span&gt;&lt;span class="o"&gt;())&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// Map an off-heap segment directly linked to a POSIX shared memory region&lt;/span&gt;
    &lt;span class="nc"&gt;MemorySegment&lt;/span&gt; &lt;span class="n"&gt;shmSegment&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;MemorySegment&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;ofAddress&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;shmAddress&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;
        &lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;reinterpret&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="no"&gt;BUFFER_SIZE&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;arena&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;cleanup&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;closeShm&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;shmFd&lt;/span&gt;&lt;span class="o"&gt;));&lt;/span&gt;

    &lt;span class="c1"&gt;// Create fast, zero-copy VarHandles for structured layout access&lt;/span&gt;
    &lt;span class="nc"&gt;VarHandle&lt;/span&gt; &lt;span class="n"&gt;sequenceWriter&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;ValueLayout&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;JAVA_LONG&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;varHandle&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
    &lt;span class="nc"&gt;VarHandle&lt;/span&gt; &lt;span class="n"&gt;payloadWriter&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;ValueLayout&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;JAVA_BYTE&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;varHandle&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;

    &lt;span class="c1"&gt;// Write directly to shared memory - zero serialization, zero heap allocation&lt;/span&gt;
    &lt;span class="n"&gt;sequenceWriter&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;set&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;shmSegment&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0L&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;1001L&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// Header at offset 0&lt;/span&gt;
    &lt;span class="n"&gt;shmSegment&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;asSlice&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;8&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;payloadSize&lt;/span&gt;&lt;span class="o"&gt;).&lt;/span&gt;&lt;span class="na"&gt;copyFrom&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;localBuffer&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// Direct copy&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Key Takeaways
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Sub-Microsecond Latency:&lt;/strong&gt; Eliminating the TCP loopback and Protobuf serialization reduces microservice-to-sidecar IPC latency by over 85%.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Zero GC Pressure:&lt;/strong&gt; Because the memory is allocated entirely off-heap and managed by scoped Panama &lt;code&gt;Arenas&lt;/code&gt;, your JVM garbage collector remains untouched.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Modern Architecture Fit:&lt;/strong&gt; In 2026, with platform I/O bottlenecks solved by Loom, optimizing CPU cycles via zero-copy IPC is the ultimate competitive advantage for high-throughput distributed systems.&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>java</category>
      <category>systemdesign</category>
      <category>concurrency</category>
      <category>computerscience</category>
    </item>
  </channel>
</rss>
