🚀 Building a Multi-Threaded Server using Java Virtual Threads Recently, I built a multi-threaded TCP server in Java using Virtual Threads to understand how modern concurrency works. Traditional servers usually rely on platform threads, which are limited because each thread is tied to an OS thread. This can become expensive when handling thousands of connections. With Virtual Threads (introduced in Java 21), things become much more efficient. Here’s what I explored while building this project: 🔹 Implemented a TCP client-server communication system 🔹 Used Virtual Threads to handle multiple client requests concurrently 🔹 Compared the behavior with traditional platform threads 🔹 Learned how lightweight threads improve scalability and resource utilization 💡 Key takeaway: Virtual Threads make it possible to write simple concurrent code while supporting massive numbers of tasks with minimal overhead. This project helped me better understand: • Concurrency in Java • Thread management • Client-server communication • Real-world backend system behavior I’m currently exploring more backend concepts and building projects to strengthen my understanding of Java and distributed systems. #Java #VirtualThreads #BackendDevelopment #Java21 #ComputerScience #LearningInPublic
Java Virtual Threads for Efficient Multi-Threading
More Relevant Posts
-
The interesting timeout question is not whether a distributed system will hit deadlines. It will. The real question is what your code does next. Do you fail the whole response? Do you return partial data? Do you stop unfinished work cleanly, or let it keep running after the caller is already gone? That is what I wrote about in Part 2 of the structured concurrency series. In Java 21, `StructuredTaskScope` makes those choices much more explicit. You can model strict all-or-nothing timeouts, or return partial results when some sections are optional. The part I like is that cancellation and cleanup stop being scattered across the code. This post covers: - all-or-nothing timeout handling - partial results with explicit missing sections - why `joinUntil(...)` is only part of the design - why `scope.shutdown()` matters when returning early - what test cases are worth adding for timeout-sensitive endpoints Article: https://lnkd.in/gWCm5UzB #Java #StructuredConcurrency #ProjectLoom #Java21 #DistributedSystems #BackendEngineering
To view or add a comment, sign in
-
Java 20 Launches Virtual Threads and Pattern Matching to Simplify Code 📌 Java 20 drops virtual threads and pattern matching - two game-changers that slash code bloat and boost concurrency without complex thread pools. Senior devs can now write cleaner, more expressive logic with less boilerplate, making it easier to scale apps to millions of tasks - all while reducing memory use. 🔗 Read more: https://lnkd.in/dSuYxdVB #Virtualthreads #Patternmatching #Jdk20
To view or add a comment, sign in
-
Java 21 just made most reactive frameworks obsolete. 🔥 I said it. For years we tortured ourselves with WebFlux, reactive streams, and callback hell — all to avoid blocking threads and handle high concurrency. Then Java 21 dropped Virtual Threads and said: "Hold my coffee." ☕ Virtual Threads in a nutshell: - Managed by the JVM, not the OS - You can spin up MILLIONS of them - Write plain blocking code — JVM handles the rest - Zero reactive syntax. Zero mental overhead. Old world: return Mono.fromCallable(() -> userRepo.findById(id)) .subscribeOn(Schedulers.boundedElastic()) .flatMap(user -> Mono.just(mapToDto(user))); New world: User user = userRepo.findById(id); // Just... this. ✅ return mapToDto(user); Same concurrency. Same performance. 10x simpler code. Does this mean reactive is dead? Not entirely — event-driven systems still have their place. But for most REST APIs and microservices? Virtual Threads win. Every time. Change my mind. 👇 #Java #Java21 #VirtualThreads #SpringBoot #BackendDevelopment #SoftwareEngineering #Programming
To view or add a comment, sign in
-
🚀 What’s new in Java 26? This is not an LTS release, but it gives a very clear picture of where Java is heading. The main highlights are HTTP/3 in HttpClient, Ahead-of-Time Object Caching for any GC, a stricter direction around final, and the final removal of the Applet API. ⚙️ What also stands out is how many practical improvements landed around GC. According to the HotSpot GC overview, around 380 issues were closed in the GC subcomponent. GC CPU time accounting was improved, a new JFR event for string deduplication was added, and G1 received changes that reduce synchronization between the application and GC to improve throughput. 🧩 Java is also moving forward with Structured Concurrency, Lazy Constants, Vector API, and primitive patterns. #Java #JDK26 #OpenJDK #Backend #SoftwareEngineering
To view or add a comment, sign in
-
-
"Architecting Knowledge" - Java Wisdom Series Post #17: Virtual Threads - Rethinking Concurrency 👇 Million threads. One JVM. Welcome to Project Loom. Why This Matters: Platform threads map 1:1 to OS threads - each consumes ~1MB stack memory. You can create maybe 4000-10000 before your JVM dies. Virtual threads are JVM-managed and stack memory is allocated dynamically on heap - you can create millions. When a virtual thread blocks on I/O, the JVM unmounts it from its carrier thread (platform thread), letting that carrier run other virtual threads. This makes blocking I/O efficient again - no more callback hell. BUT beware thread pinning: synchronized blocks prevent unmounting in Java 21-23 (fixed in 24). Use ReentrantLock for long blocking operations. Key Takeaway: Virtual threads aren't faster - they're cheaper and more scalable. Perfect for I/O-bound workloads (web servers, microservices, API calls). Don't pool them, don't cache in ThreadLocal aggressively. Write simple blocking code, let Loom handle concurrency. #Java #JavaWisdom #VirtualThreads #ProjectLoom #Concurrency #Java21 Are you still using thread pools for I/O-bound tasks? Time to go virtual! All code examples on GitHub - bookmark for quick reference: https://lnkd.in/dJUx3Rd3
To view or add a comment, sign in
-
-
New versions of Java are released regularly for several important reasons. The main goal is to keep the language modern, secure, and competitive with other programming languages. 1️⃣ Improve Performance ⚡ Each version introduces optimizations in the JVM, compiler, and garbage collectors to make applications faster and more efficient. Example: Java 17 improved the G1 Garbage Collector Java 21 introduced Virtual Threads for high-performance concurrency. 2️⃣ Add Modern Language Features 🧠 Programming evolves, so Java adds features that make code shorter, clearer, and easier to maintain. Examples: Lambda Expressions in Java 8 Records in Java 16 Sealed Classes in Java 17 Pattern Matching improvements in recent versions 3️⃣ Improve Developer Productivity 👨💻 New versions reduce boilerplate code and simplify development. Example: var in Java 10 allows type inference Text Blocks simplify multiline strings JShell allows interactive coding. 4️⃣ Security Updates 🔒 Older versions may have vulnerabilities. New releases include security patches and safer APIs. 5️⃣ Cloud & Modern Architecture ☁️ Java evolves to support: Microservices Containers (Docker/Kubernetes) Reactive systems High concurrency 6️⃣ Faster Release Cycle Since 2017, Java releases a new version every 6 months. But only some versions are Long-Term Support (LTS): Java 8 Java 11 Java 17 Java 21 Companies usually stay on LTS versions for stability. #Java #JavaDeveloper #SoftwareDevelopment #BackendDevelopment #Programming #Java17 #Java21 #JVM
To view or add a comment, sign in
-
-
Most teams today are running on Java 17 (LTS) — and for good reason. It’s stable, well-supported, and widely adopted across enterprise systems. But with Java 26 (March 2026) now available, it’s clear where the platform is heading. This isn’t about flashy new syntax. The shift is more subtle — and more important. Java 17 gave us better language design. Java 26 is focused on better system performance. ⸻ What’s new or evolving in Java 26? • Improved Garbage Collection (G1) for better latency and throughput • Early support for HTTP/3, enabling faster and more efficient network communication • Enhancements around AOT (Ahead-of-Time) optimizations, helping reduce startup time • Continued evolution of Vector API and concurrency features, supporting high-performance workloads • Stronger enforcement of code integrity and security constraints ⸻ What does this mean in practice? If you are building large-scale backend systems or microservices: • Startup time and memory efficiency are becoming more critical • Network performance (especially in distributed systems) is gaining importance • Applications are expected to handle more parallel workloads efficiently Java 26 is clearly moving in that direction. ⸻ A realistic perspective Most organizations will continue using Java 17 for production — because it’s LTS and stable. But engineers who start understanding newer Java versions early will be better prepared for: • Performance-focused system design • Modern runtime optimizations • AI and compute-heavy workloads ⸻ My takeaway The conversation is shifting from: “How do we write better code?” to “How does our system perform at scale?” ⸻ Curious to know — Are you still primarily working on Java 17, or have you started exploring newer versions? https://lnkd.in/gv2H-6Rh #java26 #java #softwareengineer
To view or add a comment, sign in
-
Day 10 of my Java Streams practice focused on solving a classic problem—finding all anagrams of a given word. The approach is based on a simple observation: two words are anagrams if they contain the same characters in the same frequency. By converting each word into a stream of characters, sorting them, and comparing the result with the sorted version of the target word, we can identify matching anagrams efficiently. This exercise helped strengthen my understanding of working with streams, transforming data, and applying comparison logic in a functional style. It also reinforced how breaking a problem into smaller transformations can lead to clean and readable solutions. #Java #JavaStreams #DSA #CodingJourney #BackendDevelopment #100DaysOfCode
To view or add a comment, sign in
-
-
Java 26 is officially here! (Released March 17, 2026) 🤩 Even though it's not an LTS release, Java 26 brings meaningful improvements focused on performance, modern networking, concurrency, and preparing for the future — including stronger foundations for AI workloads. 🔥 Key Highlights in Java 26: Ahead-of-Time Object Caching – Faster startup and warmup with any garbage collector (big win from Project Leyden) HTTP/3 Support in the HTTP Client – Native QUIC protocol for faster, more reliable web requests Structured Concurrency – Making concurrent code safer and easier to reason about Vector API – High-performance vector computations (great for AI/ML and data processing) Lazy Constants – Further startup time optimizations Prepare to Make Final Mean Final – Warnings for unsafe deep reflection on final fields Improved – G1 GC throughput by reducing synchronization Cleanup – Applet API removed Java continues its steady evolution — faster, cleaner, and more efficient with every release. Are you planning to try Java 26 in your projects soon? Or sticking with Java 21/25 LTS for now? Drop your thoughts below #Java26 #Java #JDK26 #SoftwareDevelopment #BackendDevelopment #TechNews #Programming
To view or add a comment, sign in
-
-
Key Features in the Last 4 LTS Releases of Java This infographic covers major features across Java 8, 11, 17, 21, and 22: Java 8 — Lambda, Stream API, Date/Time API, Optional class Java 11 — HTTP Client, var in lambdas, String improvements Java 17 — Sealed classes, Records, Pattern Matching, Enhanced Switch Java 21 — Virtual Threads, Sequenced Collections, Pattern Matching for switch Java 22 — Unnamed Variables, Streams for Primitives, Statements before super() A quick reference for Java developers to track language evolution across LTS versions. #Java #JavaDeveloper #Java8 #Java11 #Java17 #Java21 #Java22 #LTS #Programming #SoftwareDevelopment #BackendDevelopment #SpringBoot #CodeNewbie #100DaysOfCode #TechEducation #LearnJava #JavaProgramming #OpenJDK #VirtualThreads #LambdaExpressions #LinkedInTech
To view or add a comment, sign in
-
Explore content categories
- Career
- Productivity
- Finance
- Soft Skills & Emotional Intelligence
- Project Management
- Education
- Technology
- Leadership
- Ecommerce
- User Experience
- Recruitment & HR
- Customer Experience
- Real Estate
- Marketing
- Sales
- Retail & Merchandising
- Science
- Supply Chain Management
- Future Of Work
- Consulting
- Writing
- Economics
- Artificial Intelligence
- Employee Experience
- Workplace Trends
- Fundraising
- Networking
- Corporate Social Responsibility
- Negotiation
- Communication
- Engineering
- Hospitality & Tourism
- Business Strategy
- Change Management
- Organizational Culture
- Design
- Innovation
- Event Planning
- Training & Development
Great learning.