tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From (Steven J. Owens)
Subject Re: Servlet multithreading design question
Date Mon, 09 Sep 2002 23:58:22 GMT
On Mon, Sep 09, 2002 at 04:56:02PM +0930, Mathew Pole wrote:
> If I create classes similar to the following, then I suspect that I
> will run into multithreading issues, because OneServlet and
> TwoServlet will run in the same JVM? Is this correct?

     I think you're a bit confused, on three counts:

1) I suspect this question is probably more appropriate for a forum
like, than tomcat-users.

2) I think you mean to have "value" be a class variable, in which case
your code wouldn't be thread safe, _if_ both servlets are deployed
inside the same web application.

3) It's not just the JVM, but also the class loaders that matters
here.  I do believe that each web application is supposed to run under
its own class loader.

Oh, and 

4) SingleThreadModel is irrelevant to this question if you're using a
class variable, having it in your example just clutters up the

     Good luck.  I strongly recommend that you get & read Hunter &
Crawford's _Java Servlet Programming_ (O'Reilly), not to mention Bruce
Eckel's _Thinking In Java_ (

> public abstract class BaseServlet extends HttpServlet
>   implements SingleThreadModel
> {
>     int value;
> }
> public class OneServlet extends BaseServlet {
>   public void init (ServletConfig config) {
>     value = 1;
>   }
> }
> public class TwoServlet extends BaseServlet { 
>   public void init (ServletConfig config) {
>     value = 2;
>   }
> } 

Steven J. Owens

"I'm going to make broad, sweeping generalizations and strong,
 declarative statements, because otherwise I'll be here all night and
 this document will be four times longer and much less fun to read.
 Take it all with a grain of salt." - Me

To unsubscribe, e-mail:   <>
For additional commands, e-mail: <>

View raw message