CodeGym
AI Academy
Promotion
CodeGym University
Learning
Courses
Tasks
Surveys & Quizzes
Games
Help
Schedule
Community
Users
Forum
Chat
Articles
Success stories
Activity
Reviews
Subscriptions
Light theme

Lessons

  • Reviews
  • About us
Start
Start learning
Start learning now
  • My Progress
  • Courses
  • University
  • Quest Map
  • Lessons
  • Combining CompletableFuture: thenCombine, allOf, anyOf

    JAVA 25 SELF
    Level 55, Lesson 2
    How to parallelise tasks and merge results with CompletableFuture: combining two results via thenCombine/ thenCombineAsync, waiting for a set of tasks with allOf, reacting to the fastest response with anyOf. We’ll examine signatures, practical examples with supplyAsync, non-blocking handling ( thenAccept, thenRun), as well as error nuances and handling ( exceptionally, handle, whenComplete). At the end — a compact comparison table of the methods.
    Available
  • Error handling in asynchronous code: exceptionally, handle

    JAVA 25 SELF
    Level 55, Lesson 3
    How to safely catch and handle exceptions in CompletableFuture chains: we examine the roles of exceptionally (fallback value on error), handle (universal success/error handler), and whenComplete (side effects without changing the result). We will discuss why directly calling get()/ join() wraps causes in ExecutionException/ CompletionException, how to combine stages ( thenApply, thenAccept), and which common mistakes to avoid.
    Available
  • thenCompose + custom Executor + timeouts

    JAVA 25 SELF
    Level 55, Lesson 4
    How to properly “glue” asynchronous steps in CompletableFuture using thenCompose and when thenApply is sufficient; how and why to plug in your own thread pool via ExecutorService (instead of ForkJoinPool.commonPool()); how to protect chains from “waiting forever” using orTimeout and completeOnTimeout. At the end — a practical example with a custom Executor, thenCompose, and a timeout, plus typical mistakes and their fixes.
    Available
  • Asynchronous IO: AsynchronousFileChannel (NIO2)

    JAVA 25 SELF
    Level 56, Lesson 0
    In this lecture we cover asynchronous input/output (AIO) in Java NIO.2: how it differs from synchronous IO, how to work with AsynchronousFileChannel, launch read/write operations via Future and CompletionHandler, and how the choice of the ExecutorService thread pool affects behavior. In practice, we'll look at opening a channel via open, the read/write methods, the interaction flow, and common pitfalls.
    Available
  • Future, CompletionHandler: handling completion of operations

    JAVA 25 SELF
    Level 56, Lesson 1
    How to handle completion of NIO2 asynchronous operations in Java: “promises” via Future and callbacks via CompletionHandler. We’ll examine the read/ write signatures on AsynchronousFileChannel, blocking result retrieval via get() and polling isDone(), as well as non-blocking handling in completed()/ failed(). We’ll show practical read/write examples and a brief comparison of the approaches.
    Available
  • Asynchronous processing of text files

    JAVA 25 SELF
    Level 56, Lesson 2
    Practising asynchronous I/O in Java: read large text files in blocks into ByteBuffer via AsynchronousFileChannel, correctly convert bytes to characters using CharsetDecoder, write data back asynchronously (via Future or CompletionHandler). We unpack the problem of “split” multibyte characters (for example, "UTF-8"), on-the-fly line counting, charset choice, and common mistakes when working with buffers and channels.
    Available
  • Error handling in async I/O, canceling operations

    JAVA 25 SELF
    Level 56, Lesson 3
    How to properly catch and handle errors in Java asynchronous I/O: CompletionHandler callbacks with completed/ failed methods, logging, and notifications. We cover canceling operations via Future and cancel( boolean), implications for get() and CancellationException, plus practical tips: try-with-resources, synchronization with CountDownLatch/ CompletableFuture, and resource cleanup.
    Available
  • Debugging errors in asynchronous file I/O

    JAVA 25 SELF
    Level 56, Lesson 4
    A practical walkthrough of the pitfalls when working with asynchronous file I/O in Java NIO: correct buffer management for ByteBuffer (properties position/ limit, calls to flip(), clear(), compact()), races in parallel operations with AsynchronousFileChannel, closing resources ( channel.close(), try-with-resources), error handling in CompletionHandler (method failed(...)), managing operation lifecycle via Future<Integer> and synchronizing with CountDownLatch, correct handling of character encodings via CharsetDecoder, and choosing an appropriate thread pool with ExecutorService.
    Available
  • Threads vs virtual threads: differences and advantages

    JAVA 25 SELF
    Level 57, Lesson 0
    We’ll examine how platform threads differ from virtual ones: how the “ Platform Thread → OS” model works and why it’s heavy, what changes with virtual threads ( Virtual Thread) on top of carrier threads, and how this delivers scalability without reactive “spaghetti.” We’ll look at practical usage with Thread.ofVirtual(), compare behaviour for I/O‑bound and CPU‑bound tasks, touch on compatibility (blocking calls like InputStream.read, Socket.accept) and common mistakes (legacy synchronisation, expecting “magical speedups”).
    Available
  • Creating virtual threads: Thread.ofVirtual().start()

    JAVA 25 SELF
    Level 57, Lesson 1
    Hands-on with Java 21 virtual threads: how they differ from platform threads, how to start them via Thread.startVirtualThread(...) and Thread.ofVirtual().start(...), when new Thread(...) or Thread.ofPlatform() is still appropriate, and how to execute tasks at scale using Executors.newVirtualThreadPerTaskExecutor(). We’ll cover waiting for completion via join(), error handling with Future and ExecutionException, and common pitfalls when using virtual threads.
    Available
  • Scalability and Performance of Virtual Threads

    JAVA 25 SELF
    Level 57, Lesson 2
    A practical comparison of platform threads Thread and virtual threads in Java 21: how the JVM, thanks to “ carriers” (carrier threads), executes hundreds of thousands of tasks with minimal memory; where virtual threads shine (I/O-bound) and where they don’t (CPU-bound). We’ll examine limitations ( synchronized, native locks), best practices ( Executors.newVirtualThreadPerTaskExecutor()), monitoring via JVisualVM and Java Flight Recorder, as well as common mistakes when migrating to Virtual Threads.
    Available
  • Using Executor with virtual threads

    JAVA 25 SELF
    Level 57, Lesson 3
    We will break down how to run one task in a single virtual thread using Executors.newVirtualThreadPerTaskExecutor() (Java 21), how this differs from classic pools ( newFixedThreadPool, newCachedThreadPool), how to shut down properly via shutdown() and awaitTermination(...), how to get task results via Future, and where virtual threads deliver the biggest wins (mass I/O, web servers, load testing). At the end — common mistakes and gotchas.
    Available
  • 1
  • ...
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
Learn
  • Registration
  • Java Course
  • Help with Tasks
  • Pricing
  • Java Syntax
Community
  • Users
  • Articles
  • Forum
  • Chat
  • Success Stories
  • Activity
  • Affiliate Program
Company
  • About us
  • Contacts
  • Reviews
  • Press Room
  • CodeGym for EDU
  • FAQ
  • Support
CodeGym CodeGym is an online course for learning Java programming from scratch. This course is a perfect way to master Java for beginners. It contains 1200+ tasks with instant verification and an essential scope of Java fundamentals theory. To help you succeed in education, we’ve implemented a set of motivational features: quizzes, coding projects, content about efficient learning, and a Java developer’s career.
Follow us
Interface language
English
Deutsch Español हिन्दी Français Português Polski বাংলা 简体中文 मराठी தமிழ் Italiano Bahasa Indonesia 繁體中文 Nederlands 日本語 한국어 Bulgarian Danish Hungarian Basa Jawa Malay Norwegian Romanian Swedish Telugu Thai Українська Filipino Turkish Azərbaycan Русский Vietnamese
Programmers Are Made, Not Born © 2026 CodeGym
MastercardVisa
Programmers Are Made, Not Born © 2026 CodeGym