views:

11

answers:

1

Hi, I am using Java in order to create web application. The application has to load a form which is sent it's data to a jsp that call a long business logic. I need that the jsp will return a message like "thank you for using my service, an email will sent to you when the proccess is done."

The problem is that if I will write something like:

<html>
<head></head>
<body>
...
<span>thank you for using my service, an email will sent to you when the proccess is done</span>
...
<% businessClass.doLongOperation(); %>
...
...
</Body>
</html>

the jsp will run for long time and the user will have to wait for the operation to end. Moreover, i f the user will close the browser, I am not sure if the jsp will continue its job.

How can I isolate the long operation from the jsp so the user will not have to wait all the execution time and also how can I make the long operation execution not to be depend on the browser?

Naor

+1  A: 

Your JSP is probably backed on the server side by a servlet or Struts Action or Spring MVC Controller.

In that object, peform an asynchronous execution:

executor.execute(new Runnable() {

    public void run() { businessClass.doLongOperation(); }
});

Where the executor is an instance of java.util.concurrent.Executor.

Robert Munteanu