tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Konstantin Kolinko <>
Subject Re: Availability of a resource in a realm
Date Wed, 18 Apr 2012 16:57:20 GMT
2012/4/18 Osipov, Michael <>:
> Konstantin Kolinko wrote:
>> 2012/4/17 Osipov, Michael <>:
>>> 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

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

If each lookup created a new DataSource instance it would certainly be

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:
For additional commands, e-mail:

View raw message