Which is better in concurrency? Golang or Java?

Quick tech learn
2 min readAug 20, 2023

--

In this blog, we are going to see about the concurrency concepts in Golang and compare it with Java threads.

All operations are executed synchronously in golang. In golang, async operations are achieved by go routines

What is a goroutine?

A goroutine is a lightweight thread of execution.

Goroutines are managed by the Go runtime, and they execute independently and concurrently with each other. The Go runtime scheduler determines how goroutines are scheduled and executed on the available CPUs.

The scheduler is responsible for managing the lifecycle of goroutines, including their creation, scheduling, suspension, and resumption. The scheduler uses a technique called “preemptive scheduling” to switch between goroutines. Preemption means that a running goroutine can be paused and its execution context saved so that another goroutine can be scheduled to run.

How it is efficient when compared to java threads?

  • In high level languages like Java, the bytecode generated during compilation is executed by the Java Virtual Machine (JVM) at run time. The JVM interprets or just-in-time (JIT) compiles the bytecode into machine code specific to the underlying system architecture.
  • In Go, the compiled executable directly runs on the target system without the need for a separate virtual machine. The Go runtime scheduler manages the execution of goroutines and coordinates their interactions.

--

--

Quick tech learn

Blogs are written by a fullstack developer with experience in tech stack like golang, react, SQL, mongoDB and cloud services like AWS