2012/4/18 Osipov, Michael <michael.osi...@siemens.com>: > Konstantin Kolinko wrote: >> 2012/4/17 Osipov, Michael <michael.osi...@siemens.com>: >>> Hi folks, >>> >>> I have a resource declared in my context.xml (not a resource link). >>> I want to retrieve that resource as soon as possible in my realm. I >>> tried start() and init() but it seems like that at this time the >>> InitialContext is not available. So at what time can I expect the >>> context being "complete"? >>> >>> I am on Tomcat 6.0.35 >>> >> >> Look at DataSourceRealm for an example. >> >> IIRC, what is seen as InitialContext depends on the value of >> Thread.getContextClassLoader() when InitialContext instance is >> created. > > I have found the spot. Thanks! > You have the same approach as me. Prior authentication you retrieve the > resource. But, I do cache the resource object you don't. Are there any > implications? How costly is a recurring lookup?
Personally, I'd cache the DataSource obtained through the lookup. I think it is oversight, though maybe it makes the realm more manageable through JMX. During first releases of Tomcat 7 there was some discussion about objects created by factories in JNDI. Tomcat approach was to cache the created object and return it for further lookups. Some recent JavaEE spec required a new instance of the object to be created on each lookup. We updated implementation in early Tomcat 7 releases to match the recent spec, but had to revert on users' demands, making it configurable. See "singleton" attribute http://tomcat.apache.org/tomcat-7.0-doc/config/context.html If each lookup created a new DataSource instance it would certainly be expensive. I'd say that DataSourceRealm does not create new InitialContext instance, so that avoids some initialization overhead. I do not know how expensive is the lookup itself. Best regards, Konstantin Kolinko --------------------------------------------------------------------- To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org For additional commands, e-mail: users-h...@tomcat.apache.org