It pins goroutine until it is explicitly released ensuring that multiple native calls will remain on the same platform thread and nothing else is going to use it.
This is critical for namespace manipulation on Linux.
Java only pins for duration of native call and synchronized blocks.
It looks like Java does not offer equivalent API?
For now could be achieved with synchronized but if synchronized will be changed in the future to not pin it would break.
For example, https://pkg.go.dev/runtime#LockOSThread