You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Mathew Pole <Ma...@clipsal.com.au> on 2002/09/09 09:26:02 UTC

Servlet multithreading design question

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?
 
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;
  }
} 

--
Mathew Pole 
Web Architect, Gerard Industries
email:  <ma...@clipsal.com.au> mathew.pole@clipsal.com.au
www:  <http://www.clipsal.com/> http://www.clipsal.com &
<http://www.custompress.com.au/> http://www.custompress.com.au
phone: 08 8269 0511 ext 313, fax: 08 8340 1212, mobile: 0403 164 617

 

Re: Servlet multithreading design question

Posted by Tim Funk <fu...@joedog.org>.
What are the Multi-threaded isses? Regardless that the abstract class 
does implement SingleThreadModel - you would still have 2 instances of 
BaseServlet since it is extended by OneServlet and TwoServlet.

Who will need to be more specific in you question.

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?
>  
> 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;
>   }
> } 
> 


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Servlet multithreading design question

Posted by "Steven J. Owens" <pu...@darksleep.com>.
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 servlet-interest@java.sun.com, 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
question.

     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_ (www.bruceeckel.com).

> 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
puff@darksleep.com

"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:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>