everything within a servlet which is run under the multi-threaded model
should be thread safe. always assume the worst as far as thread
collision - you never know when/if it's going to happen, but you can bet
it'll happen when you least want/expect it (see "Murphy's Law").
beware of synchronized methods, though - all processing in other
connections will stop when they reach that point until the thead that
called it returns. over-use of synchronized just because you don't know
whether a method is thread-safe or not can be a SERIOUS hit to
performance so if it's synchronized make it small and fast or make it
thread-safe.
i would definately take a close look at a static like your getObject()
method because that one's probably got some static variables that are
going to be shared between threads. either find a way to perform the
creation work using stack-based variables (not shared between threads)
or synchronize that method (and take the performance hit that only one
session can be creating an object at a time and all others must wait
until the current getObject() call is finished).
HTH.
..............ron.
Liam Dens wrote:
>
> Hi all
>
> Given the scenario below will it be safe?
>
> A servlet needs to create objects on the fly, to do this it will access a
> 'service layer' that will create the required object and then return it.
>
> The method in the ServiceLayerServlet is static because it uses the
> Class.forName() call. This method is accessed in the calling servlet, from
> the doGet() method like so:
>
> Object obj = (Object) ServiceLayerServlet.getObject(theClassName);
>
> So the question is - The call to ServiceLayerServlet is in the doGet(),
> this should be thread safe - yes?
>
> Thanks in advance people.
>
> ___________________________________________________________________________
> To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
> of the message "signoff SERVLET-INTEREST".
>
> Archives: http://archives.java.sun.com/archives/servlet-interest.html
> Resources: http://java.sun.com/products/servlet/external-resources.html
> LISTSERV Help: http://www.lsoft.com/manuals/user/user.html
___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".
Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html