Skip to content

Sample code using Project Loom, Virtual Threads, Executors and ExecutorService

Notifications You must be signed in to change notification settings

brunolellis/java-loom

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Java Loom and ExecutorService

Trying to handle how many virtual threads may run in parallel. Think about throttle and how to avoid overloading external systems.

1. SampleFixedThreadPool

that is the way we are used to: create a fixed thread pool (or a cached thread pool) and submit jobs

2. SampleUnboundedVirtualThreads

it is that easy: just create an ExecutorService with Executors.newVirtualThreadPerTaskExecutor() and submit your jobs.

but you may process thousands or millions of processes concurrently and end up overloading an external system.

3. SampleFixedVirtualThreads

that's the same implementation as 1 but using Project's Loom Virtual Threads implementation with fixed number of virtual threads.

4. SampleCustomVirtualThreads

tried something different customizing ThreadPoolExecutor but at the end of the day, it is the same as the 3.

5. SampleVirtualThreadsWithSemaphore

handles the maximum number of concurrent tasks executed in parallel by using a Semaphore to limit virtual threads.

About

Sample code using Project Loom, Virtual Threads, Executors and ExecutorService

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages