Killing the process if running for long time in script

I am running a script which will read the data from fail line by line and call the Java program by providing the arguments from the each line.

The Java code is working fast for few records and for some records its getting hanged not providing response for morethan one hour.

Currently am killing it manually, so that the script will proceed with next line.

How can we automate it , we don't get response the process id should be killed.
and the script should proceed with the other data.

while read line
do
 <java program> $line 

st=`grep -c "{\"status\":false}" <JAR_LOG>
if [ $st -gt 0 ]; then
echo "${USRNAME}" >> $FAILURE_IDS_FILE
else
echo "${USRNAME}" >> $SUCCESS_IDS_FILE
fi
done

Do you have the timeout program?

timeout 60 java ... 

I'd prefer to fix the code that can't cope with some, say, ill-structured records...
How do the records that cause the code to "hang" differ from the others that make it work well?

I mean we are not getting any response from the Java code

I mean you check the code and the input data.