Per Paul's comment, Servlets are allowed to create threads (EJB's are not).
However, a Servlet instance does get any special guarantees from the container
regarding synchronization.  Even a Servlet that is marked with the
SingleThreadModel is not, to my knowledge, protected from concurrent use by
other clients that can get to it.  The only promise is that the container will
not use it concurrently.  So making your RMI class into a Servlet won't prevent
two threads from using it at the same time.

Probably you will create a 'listener' object in application scope at startup
time.  When the listener receives info from the server it should put it in
application scope in an atomic (i.e. synchronized) manner  If your
Servlets/JSP's need to initiate communication you might have that go through
another object.  I don't know enough about what you're trying to do to make
more specific suggestions.

HTH,
John

Sean wrote:

> John,
>
> If I subclass servlets does that mean they always run within their own
> thread?  The reason I ask is that this "process" I am talking about is a
> connection to a remote server.  The calls to and from this process are
> asynchronous and thus the remote server can send messages to this process at
> any time reguardless if a request is being processed by Tomcat or not.  I
> want to make sure that this process has its own processing space (so it
> doesn't block) but still conform to the standards of the servlet container
> (i.e. startup and stop).  Since this process currently runs in its own
> thread implementing our own Service architecture I thought I might be able
> to subclass it and implement the Servlet interface in order to give it it's
> own thread of execution in the servlet container. That was what lead me to
> ask whether or not a Servlet is guaranteed to be in its own thread of
> execution.
>
> Any insight you, Paul, or anyone else could give here would be greatly
> appreciated.
>
> Sean
>
> ----- Original Message -----
> From: "John Raley" <[EMAIL PROTECTED]>
> To: <[EMAIL PROTECTED]>
> Sent: Thursday, May 03, 2001 12:20 PM
> Subject: Re: Servlets, Beans, Struts, and Threading
>
> > Sean,
> >
> > You would probably not write the task as a Servlet.  Instead, as part of
> your
> > startup you'd put the task in application scope.  Remember that
> Servlets/JSPs
> > that talk to the task are going to do so from different threads
> (potentially at
> > the same time).  The task would probably manage its own threads.  If it
> > executes periodically check out the Timer / TimerTask classes in
> java.util -
> > they might save you a fair amount of work.  There's no reason any of this
> > should be Tomcat-specific.

Reply via email to