如何从Go调用Java代码而无需为每个调用调用JVM?

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?

You can make a Java management class in Java which is capable of talking to your Go program, and which you run once and will make the appropriate calls to other Java code when your Go program asks for them.

Bundle your java code in a "server" and call it with RPC like "rest/soap/thrift" and keep the server running. I don't know of any system that automate this for you though.

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.