1

I have a Java EE application in which the user performs a series of actions over many pages in a linear direction. On one of the first pages I have the details needed to perform a database query, of which the result is required on one of the last. I do not want to make the user to wait for this database query to execute between pages, instead I want to run it in the background whilst the user is continuing.

What is the best way of doing this?

I know use of threads in a Java EE application is discouraged.

3
  • just create a bean for this function.. Commented Oct 3, 2012 at 14:36
  • @AshokRaj thanks for that. Care to elaborate? Commented Oct 3, 2012 at 15:12
  • are you using any frameworks? or just jsp/servlets like? & is it MVC? you know JMS? Commented Oct 4, 2012 at 7:11

2 Answers 2

3

You can use the data provided in the first step to invoke an operation on asynchronous EJB or Servlet (although if you use Java EE you should go with EJB as it's better suited for this kind of job).
Take a look here: Execute subprocesses in JavaEE 6

You can save the Future<?> object that asynchronous methods returns and, on the last page, invoke its get(-) command. You can even block the user at this last stage as you probably want to show him the results instead of allowing him to proceed.

Sign up to request clarification or add additional context in comments.

Comments

1

It is discourages to manage threads in J2EE application because Application server is unaware of your custom threads and hence it can't manage resources attached to these threads. But some application servers like WebSphere, WebLogic supports the use of threads. You can use a framework like commonj to achieve this.

May you should take a look on this option as well.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.