Shell script to restart a certain process if it is not responding
Look at the launchctl which is an interface to launchd daemon.

This daemon main task is to take care of all the system and users
daemons. This care includes the possibility to restart a daemon whenever
it quits or crashes.

To start with, I advise you to read:

man launchd
man launchctl


Then have a look at one of the simplest plist files used by the
system to help you writing your own one to survey JVM and restart it if needed:

/System/Library/LaunchDaemons/com.apple.autofsd.plist