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
  • Why file I/O blocks and how it affects choosing Dispatchers

    Kotlin SELF
    Level 56, Lesson 0
    We break down the difference between suspension and thread blocking, why JVM file operations are most often blocking, and how this directly affects the choice of coroutine context: where to use Dispatchers.Default and where to use Dispatchers.IO. With examples using withContext, async, and blocking Thread.sleep, we show how “accidental I/O on Default” can slow down CPU tasks, and how the discipline “I/O separately, CPU separately” simplifies architecture.
    Available
  • withContext(Dispatchers.IO) + use {}: proper boundaries for I/O functions

    Kotlin SELF
    Level 56, Lesson 1
    Let’s break down how, in Kotlin coroutines, to correctly separate blocking file I/O from CPU logic: where to put withContext( Dispatchers.IO), how to exit safely via return@withContext, why you need use { ... } to close resources, and why a “wide” IO context turns into a trash bin for responsibility. At the end: hands-on practice for the File Organizer utilities and a list of common mistakes.
    Available
  • Parallel file processing — async + awaitAll()

    Kotlin SELF
    Level 56, Lesson 2
    We break down a practical pattern for concurrent processing of many files with Kotlin coroutines: how launch and async differ, how to collect results in a batch via awaitAll(), why it is dangerous to start “a thousand tasks at once”, how to limit concurrency with Dispatchers.IO.limitedParallelism(n), where the boundary between I/O and CPU lies, and how to integrate this into structured concurrency via coroutineScope.
    Available
  • Cancellation in long-running file operations: chunk loop, isActive, CancellationException

    Kotlin SELF
    Level 56, Lesson 3
    We break down cooperative coroutine cancellation in long-running file operations: why blocking I/O “doesn’t hear” cancel(), why you need a chunk loop (read/write in chunks), where to put cancellation points via isActive and ensureActive(), how to work correctly with CancellationException (and not “silence” it in catch), and how to cancel a task from the outside via cancelAndJoin().
    Available
  • Partial results and cleanup: temp files, renaming, cleanup

    Kotlin SELF
    Level 56, Lesson 4
    We will go through a practical strategy for reliable “result publication” when working with files: write to a draft ( .tmp/ .part), then (as atomically as possible) “publish” via renameTo(), and in any case perform best-effort cleanup in finally. Using Kotlin and coroutines examples: try / finally, withContext( Dispatchers. IO), helper deleteQuietly, safe report writing, and a wrapper for copying.
    Available
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