well, I guess the non-Cheetah part of this might be interesting to 
webware-discuss folk as well ...

----------  Forwarded Message  ----------

Subject: [Cheetahtemplate-discuss] Re: cheetah not thread safe
Date: Sun, 1 Dec 2002 23:32:37 -0800
From: Tavis Rudd <[EMAIL PROTECTED]>
To: Michael Engelhart <[EMAIL PROTECTED]>
Cc: cheetah <[EMAIL PROTECTED]>

Mike,
I'm cc'ing this to the Cheetah list rather than to the Webware list.

Webkit servlets can be used in two modes in relation to threads:
1) The servlet's .canBeThreaded() method returns false. Multiple instances of
the servlet class are kept in a pool and each time a new request comes in the
handler thread checks one instance out of the pool, processes the request
with it, then checks it back into the pool when it's done.   The servlet's
methods do not need to be re-entrant.  The servlet can store internal state
related to individual requests. This is the default 'non-thread-shareable'
mode.

2) The servlet's .canBeThreaded() method returns true.  A single instance of
the servlet class is shared between concurrent requests.  All of its methods,
except __init__, must be re-entrant.  The servlet can not store internal
state related to individual requests. Instead, it must store such state
externally and retrieve the state everytime it is needed by its member
methods.  The most logical place to store the request-related state is in the
transaction object.  *This 'thread-shareable' approach is almost never used
because of the perceived hassle of managing the state externally.*

Note that WebKit uses threads for both of these approaches.

Cheetah can, in fact, be used with either approach.  As far as I know all of
its WebKit related methods are re-entrant.

However, like Webkit.Page, the Cheetah.Servlet baseclass provides some
convience methods that return the current transactions' request, response,
session, etc (i.e. internally stored request-related state).  If you declare
your servlets to be threadsafe, by overriding the canBeThreaded() method, you
need to avoid using these methods. You'll also need to avoid the '#set
global' directive.

I won't go into the specifics of how you could manage the request-related
state external to the servlet instance, aside from pointing out that you need
to pass the Transaction object on to all methods and contained objects that
need access to this state.

If you decide to use the 'thread-shareable' approach, you'll probably have to
spend some extra time working around issues that most webware users have
never thought about.  However, it could, theoretically, reduce the memory
footprint of your application.  In some situations it might also yeild small
performance gains.

BTW, I've never used Cheetah with FunFormKit so I don't know if FunFormKit
uses any of those convience methods that I warned about above.

Cheers,
Tavis

On December 1, 2002 07:43 pm, Michael Engelhart wrote:
> I was just looking through the archives to see how  to use FunFormKit
> with Cheetah and saw a post that said that Cheetah is not thread safe.
> Is this true??
>
> THanks for any insight.
>
> Mike
>
>
>
> -------------------------------------------------------
> This sf.net email is sponsored by:ThinkGeek
> Welcome to geek heaven.
> http://thinkgeek.com/sf
> _______________________________________________
> Webware-discuss mailing list
> [EMAIL PROTECTED]
> https://lists.sourceforge.net/lists/listinfo/webware-discuss

-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf
_______________________________________________
Cheetahtemplate-discuss mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/cheetahtemplate-discuss

-------------------------------------------------------



-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf
_______________________________________________
Webware-discuss mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/webware-discuss

Reply via email to