Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / April 2006

Tip: Looking for answers? Try searching our database.

Servlet

Thread view: 
rickbeardk@gmail.com - 07 Apr 2006 18:06 GMT
Hi!

When you create a servlet with the method doGet, the servlet runs at
every request.

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 -
Alex Hunsley - 08 Apr 2006 00:32 GMT
> 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 -


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.