Shell script to restart a certain process if it is not responding I need an java application to run 24/7 on my mac. Unfortunately the JVM process sometimes gets stuck and thus the java application does not respond anymore.

Is there a possebility to detect if a given process has crashed (or at least is not in a proper running state) and restart this specific process subsequent?

I found 

ps aux|grep java


which lists the java process (/usr/bin/java)

Now I need to know how to watch the process state codes and how to restart this particular process in e.g. a shell script.

BTW, the process state is T which means stopped as far as I know.

EDIT:
Unfortunately four suggestions didn't work on my machine. I configured an global agent and the jar is starting properly but the process still fails after a certain period of time. Strangely enough the process in activity monitor is not marked as not responding, whereas the context menu of the dock item does (see figure)
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