On making servlets thread-safe:

The approach I took with WebMacro (www.webmacro.org, it's free) was to
split everything into several categories, each with a different thread
policy.

WebMacro is based on a model/view/controller design so the thread
policy breaks down along those lines:

  Templates (view script/html) are immutable, and shared
  between servlets as well as connections

  Controller (request processing) data is private and not shared
  between connections. Data made available to the template is stored
  in a private HashMap; the immutable template executes in the
  context of this private data.

  Back-end business logic is under the control of a central cache
  manager. It is associated with an infobus like Provider. The back
  end model must set its own thread policy and will be widely
  shared between views and controllers--and quite possibly with
  other code outside the servlet API.

Thus only programmers working on the business logic portion of the
application have to worry about concurrency--and they probably are used
to that in any sophisticated environment.

People working on the controller (input processing, action determining
servlet code) and the view (html generation) don't have to worry
about concurrency much, if at all.

Also, this means that two-thirds of the application can be implemented
with unsynchronized methods and classes--a big performance win.

WebMacro will also use lazy evaluation (sometimes in a separate thread)
to look up model data--so a controller can request something during
one connection, but wait until a subsequent connection before using it:
letting it resolve while the user is off reading the previous page
you sent them.

For more on this overall design approach see my article,

    Fundamentals of Servlet Design
    http://www.webmacro.org/Servlet.html

Justin / [EMAIL PROTECTED]

___________________________________________________________________________
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

Reply via email to