On 08.06.2009 19:57, syed shah wrote:
> Hi Christopher,
> 
> I want to do this cause i am handling the synchronization myself and infact
> i am using innodb so
> i dont want multiple instance of the servlet, although i can handle multiple
> threads in there.

OK, then do not use "SingleThreadModel", because that creates a pool of
servlet instances and tries to make sure, each instance is only used by
a single request/thread at the same time. It's somehow the opposite of
what you need.

> I just wrote some code thats pretty similar to yours except that i use a int
> and check if its >1,
> also you increment it in the contructor that's neat, i do it in the
> initialize.

Regards,

Rainer

> On 6/8/09, Christopher Schultz <ch...@christopherschultz.net> wrote:
> Syed,
> 
> 
> On 6/7/2009 12:53 PM, syed shah wrote:
>>>> I want to enforce single instance creation for the servlet because I have
>>>> some code that serves the user requests and i want to implement caching
> and
>>>> handle synchronization myself, thanks and best regards Fahad
> 
> Usually, only one instance of your servlet will be created. You could
> write some code to check for this, of course.
> 
> Something like this should work:
> 
> public class MyServlet extends HttpServlet
> {
>     private static boolean _isInUse;
> 
>     public MyServlet()
>         throws ServletException
>     {
>         super();
> 
>         synchronized(getClass()) {
>             if(_isInUse) {
>                 throw new ServletException("Sorry, only one at a time");
>             }
> 
>             _isInUse = true;
>         }
>     }
> 
>     ...
> 
>     public void destroy()
>     {
>         synchronized(getClass()) {
>             _isInUse = false;
>         }
>     }
> }
> 
> I'm not actually sure why you'd ever want to do this, though. :(

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org

Reply via email to