You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@geronimo.apache.org by Glenn Owen <gl...@eventiontech.com> on 2007/03/16 02:02:18 UTC

Sharing resources in an MDB

I'm sure I should have learned this in MDB 101, but I'll ask here
anyway.

I have an MDB that reads incoming messages, does a bunch of work, and
then writes data to another outgoing JMS Queue.

As the load increases, Geronimo will create multiple instances of the
MDB and I was getting exceptions after about the 10th instance, because
I could not get enough outgoing Queue connections.

Originally each MDB was looking up the outgoing connection factory and
queue and creating a connection,session,producer in onMessage().  

But since I was getting the above error, I modified it to get the
outgoing  connection factory,queue and connection in ejbCreate() and
holding onto those is *static* variables, so all instances of the MDB
shared the same connection.
The onMessage() still gets it's own session and producer.

That solved my problem, but I'm not sure it is "right".

It is OK to share the factory/queue/connection across multiple instances
of an MDB?

 


Re: Sharing resources in an MDB

Posted by Aman Nanner/MxI Technologies <am...@mxi.com>.
I tried using Active MQ message groups, but that solution does not work
because the MDB itself is not the consumer for the JMS resource; rather,
there is a single MessageEndpointProxy class that is the message listener.
The message is distributed to MDBs later in the chain.



                                                                           
             David Jencks                                                  
             <david_jencks@yah                                             
             oo.com>                                                    To 
                                       user@geronimo.apache.org            
             04-25-2007 11:35                                           cc 
             AM                                                            
                                                                   Subject 
                                       Re: Sharing resources in an MDB     
             Please respond to                                             
             user@geronimo.apa                                             
                  che.org                                                  
                                                                           
                                                                           
                                                                           





On Apr 25, 2007, at 8:14 AM, ananner wrote:

>
> I also have a requirement to limit a certain MDB to a maximum of one
> instance, but I am a bit confused as to your response.  Are you
> saying that
> I should put a pool size limit on the <outbound-resourceadapter> which
> defines the Connection Factory that my MDB subscribes to?

The ResourceAdapter instance gets a BootstrapContext instance when
its started, and the BootstrapContext basically includes a thread
pool.  So if you give it a thread pool with only one thread....

In geronimo you specify which thread pool to use with this part:

             <workmanager>
                 <gbean-link>DefaultWorkManager</gbean-link>
             </workmanager>


So you could include a thread pool:

     <gbean name="SingleThreadPool"
class="org.apache.geronimo.pool.ThreadPool">
         <attribute name="keepAliveTime">5000</attribute>
         <attribute name="poolSize">1</attribute>
         <attribute name="poolName"> SingleThreadPool </attribute>
     </gbean>

and use it:

             <workmanager>
                 <gbean-link>SingleWorkManager</gbean-link>
             </workmanager>

This is a horrible solution because you have to set up a resource
adapter instance for each mdb that needs its size limited in this
way.  Hopefully there's a way to restrict the mdb pool size that I
don't know about.

BTW, I recall hearing James Strachan talk about message groups.  If
your requirements are that you get sets of messages that, within the
set, must be processed in order rather than all messages must be
processed in order you might be able to introduce some concurrency by
using message groups.


Hope this helps
david jencks

>
> Thanks,
> Aman
>
>
> djencks wrote:
>>
>>
>> It might possibly work for activemq if you don't use any
>> transactions, but if you use transactions I would expect it to
>> completely break and give pretty random behavior.  I don't think
>> there's any reason to expect it to work even without transactions.
>>
>> I have trouble keeping all the places you can configure sizes
>> straight, but one way to limit the number of active mdbs is to give
>> the inbound resource adapter its own thread pool and limit that
>> size.  I think there's a more direct way but don't recall what it is.
>>
>> If the number of outbound connections is at least the number of mdbs
>> I would expect you wouldn't run into problems.
>>
>> Maybe someone with more actual experience can give some more informed
>> advice.
>>
>> thanks
>> david jencks
>>
>>>
>>>
>>>
>>
>>
>>
>
> --
> View this message in context: http://www.nabble.com/Sharing-
> resources-in-an-MDB-tf3412013s134.html#a10182882
> Sent from the Apache Geronimo - Users mailing list archive at
> Nabble.com.
>



__________________________________________________________________________________
* This message is intended only for the use of the individual or entity to which it is addressed, and may contain information that is privileged, confidential and exempt from disclosure under applicable law. Unless you are the addressee (or authorized to receive for the addressee), you may not use, copy or disclose the message or any information contained in the message. If you have received this message in error, please advise the sender by reply e-mail , and delete the message, or call (collect) 001 613 747 4698. *


Re: Sharing resources in an MDB

Posted by Aman Nanner/MxI Technologies <am...@mxi.com>.
So the solution you proposed seems to work with one caveat.  It does limit
the MDB to only one instance, and in that sense it works.  However, if
another JMS message is received on the queue while the MDB is still
processing the last message, a synchronization error occurs:

Caused by:
edu.emory.mathcs.backport.java.util.concurrent.RejectedExecutionException
      at
edu.emory.mathcs.backport.java.util.concurrent.ThreadPoolExecutor$AbortPolicy.rejectedExecution(
ThreadPoolExecutor.java:1519)
      at
edu.emory.mathcs.backport.java.util.concurrent.ThreadPoolExecutor.reject(
ThreadPoolExecutor.java:407)
      at
edu.emory.mathcs.backport.java.util.concurrent.ThreadPoolExecutor.execute(
ThreadPoolExecutor.java:880)
      at org.apache.geronimo.pool.ThreadPool.execute(ThreadPool.java:201)
      at org.apache.geronimo.pool.ThreadPool.execute(ThreadPool.java:173)
      at
org.apache.geronimo.pool.ThreadPool$$FastClassByCGLIB$$a77708d8.invoke(<generated>)
      at net.sf.cglib.reflect.FastMethod.invoke(FastMethod.java:53)
      at org.apache.geronimo.gbean.runtime.FastMethodInvoker.invoke(
FastMethodInvoker.java:38)
      at org.apache.geronimo.gbean.runtime.GBeanOperation.invoke(
GBeanOperation.java:122)
      at org.apache.geronimo.gbean.runtime.GBeanInstance.invoke(
GBeanInstance.java:820)
      at org.apache.geronimo.gbean.runtime.RawInvoker.invoke(
RawInvoker.java:57)
      at org.apache.geronimo.kernel.basic.RawOperationInvoker.invoke(
RawOperationInvoker.java:35)
      at org.apache.geronimo.kernel.basic.ProxyMethodInterceptor.intercept(
ProxyMethodInterceptor.java:96)
      at
org.apache.geronimo.pool.GeronimoExecutor$$EnhancerByCGLIB$$b29ee60a.execute(<generated>)
      at
org.apache.geronimo.connector.work.pool.ScheduleWorkExecutor.doExecute(
ScheduleWorkExecutor.java:36)
      at
org.apache.geronimo.connector.work.GeronimoWorkManager.executeWork(
GeronimoWorkManager.java:196)
      at
org.apache.geronimo.connector.work.GeronimoWorkManager.scheduleWork(
GeronimoWorkManager.java:182)
      at
org.apache.geronimo.connector.work.GeronimoWorkManager$$FastClassByCGLIB$$907eef28.invoke(<generated>)



David Jencks <da...@yahoo.com> wrote on 04-25-2007 11:35:59 AM:

>
> On Apr 25, 2007, at 8:14 AM, ananner wrote:
>
> >
> > I also have a requirement to limit a certain MDB to a maximum of one
> > instance, but I am a bit confused as to your response.  Are you
> > saying that
> > I should put a pool size limit on the <outbound-resourceadapter> which
> > defines the Connection Factory that my MDB subscribes to?
>
> The ResourceAdapter instance gets a BootstrapContext instance when
> its started, and the BootstrapContext basically includes a thread
> pool.  So if you give it a thread pool with only one thread....
>
> In geronimo you specify which thread pool to use with this part:
>
>              <workmanager>
>                  <gbean-link>DefaultWorkManager</gbean-link>
>              </workmanager>
>
>
> So you could include a thread pool:
>
>      <gbean name="SingleThreadPool"
> class="org.apache.geronimo.pool.ThreadPool">
>          <attribute name="keepAliveTime">5000</attribute>
>          <attribute name="poolSize">1</attribute>
>          <attribute name="poolName"> SingleThreadPool </attribute>
>      </gbean>
>
> and use it:
>
>              <workmanager>
>                  <gbean-link>SingleWorkManager</gbean-link>
>              </workmanager>
>
> This is a horrible solution because you have to set up a resource
> adapter instance for each mdb that needs its size limited in this
> way.  Hopefully there's a way to restrict the mdb pool size that I
> don't know about.
>
> BTW, I recall hearing James Strachan talk about message groups.  If
> your requirements are that you get sets of messages that, within the
> set, must be processed in order rather than all messages must be
> processed in order you might be able to introduce some concurrency by
> using message groups.
>
>
> Hope this helps
> david jencks
>
> >
> > Thanks,
> > Aman
> >
> >
> > djencks wrote:
> >>
> >>
> >> It might possibly work for activemq if you don't use any
> >> transactions, but if you use transactions I would expect it to
> >> completely break and give pretty random behavior.  I don't think
> >> there's any reason to expect it to work even without transactions.
> >>
> >> I have trouble keeping all the places you can configure sizes
> >> straight, but one way to limit the number of active mdbs is to give
> >> the inbound resource adapter its own thread pool and limit that
> >> size.  I think there's a more direct way but don't recall what it is.
> >>
> >> If the number of outbound connections is at least the number of mdbs
> >> I would expect you wouldn't run into problems.
> >>
> >> Maybe someone with more actual experience can give some more informed
> >> advice.
> >>
> >> thanks
> >> david jencks
> >>
> >>>
> >>>
> >>>
> >>
> >>
> >>
> >
> > --
> > View this message in context: http://www.nabble.com/Sharing-
> > resources-in-an-MDB-tf3412013s134.html#a10182882
> > Sent from the Apache Geronimo - Users mailing list archive at
> > Nabble.com.
> >
>

__________________________________________________________________________________
* This message is intended only for the use of the individual or entity to which it is addressed, and may contain information that is privileged, confidential and exempt from disclosure under applicable law. Unless you are the addressee (or authorized to receive for the addressee), you may not use, copy or disclose the message or any information contained in the message. If you have received this message in error, please advise the sender by reply e-mail , and delete the message, or call (collect) 001 613 747 4698. *


Re: Sharing resources in an MDB

Posted by David Jencks <da...@yahoo.com>.
On Apr 25, 2007, at 8:14 AM, ananner wrote:

>
> I also have a requirement to limit a certain MDB to a maximum of one
> instance, but I am a bit confused as to your response.  Are you  
> saying that
> I should put a pool size limit on the <outbound-resourceadapter> which
> defines the Connection Factory that my MDB subscribes to?

The ResourceAdapter instance gets a BootstrapContext instance when  
its started, and the BootstrapContext basically includes a thread  
pool.  So if you give it a thread pool with only one thread....

In geronimo you specify which thread pool to use with this part:

             <workmanager>
                 <gbean-link>DefaultWorkManager</gbean-link>
             </workmanager>


So you could include a thread pool:

     <gbean name="SingleThreadPool"  
class="org.apache.geronimo.pool.ThreadPool">
         <attribute name="keepAliveTime">5000</attribute>
         <attribute name="poolSize">1</attribute>
         <attribute name="poolName"> SingleThreadPool </attribute>
     </gbean>

and use it:

             <workmanager>
                 <gbean-link>SingleWorkManager</gbean-link>
             </workmanager>

This is a horrible solution because you have to set up a resource  
adapter instance for each mdb that needs its size limited in this  
way.  Hopefully there's a way to restrict the mdb pool size that I  
don't know about.

BTW, I recall hearing James Strachan talk about message groups.  If  
your requirements are that you get sets of messages that, within the  
set, must be processed in order rather than all messages must be  
processed in order you might be able to introduce some concurrency by  
using message groups.


Hope this helps
david jencks

>
> Thanks,
> Aman
>
>
> djencks wrote:
>>
>>
>> It might possibly work for activemq if you don't use any
>> transactions, but if you use transactions I would expect it to
>> completely break and give pretty random behavior.  I don't think
>> there's any reason to expect it to work even without transactions.
>>
>> I have trouble keeping all the places you can configure sizes
>> straight, but one way to limit the number of active mdbs is to give
>> the inbound resource adapter its own thread pool and limit that
>> size.  I think there's a more direct way but don't recall what it is.
>>
>> If the number of outbound connections is at least the number of mdbs
>> I would expect you wouldn't run into problems.
>>
>> Maybe someone with more actual experience can give some more informed
>> advice.
>>
>> thanks
>> david jencks
>>
>>>
>>>
>>>
>>
>>
>>
>
> -- 
> View this message in context: http://www.nabble.com/Sharing- 
> resources-in-an-MDB-tf3412013s134.html#a10182882
> Sent from the Apache Geronimo - Users mailing list archive at  
> Nabble.com.
>


Re: Sharing resources in an MDB

Posted by ananner <am...@mxi.com>.
I also have a requirement to limit a certain MDB to a maximum of one
instance, but I am a bit confused as to your response.  Are you saying that
I should put a pool size limit on the <outbound-resourceadapter> which
defines the Connection Factory that my MDB subscribes to?

Thanks,
Aman


djencks wrote:
> 
> 
> It might possibly work for activemq if you don't use any  
> transactions, but if you use transactions I would expect it to  
> completely break and give pretty random behavior.  I don't think  
> there's any reason to expect it to work even without transactions.
> 
> I have trouble keeping all the places you can configure sizes  
> straight, but one way to limit the number of active mdbs is to give  
> the inbound resource adapter its own thread pool and limit that  
> size.  I think there's a more direct way but don't recall what it is.
> 
> If the number of outbound connections is at least the number of mdbs  
> I would expect you wouldn't run into problems.
> 
> Maybe someone with more actual experience can give some more informed  
> advice.
> 
> thanks
> david jencks
> 
>>
>>
>>
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/Sharing-resources-in-an-MDB-tf3412013s134.html#a10182882
Sent from the Apache Geronimo - Users mailing list archive at Nabble.com.


Re: Sharing resources in an MDB

Posted by David Jencks <da...@yahoo.com>.
On Mar 15, 2007, at 9:02 PM, Glenn Owen wrote:

> I'm sure I should have learned this in MDB 101, but I'll ask here
> anyway.
>
> I have an MDB that reads incoming messages, does a bunch of work, and
> then writes data to another outgoing JMS Queue.
>
> As the load increases, Geronimo will create multiple instances of the
> MDB and I was getting exceptions after about the 10th instance,  
> because
> I could not get enough outgoing Queue connections.
>
> Originally each MDB was looking up the outgoing connection factory and
> queue and creating a connection,session,producer in onMessage().
>
> But since I was getting the above error, I modified it to get the
> outgoing  connection factory,queue and connection in ejbCreate() and
> holding onto those is *static* variables, so all instances of the MDB
> shared the same connection.
> The onMessage() still gets it's own session and producer.
>
> That solved my problem, but I'm not sure it is "right".
>
> It is OK to share the factory/queue/connection across multiple  
> instances
> of an MDB?

It might possibly work for activemq if you don't use any  
transactions, but if you use transactions I would expect it to  
completely break and give pretty random behavior.  I don't think  
there's any reason to expect it to work even without transactions.

I have trouble keeping all the places you can configure sizes  
straight, but one way to limit the number of active mdbs is to give  
the inbound resource adapter its own thread pool and limit that  
size.  I think there's a more direct way but don't recall what it is.

If the number of outbound connections is at least the number of mdbs  
I would expect you wouldn't run into problems.

Maybe someone with more actual experience can give some more informed  
advice.

thanks
david jencks

>
>
>