This is a created article in which the information may have evolved or changed.
Golang Concurrent Two (principle)
Each operating system has a fixed-size stack memory, and the user holds local variables for the function. But this fixed size is obviously less flexible than the empty energy. Instead, Goroutine applies a very small stack at the beginning of the lifecycle, similar to the operating system thread, to hold local variables during function calls. The essential difference is that its size is not fixed and can be enlarged and scaled down as needed.
The operating system thread is dispatched by the kernel, every few seconds, the CPU calls the kernel function, pauses the running thread, saves the execution information to memory, finds the next thread to execute, then resumes execution information from memory, and finally executes the thread. Context switches because the state of a thread is saved to memory and the state of another thread is restored from memory. This is a relatively slow process.
The Go runtime contains a scheduler that can call M goruotine to n operating system threads, unlike operating system thread scheduling, where the go Scheduler is not determined by the clock, but is triggered by a specific go language structure.
Each thread in Java has a unique identity, but Goroutine does not provide an identity that the programmer can access.