> Hi!
>
> When you create a servlet with the method doGet, the servlet runs at
> every request.
No, a servlet is not created with doGet. doGet is called per request (or
more accurately, service() in the superclass is called per request,
which then calls doGet or doPost etc.). Your servlet instance persists
across all requests between server startup and server shutdown/restart.
This is why servlets must be careful about storing any state between
requests: they can't just use member variables in a normal naive way,
since those member variables are shared across all requests they service.
Anyway, for a servlet to do some background processing, perhaps try a
scheme like this:
On a request for starting work, start a new thread to do the calculation
work. Associate this thread with the session of the requesting party. On
subsequent requests, check if the thread has finished its work:
Yes -> return result to user
No -> return a message page saying 'processing, please wait...',
complete with an http-refresh header in the page, to cause the page to
automatically refresh every 1 second (or whatever interval you choose).
This way to user sees a continually refreshing page telling them the
processing is in progress. Your "please wait" page could also return
some sort of progress bar or percentage, if you could work out such a thing.
This is only one way, but a fairly common strategy methinks.
> Is it possible to create a servlet wich runs all the time and is doing
> things on the server on wich it is running (e.g. writing a logfile,
> listening to RS232 etc.) and still also react and response at requests
> from a client?
>
> - rick -