JVM Languages like Java and Scala have the ability to run concurrent code using the Thread class. Threads are notoriously complex and very error prone, so having a solid understanding of how they work is essential.

Let’s start with the Javadoc for Thread.sleep:

Causes the currently executing thread to sleep (temporarily cease execution) for the specified number of milliseconds

What are the implications of cease execution, also known as blocking, and what does it mean? Is it bad? And if so can we achieve non-blocking sleep?

What We’ll Cover in This Article

This post covers a lot of ground and hopefully you will learn a lot of cool things.

  • What happens at the OS level when sleeping?
  • The problem with sleeping
  • Project Loom and virtual threads
  • Functional programming and design
  • ZIO Scala library for concurrency

#java #programming #developer

How to Use Thread.sleep without Blocking on the JVM
8.90 GEEK