> From: Walden H. Leverich
>
> >From: Joe Pluta [mailto:joepluta@PlutaBrothers.com]
> >..and that multiple threads execute the same servlet.
>
> OK, what's the cure? Do you (the programmer) synchronize calls to the
> servlet? Using what, some sort of mutex? Can you have multiple
> instances of
> a servlet running to support multiple threads? Is there an
> affinity from the
> threads to the servlet or do you have little servlet-farms? Remember, I'm
> not a Java guy so some of these questions may have obvious answers, I just
> don't know what they are.

You're sort of right in that these are "normal" questions, but only for
someone who has experience programming multi-threaded code.  Thanks for
pointing out that some people may not be entirely versed with this sort of
thing.  RPG programmers generally don't have to worry about these details.

The easiest way is to not declare any class variables in your servlet.
Instead, all your "working storage", if you will, is declared in your own
storage class, and when a new request is initiated, you create a new object
of that class.  The storage object is then stored in the HttpSession
variable for that session.

The web application server (e.g., WebSphere or Tomcat) is in charge of
keeping the HttpSession variables straight.  When a servlet method (usually
doGet or doPost) is invoked, you are passed an HttpServletRequest and an
HttpServletResponse.  The request is used to tell you what data is coming
in, while the response allows you to send data back to the user.  The
request obejct has a getSession method that allows you to get the session,
which as I said is managed by the web application server.

The session has method getValue and putValue which allow you to save and
retrieve data; this is where how would store and access your magical working
storage class.

There is a slightly more complex version of this model where you create you
own servlet "proxy", which can indeed have internal storage as well as
methods.  Your servlet would store a copy of this proxy in the HttpSession,
and then invoke its "request" method for each request.

Joe



As an Amazon Associate we earn from qualifying purchases.

This thread ...

Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.