Go Goroutines vs Java 21 Virtual Threads: How They Compare on Memory and Speed
Go's goroutines and Java 21's virtual threads both enable launching hundreds of thousands of concurrent tasks without exhausting CPU or memory, but they achieve this through fundamentally different designs. Go uses an M:N scheduler (the G-M-P model) where goroutines start with a 2KB dynamic stack, allowing 50,000 goroutines to run in roughly 160MB of RAM. Java 21 virtual threads, introduced via Project Loom, store stack frames as heap objects and mount them onto carrier threads only when executing, consuming around 195MB for the same workload — while older Java 17 platform threads crashed at just 4,200 threads. A key behavioral difference is preemption: Go forcibly interrupts goroutines running longer than 10ms via OS signals, whereas Java virtual threads are cooperative and can be monopolized by tight CPU loops. In throughput benchmarks, both runtimes performed nearly identically, with Go at roughly 48,200 requests per second and Java 21 close behind at 46,800.
This is an AI-generated summary. ShortSingh links to the original source for the complete article.


Discussion (0)
Log in to join the discussion and vote.
Log in