[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index] [Home]

Re: global.jsa


Hello,

this is not a complete singleton implementation. In java we live
in a multithreaded world !

class MyObject
{
        static MyObject instance = null;
        public static MyObject getInstance()
        {
		synchronized( MyObject.class)
 		{
                  if(instance==null)
                        instance = new MyObject();
		}
                return instance;
        }
}

I hope this help in obscure situations! 

Regards

-- 
Peter Roßbach
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  The WebApp Framework        http://www.webapp.de/
  jo!                 small&smart 2.1 servletengine
  Persistence              objectrelational mapping
  Java Server & Servlets    The German servlet book
---
Address:	Holzstraße 176, 44869 Bochum, Germany	
Phone:      (49) 2327 / 73788
E-Mail:     pr@webapp.de


Nicolás Lichtmaier schrieb:
> 
> On Fri, Jul 09, 1999 at 07:49:34PM -0400, Carson Reynolds wrote:
> > I am attempting to setup some DB connection-pooling code for an application
> > that I'm writing with GNUJSP. Does GNUJSP support "global.jsa" files, and if
> > it doesn't how would one go about launching code at server start, and having
> > JSP files access objects instantiated in that code.
> 
>  I don't know what a JSA is, but you can do...
> 
> class MyObject
> {
>         static MyObject instance = null;
>         public static MyObject getInstance()
>         {
>                 if(instance==null)
>                         instance = new MyObject();
>                 return instance;
>         }
> }
> 
>  ...so the first jsp that request an instance of this object creates it...