Faz
Faz

Reputation: 554

Invoking Java standalone program in servlet or any other J2EE technologies

Here's what i need.. I have a UI where a user has the capability to upload a file and extract a report based on the inputted(uploaded) data. Since there is a huge data to be extracted, once the user uploads the data i would like to come out of the servlet control so that user doesn't have to wait in the same page and that the control to be passed on to a java stand alone program there by making it possible for the user to work on something else. So once the control goes on to the java standalone,it would invoke back-end sps and build an extract out of it and place it in a file path on the server.

The user how-over has a capability from UI to check if the extract is ready for them to download.

So the question here is, what is the best practice or possibility in achieving the same? Please let me know your valuable comments.

Thanks!

Upvotes: 1

Views: 420

Answers (3)

Anders R. Bystrup
Anders R. Bystrup

Reputation: 16060

If you're running in a Java EE environment I would suggest having the servlet dispatch the task to a JMS queue and use a message driven bean to do the (async) processing.

As others suggest, it would be fairly trivial to have the upload servlet redirect the user to some ajax-enabled page that polls the backend for job completion.

If you're not in an EE environment, you could create a standalone (thread pooled) application to consume from the queue and provide signalling eg. through the database (I assume the result goes in a DB anyway). The Spring framework provides very capable and extensive facilities for binding it all together.

But really, there are several free/open source EE containers available, from light weight up to enterprise, so there's no need to build the necessary stuff yourself.

Cheers,

Upvotes: 2

Khain
Khain

Reputation: 955

If you can't use message driven beans, you could have your servlet upload the data to a location on the filesystem and record a row in a DB table to say there's a job to be processed.

Then you have your standalone program polling for jobs, processing the data and updating the DB row on completion (including reasons for failure etc.).

Finally, you can poll the status of the job from the UI using an ajax request.

Allows the user to build up a queue of data jobs to be processed while they're doing something else.

Upvotes: 0

Makky
Makky

Reputation: 17471

Its very easy.

  • Have one thread in your servlet class.

  • Run the thread (Thread will extract the data etc).

  • After running the thread redirect user to a page where you have auto-refresh or something to show how much extraction is done.(You mentioned that you have a way to find it)

Upvotes: 0

Related Questions