I suggest that you use an http-based callback mechanism.
Expose an http post endpoint in the Python application that accepts a call indicating that the Java service has completed its work.
Java calls Python back to indicate completion and pass back results. Usually the initial call that Python makes to Java includes info to identify the call and this identifier is passed back in the callback allowing Python to tie everything together.
The advantage of this approach is that, because it uses http for all integration, it is not tied to the implementation technology on either end. It allows scalability, location independence and a microservice type architecture.
Implementation notes
The payload in initial call from Python to Java must include a url where the Python http server is running, for Java to call Python back on when it’s completed the work. For example the following request body (if we are POSTing to Java):
{
“callbackUrl”: “http://10.0.0.2:8000/callback?job_id=123”,
“foo”: “bar”
}
When complete, Java (java.net.http.HttpClient or Spring RestTemplate) POSTs the results to the callbackUrl provided and identifies the job (if required.)
POST http://10.0.0.2:8000/callback?job_id=123
{
“resultFoo”: true,
“resultBar”: 10
}
In Python create a function to accept the callback, eg with flask
@api.route('/callback', methods=['POST'])
def post_callback():
jobId = request.args.get('job_id')
#link back to original call with JobId
request_data = request.get_json()
# used the posted body data, eg request_data.resultFoo
return json.dumps({"success": True}), 201)