Flipping spring.threads.virtual.enabled=true? Read This First

Virtual threads can be one of the easiest throughput wins in a blocking Spring Boot application. The switch is one line: spring: threads: virtual: enabled: true But that line changes the concurrency model of the application. It does not make database queries faster, reduce API latency, or create more database connections. It makes waiting cheaper by allowing many request tasks to share a smaller number of carrier threads. ...

2026-09-20 · 10 min · Ramesh

Java Streams

JAVA Streams Sum of Elements Given a list of integers, compute the sum of all numbers. // using sum List<Integer> arr = Arrays.asList(1, 4, 5, 6, 22, 3, 90, 89, 2, 1, 3, 4, 55, 6); int sum = arr.stream() .mapToInt(Integer::intValue) .sum(); // or int sum3 = arr.stream() .reduce((a,b) -> a + b) .get(); // or int sum2 = arr.stream() .reduce(0, (total, n) -> total + n, (total1, total2) -> total1 + total2); Average of Elements Given a list of integers, compute the average of all numbers. ...

2024-07-29 · 3 min · Ramesh

Java Concurrency Multithreading

Thread Thread Subclass Here is an example of creating a Java Thread subclass: public class MyThread extends Thread { public void run(){ System.out.println("MyThread running"); } } To create and start the above thread you can do like this: MyThread myThread = new MyThread(); myTread.start(); You can also create an anonymous subclass of Thread like this: Thread thread = new Thread(){ public void run(){ System.out.println("Thread Running"); } } thread.start(); Runnable Interface Implementation Java Class Implements Runnable public class MyRunnable implements Runnable { public void run(){ System.out.println("MyRunnable running"); } } Anonymous Implementation of Runnable Runnable myRunnable = new Runnable(){ public void run(){ System.out.println("Runnable running"); } } Java Lambda Implementation of Runnable Runnable runnable = () -> { System.out.println("Lambda Runnable running"); }; Starting a Thread With a Runnable Runnable runnable = new MyRunnable(); // or an anonymous class, or lambda... Thread thread = new Thread(runnable); thread.start(); The Java Memory Model Here is a diagram illustrating the call stack and local variables stored on the thread stacks, and objects stored on the heap: ...

2024-07-23 · 6 min · Ramesh

Asynchronous Programming in Java

Asynchronous Programming in Java Parallel vs. Concurrent vs. Asynchronous Parallel: Multiple tasks executed at the same time. For example, I can walk and talk at the same time. Concurrent: I can work on multiple tasks, but I can do only one task at a moment in time. For example, I can talk or drink water at a moment. Asynchronous: It just means non-blocking. For example, I can brew a coffee, and in the meantime, I could do something else. responsive preemptive performance For Async programming JavaScript used callback. Callbacks created a problems of its own like callback hell. Promise came to solve the problem. ...

2024-07-21 · 2 min · Ramesh

Aws Questions

AWS Use Case Questions You’re setting up a website for a small shop using AWS. How would you choose the right AWS tools to make sure the website stays fast and reliable, whether there are only a few visitors or a lot of people shopping at once during a big sale? To set up a website for a small shop using AWS, ensuring it stays fast and reliable regardless of traffic fluctuations, follow these steps: ...

2024-07-16 · 13 min · Ramesh