tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Thomas Strauß <t.stra...@srs-management.de>
Subject AW: making a singleton servlet
Date Wed, 07 Dec 2005 13:08:17 GMT
Hi,

If I understood you correctly, the problem you are trying to solve should better be solved
by a worker-thread-singleton that is started for example by your servlet's init() method.

This worker-thread can easily serialize all incoming requests in a working queue (database-
or file-based) and your servlet just pushes a job into the working queue for the thread.

If you want to wait for your job to be finished, you should either setup a cyclic check in
the browser (check back for job finished every 2 secs), which can put up quite a load on your
server, or you implement a listener to your w-thread that gets called when the job finishes.
The servlet submitting the job gives the listener as a feedback object to the thread and waits
for the call back, BUT here you can end up with loads of threads, waiting for their job to
finish and loads of impatient users clicking again, again, again.

Alternatively you can do a fire and forget to the worker thread and have a status page for
the submitter, where he can check if his entry has been saved.

Best regards 
 
Thomas Strauß

-----Ursprüngliche Nachricht-----
Von: James Black [mailto:jblack@ieee.org] 
Gesendet: Mittwoch, 7. Dezember 2005 03:33
An: Tomcat Users List
Betreff: Re: making a singleton servlet

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Caldarale, Charles R wrote:
>>From: James Black [mailto:jblack@ieee.org] 
>>Subject: re: making a singleton servlet
>>
>>I am going to make my servlet be static, with the hope that 
>>it will only have one instance running, regardless of how 
>>many clients connect to it.
> 
> 
> What do you mean by "servlet be static"?  What syntactical construct are
> you employing?
> 
> If you mean using static fields in your servlet class, then you will
> have to make use of synchronization clauses to insure concurrent
> requests are serialized.  It's my understanding that the container
> (Tomcat or whatever) is free to process as many requests in parallel as
> needed, as well as create multiple servlet instances - see the servlet
> spec.
> 
> What problem are you trying to solve?

  My plan is to try:
public static class SomeServlet extends HttpServlet {  ... }

  That way there should only be one servlet.

  I am writing a servlet to save grades to a database, but,
unfortunately, instructors will procrastinate like students do. So, I
expect that 2000+ instructors will submit their grades in the last hour
or so, before the deadline.  If each instructor had their own db
connection then the system will be useless, as students won't be able to
get connections, since all the connections will be used up.

  For the first test I want to limit them to only one connection that
will read from an input queue, and just process all the grades. Later it
may be bumped up to 20-50 connections, to speed it up.

  That is the basic problem I am trying to solve.

  I am actually using XmlHttpRequest to connect to the servlet so it
doesn't lock up the browser.

- --
Corruptisima republica plurimae leges. [The more corrupt a republic, the
more laws.]
Tacitus from Annals III, 116AD
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.0 (MingW32)

iD8DBQFDlkneJ/zyYkX46joRAlfpAJ0cdiTxXrSSdLfZ3znd63dSJesvJACgiFes
PfU+fddjZNUPTT1gq0Ft69g=
=tKjO
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org




Mime
View raw message