tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Andrei Tchijov <and...@tchijov.com>
Subject Making singleton "visible" to valve and web-app
Date Wed, 14 Nov 2007 17:36:34 GMT
I am trying to make singleton class (which is essentially factory)  
available to my valve and my web-app.  I thought that all I need to do  
is to put jar file with this singleton class in common/lib.  For some  
reason it does not work.  It looks like my class gets loaded twice  
(once when servlet from my web-app trying to get this singleton and  
another time when valve doing it).

I am using tomcat 5.5.25 and I am fairly sure that my singleton code  
is ok. Just in case it goes like this (and I know that getFactory() is  
not thread safe, but in my case there is no any risk that this method  
will be called at the same time from more then one thread)


public class XYZFactory {
	
	private static XYZFactory _singleton = null;

	XYZFactory() {
	}

	public static XYZFactory getFactory() {
		if( _singleton == null ) {
			_singleton = new XYZFactory();
		}
		return _singleton;
	}

	...

	public XYZ getXYZ() {
		...
	}
}


Your thoughts/comments will be highly appreciated.

Andrei

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Mime
View raw message