CodeGym
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
  • Deadlock: causes, examples, and fixes

    JAVA 25 SELF
    Level 53, Lesson 0
    In this lecture, we examine what a thread deadlock is in Java, why it happens, and which four conditions are required for it. With a practical example using synchronized, we show how to reproduce the problem, then study prevention strategies: a single resource acquisition order, using ReentrantLock.tryLock with a timeout, shortening critical sections, and avoiding unnecessary nested locks. We will show diagnosis via Thread dump and jstack, how to recognise the BLOCKED/ WAITING states, and finish with a checklist and common mistakes.
    Available
  • Livelock and Starvation: definition and examples

    JAVA 25 SELF
    Level 53, Lesson 1
    We examine concurrency anomalies Livelock and Starvation: how they differ from Deadlock, and how they look in code and logs. Java examples are shown: “polite workers” (livelock) and starvation due to priorities and unfair locks. We learn to detect the problem (logging, Thread dump, VisualVM, Java Mission Control) and to prevent it: random delays before retry ( Thread.sleep), non‑blocking algorithms, fair locks via ReentrantLock with the fairness flag ( new ReentrantLock(true)), careful critical sections, and avoiding abuse of setPriority() and synchronized.
    Available
  • Thread-safe collections: ConcurrentHashMap and others

    JAVA 25 SELF
    Level 53, Lesson 2
    In this lecture, we’ll look at why regular collections ( ArrayList, HashMap) are dangerous in a multithreaded environment, and which thread-safe alternatives the java.util.concurrent package provides: ConcurrentHashMap, CopyOnWriteArrayList, ConcurrentLinkedQueue, skip-list–based structures, and BlockingQueue. We’ll discuss atomic operations like merge, putIfAbsent, computeIfAbsent, compare them with Collections.synchronizedMap, and cover practical examples and common mistakes (weakly consistent iterators, non-atomic sequences of operations, etc.).
    Available
  • AtomicInteger, AtomicReference: atomic operations

    JAVA 25 SELF
    Level 53, Lesson 3
    Why the increment i ++ doesn’t work in multithreading, what atomic operations are, and how the java.util.concurrent.atomic package provides them. We break down AtomicInteger and AtomicReference, the methods incrementAndGet(), compareAndSet(...), the internal CAS (Compare-And-Swap) mechanism, as well as when it’s better to choose synchronized and when — LongAdder. Finally — typical pitfalls: compound operations, ABA, and thread safety of nested objects.
    Available
  • Diagnosing and debugging multithreaded programs

    JAVA 25 SELF
    Level 53, Lesson 4
    How to capture and read a Thread Dump using jstack, VisualVM, and an IDE; recognize thread states ( RUNNABLE, BLOCKED, WAITING) and find deadlocks. We will cover thread monitoring in Java Mission Control and Java Flight Recorder, logging practices (thread names, entering/exiting synchronized), minimizing locks, concurrency testing with CountDownLatch, and a real deadlock case study. Finally — common mistakes and how to avoid them.
    Available
  • Introduction to Parallelism

    JAVA 25 SELF
    Level 54, Lesson 0
    In this lecture we unpack the difference between multithreading and parallelism: where responsiveness matters, and where real speed-up across multiple cores matters. We will discuss creating threads via Thread, implementing Runnable, and high-level pools with ExecutorService; look at a simple array-summing example; examine when parallelism helps and when it hurts; and cover typical issues: data races, synchronization with synchronized, deadlocks, and load balancing. We finish with a comparison table and scenario visualizations.
    Available
  • ExecutorService, Callable, Future: running tasks

    JAVA 25 SELF
    Level 54, Lesson 1
    Serious multithreading practice: pass tasks to ExecutorService instead of manually creating a Thread, and manage the pool, the queue, and the lifecycle ( shutdown(), shutdownNow()). We’ll go over the difference between Runnable and Callable<T>, get results via Future and its methods ( get(), isDone(), cancel(...), isCancelled()). We’ll show running multiple tasks, invokeAll/ invokeAny, handling ExecutionException, and common mistakes.
    Available
  • Parallel streams: syntax and usage

    JAVA 25 SELF
    Level 54, Lesson 2
    Let’s figure out how to switch a regular data stream to parallel processing in one line—via parallelStream() or .parallel(), what happens under the hood in ForkJoinPool.commonPool(), when parallelism actually speeds up computations (large collections, “heavy” operations), and where it can slow things down. We’ll show examples of filtering, aggregation, sorting, performance measurement, and break down typical mistakes: side effects in forEach, preserving order, choosing collections, and tuning the degree of parallelism.
    Available
  • ForkJoinPool and RecursiveTask: recursive tasks

    JAVA 25 SELF
    Level 54, Lesson 3
    A practical guide to parallel computation in Java: how the ForkJoinPool task pool and recursive tasks RecursiveTask<T>/ RecursiveAction work, why the work-stealing algorithm is useful, how to split tasks via fork() and merge results with join() inside compute(). We will cover running via pool.invoke(), an example of summing an array and finding a maximum, the role of ForkJoinPool in parallelStream(), as well as typical mistakes and how to avoid them.
    Available
  • Best practices for parallel programming

    JAVA 25 SELF
    Level 54, Lesson 4
    A practical guide to parallel programming in Java: when to use ExecutorService, where parallelStream helps, and what tasks need ForkJoinPool. We will discuss thread safety with ConcurrentHashMap/ CopyOnWriteArrayList and atomic classes ( AtomicInteger), performance measurements with System.nanoTime() and JMH, error handling from Future.get() and ForkJoinTask, proper reactions to InterruptedException, as well as logging techniques ( Thread.currentThread().getName()) and testing ( Awaitility). At the end—an instrument selection table and common mistakes.
    Available
  • Introduction to CompletableFuture

    JAVA 25 SELF
    Level 55, Lesson 0
    In this lecture we will examine why synchronous code leads to blocking, what limitations Future had (such as the blocking get()), and how the CompletableFuture class from the java.util.concurrent package changes the way we work with asynchrony. We will practice launching background tasks via supplyAsync, subscribing to results with thenAccept/ thenApply, discuss the role of the ForkJoinPool, and cover common pitfalls: using get()/ join() on the main thread, missing error handling via exceptionally/ handle, and more.
    Available
  • Asynchronous tasks: thenApply, thenAccept, thenRun

    JAVA 25 SELF
    Level 55, Lesson 1
    Breaking down launching and composing asynchronous computations with CompletableFuture: how to start tasks via supplyAsync and runAsync, how the handlers thenApply, thenAccept, thenRun differ, and when to choose their async versions thenApplyAsync/ thenAcceptAsync/ thenRunAsync. We’ll talk about execution threads ( ForkJoinPool or your Executor), result types ( CompletableFuture<T>, CompletableFuture<Void>) and common mistakes: blocking get()/ join(), unhandled errors without exceptionally/ handle/ whenComplete, and also trying to use the result inside thenRun.
    Available
  • 1
  • ...
  • 23
  • 24
  • 25
  • 26
  • 27
  • ...
  • 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