Chandan
Chandan

Reputation: 229

getting status from a servlet

How can we determine the status of a Job a servlet is doing. If a sservlet creates a Job Object and call its do() method which takes 2 minutes to complete and we want to show the users how much task it has completed so far on the front-end.

Upvotes: 0

Views: 54

Answers (1)

JB Nizet
JB Nizet

Reputation: 691715

You'll have to

  • put the job in a session attribute, for example, or in some other shared map where you can find it in a subsequent request
  • start a new thread which invokes the job's long-running method
  • make sure every access to the job's status is properly synchronized
  • poll the server from your HTML page (by refreshing the page or submitting AJAX requests

Each polling request will just get the job from the session (or the shared map) and get its status.

Upvotes: 1

Related Questions