'Using an instance of a Python object from a Java code

I'm trying to integrate my Python backend program into a project that's predominantly written in Java, and I was wondering if there is any way I could create, "maintain", and call a certain Python object from Java code. In particular: I have a "Head" class in my Python code that contains a bunch of useful methods I'd like to call and get their output from a Java code. A solution to this would be to write a script that instantiates and runs methods in "Head" every time it's necessary. The problem is, however, that Head takes a lot of time to instantiate (I have to load some models, etc.), and therefore it would be much more time-effective to keep it running in the background. Is this by any chance possible? Or am I just thinking of something that is not possible to do in a reasonable way? I couldn't find anything helpful on the internet. Thank you.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source