How to call java code from Go without invoking the JVM for every call?

go, java

Solution

Use cgo to call into C code that creates a JVM instance using the JNI invocation API, and call into Java code using the JNI interface. As goroutines can technically switch between native threads, you'll probably have to be very careful about testing, attaching and detaching threads to the JVM upon entry and exit from Go code and/or supplement with use of a native threads library like pthreads.

Problem

Is it possible (and if so, what is the recommended way) to call java code from Go, without the need to start the JVM for every function call? I.e, is there any equivalent to the jpype solution for python, which lets you start the JVM once, and then import java classes and call them, using the already started up JVM?

Original source