0

I created a WebService that runs a algorithm that takes 15 minutes running. The algorithm returns a result (JSON).

Because of the result, I am using a thread "Future Task". After I deploy the application, when I run, it returns me the correct value.

Then I run the algorithm again without restarting the Glassfish and the result is the old. How can I solve this?

Code:

@Produces(MediaType.APPLICATION_JSON)
    @Path("getValues")
    public String getValuesAlgorithm() throws Exception {        


        ExecutorService executor = Executors.newSingleThreadExecutor();        
        Future <String> future = executor.submit(new Task());

        String result = future.get();

        executor.shutdown();

        return result;
    }

    class Task implements Callable<String> {


        //algorithm is executed here...

        return result;
    }

Thanks

Kukeltje
  • 12,223
  • 4
  • 24
  • 47
user17245
  • 207
  • 1
  • 8
  • Why use executor when you are still going to wait for result and block the client request? Can you also post code for `Task` class. – tsolakp Jan 31 '18 at 16:53
  • Is there another way to use future call without executor? I'm using this because I want to execute the task and get a result. Btw, the code just run a n algorithm that return a JSON. Nothing more. Thanks, guy. Yes, this algorithm must be executed when the previous finishes. – user17245 Jan 31 '18 at 17:03

0 Answers0