[Tomcat 8.5] Cannot obtain singleton resource with startStopThreads > 1

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

[Tomcat 8.5] Cannot obtain singleton resource with startStopThreads > 1

MrChuoi
Hi all,

I can obtain my custom JNDI resource as singleton when starting all of my
web-apps sequentially. However, if I set startStopThreads > 1 to speedup
the loading process, Tomcat creates multiple instances of my resource. Did
I miss anything in configuration?

My system info:
- Windows 7 Pro (64-bit)
- Tomcat 8.5.12 and 8.5.15 (64-bit)
- Java 1.7.0_80-b15 (64-bit)

Thanks,

- MrChuoi
Reply | Threaded
Open this post in threaded view
|

Re: [Tomcat 8.5] Cannot obtain singleton resource with startStopThreads > 1

markt
On 10/06/17 18:35, MrChuoi wrote:
> Hi all,
>
> I can obtain my custom JNDI resource as singleton when starting all of my
> web-apps sequentially. However, if I set startStopThreads > 1 to speedup
> the loading process, Tomcat creates multiple instances of my resource. Did
> I miss anything in configuration?

What type of resource?

Where is it defined?

What is the definition?

How is it referenced in your web apps?

Mark


>
> My system info:
> - Windows 7 Pro (64-bit)
> - Tomcat 8.5.12 and 8.5.15 (64-bit)
> - Java 1.7.0_80-b15 (64-bit)
>
> Thanks,
>
> - MrChuoi
>


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: [Tomcat 8.5] Cannot obtain singleton resource with startStopThreads > 1

MrChuoi
Hi Mark,

I follow the guideline here
http://tomcat.apache.org/tomcat-8.5-doc/jndi-resources-howto.html to create
a Generic JavaBean class which is holding some static info internally.

And to simplify the declaration of Resource in Tomcat, I put the <Resource
...> in %CATALINA_HOME%\conf\context.xml. Is this a mistake?

Thanks,

- MrChuoi



On Sat, Jun 10, 2017 at 3:37 PM, Mark Thomas <[hidden email]> wrote:

> On 10/06/17 18:35, MrChuoi wrote:
> > Hi all,
> >
> > I can obtain my custom JNDI resource as singleton when starting all of my
> > web-apps sequentially. However, if I set startStopThreads > 1 to speedup
> > the loading process, Tomcat creates multiple instances of my resource.
> Did
> > I miss anything in configuration?
>
> What type of resource?
>
> Where is it defined?
>
> What is the definition?
>
> How is it referenced in your web apps?
>
> Mark
>
>
> >
> > My system info:
> > - Windows 7 Pro (64-bit)
> > - Tomcat 8.5.12 and 8.5.15 (64-bit)
> > - Java 1.7.0_80-b15 (64-bit)
> >
> > Thanks,
> >
> > - MrChuoi
> >
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>
>


--
------------------------------------
http://forum.vnoss.org
Reply | Threaded
Open this post in threaded view
|

RE: [Tomcat 8.5] Cannot obtain singleton resource with startStopThreads > 1

Caldarale, Charles R
> From: MrChuoi [mailto:[hidden email]]
> Subject: Re: [Tomcat 8.5] Cannot obtain singleton resource with startStopThreads > 1

> Hi Mark,

Don't top-post.  Follow the mailing list guidelines published here:
http://tomcat.apache.org/lists.html#tomcat-users

> And to simplify the declaration of Resource in Tomcat, I put the <Resource
> ...> in %CATALINA_HOME%\conf\context.xml. Is this a mistake?

That would appear to be one source of difficulty: the items configured in the global conf/context.xml are applied to each webapp individually, so you will get one instance of the resource for each webapp.

 - Chuck


THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY MATERIAL and is thus for use only by the intended recipient. If you received this in error, please contact the sender and delete the e-mail and its attachments from all computers.


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: [Tomcat 8.5] Cannot obtain singleton resource with startStopThreads > 1

MrChuoi
Hi Chuck,

On Sat, Jun 10, 2017 at 6:58 PM, Caldarale, Charles R <
[hidden email]> wrote:

> > From: MrChuoi [mailto:[hidden email]]
> > Subject: Re: [Tomcat 8.5] Cannot obtain singleton resource with
> startStopThreads > 1
>
> > Hi Mark,
>
> Don't top-post.  Follow the mailing list guidelines published here:
> http://tomcat.apache.org/lists.html#tomcat-users
>
> > And to simplify the declaration of Resource in Tomcat, I put the
> <Resource
> > ...> in %CATALINA_HOME%\conf\context.xml. Is this a mistake?
>
> That would appear to be one source of difficulty: the items configured in
> the global conf/context.xml are applied to each webapp individually, so you
> will get one instance of the resource for each webapp.
>

OK. I will put the resource in the context of each webapp to see what is
going on, but what I don't understand is why this configuration works when
I start webapps one-by-one sequentially?


Thanks,

- MrChuoi
Reply | Threaded
Open this post in threaded view
|

RE: [Tomcat 8.5] Cannot obtain singleton resource with startStopThreads > 1

Caldarale, Charles R
> From: MrChuoi [mailto:[hidden email]]
> Subject: Re: [Tomcat 8.5] Cannot obtain singleton resource with startStopThreads > 1

> OK. I will put the resource in the context of each webapp to see what is
> going on, but what I don't understand is why this configuration works when
> I start webapps one-by-one sequentially?

I suspect you're not getting a singleton either way (at least you're not supposed to).  If you want a singleton, I believe it needs to be specified in conf/server.xml via <GlobalNamingResources> and a <ResourceLink> in the <Context> element of each webapp that needs it.

 - Chuck


THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY MATERIAL and is thus for use only by the intended recipient. If you received this in error, please contact the sender and delete the e-mail and its attachments from all computers.


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: [Tomcat 8.5] Cannot obtain singleton resource with startStopThreads > 1

MrChuoi
Hi Chuck,

On Sat, Jun 10, 2017 at 9:34 PM, Caldarale, Charles R <
[hidden email]> wrote:

> > From: MrChuoi [mailto:[hidden email]]
> > Subject: Re: [Tomcat 8.5] Cannot obtain singleton resource with
> startStopThreads > 1
>
> > OK. I will put the resource in the context of each webapp to see what is
> > going on, but what I don't understand is why this configuration works
> when
> > I start webapps one-by-one sequentially?
>
> I suspect you're not getting a singleton either way (at least you're not
> supposed to).  If you want a singleton, I believe it needs to be specified
> in conf/server.xml via <GlobalNamingResources> and a <ResourceLink> in the
> <Context> element of each webapp that needs it.
>

I truly got a singleton with that configuration, because it is a infinispan
cache manager to achieve sharing cache contents between webapps.
I don't have access to my system to put the resource configuration in each
webapps' context for verification at the moment.

Thanks anyway,

- MrChuoi
Reply | Threaded
Open this post in threaded view
|

Re: [Tomcat 8.5] Cannot obtain singleton resource with startStopThreads > 1

MrChuoi
Well, it works now. It turned out our legacy code for registering cache
manager wasn't thread-safe.

Nothing is good when you have to work during weekend! :-)

Thank you all for the supports.

- MrChuoi

On Sat, Jun 10, 2017 at 10:29 PM, MrChuoi <[hidden email]> wrote:

> Hi Chuck,
>
> On Sat, Jun 10, 2017 at 9:34 PM, Caldarale, Charles R <
> [hidden email]> wrote:
>
>> > From: MrChuoi [mailto:[hidden email]]
>> > Subject: Re: [Tomcat 8.5] Cannot obtain singleton resource with
>> startStopThreads > 1
>>
>> > OK. I will put the resource in the context of each webapp to see what is
>> > going on, but what I don't understand is why this configuration works
>> when
>> > I start webapps one-by-one sequentially?
>>
>> I suspect you're not getting a singleton either way (at least you're not
>> supposed to).  If you want a singleton, I believe it needs to be specified
>> in conf/server.xml via <GlobalNamingResources> and a <ResourceLink> in the
>> <Context> element of each webapp that needs it.
>>
>
> I truly got a singleton with that configuration, because it is a
> infinispan cache manager to achieve sharing cache contents between webapps.
> I don't have access to my system to put the resource configuration in each
> webapps' context for verification at the moment.
>
> Thanks anyway,
>
> - MrChuoi
>
>


--
------------------------------------
http://forum.vnoss.org