I have a Restful Service that is calling an external application. This application is making my service hang. So when a user calls my service, it may take an hour due to this external application. The external application should only take a few seconds to execute. Otherwise, something has gone wrong. So I want the code in my service to execute for up to 30 seconds. If it passes the 30 second mark, I want to stop the service and restart it.
Here is what I am wanting:
public static void main(String[] args){
Thread thread = new Thread(){
public void run(){
System.out.println("Hello Thread");
}
};
thread.start();
//if thread is alive in 30 seconds, stop and retry
}
I am not wanting the code to execute every 30 seconds. I want to be able to stop the code execution and restart it from the beginning.
Here is the service:
@Path("/test")
@GET
@Produces(MediaType.APPLICATION_JSON )
public Response test(@QueryParam("input") String input) {
//call external application... if it hangs, it will take more than 30 seconds...
}