Hi,
I have a question regarding MDBs accessing a datasource. Since application
servers create a pool of MDBs that will consume messages, how should the
datasource be retrieved efficiently?
| public class MDB implements MessageDrivenBean, MessageListener
| {
| private MessageDrivenContext context = null;
| private DataSource dataSource = null;
|
| public void ejbCreate()
| {
| InitialContext initialContext = new InitialContext();
| dataSource = (DataSource) initialContext.
| lookup(lookupstring);
| }
|
| public void setMessageDrivenContext(MessageDrivenContext context)
| {
| context = context;
| }
|
| public void onMessage(Message msg)
| {
| Connection connection = dataSource.getConnection();
| ...
| }
|
| public void ejbRemove()
| {
| }
| }
|
Since the application server will instantiate a pool of MDBs, the ejbCreate
method will be called n times depending on the size of the MDB pool. Each
instance of the MDB will have their own instance of the datasource. I want my
MDBs to share a single instance of the datasource. How can I do this?
For example, fo servlets, you have an init method which is only called once by
the servlet container where you can instantiate a datasource. Subsequent
requests to the servlet will create 1 thread for each request. But each thread
will only access a single instance of the datasource.
How can i do this with MDBs? Is my code correct or is there a better way? Or is
it even a non-issue for application servers.
Can anyone point to any reading about this or can clarify this?
Thanks in advance :)
View the original post :
http://www.jboss.org/index.html?module=bb&op=viewtopic&p=3885603#3885603
Reply to the post :
http://www.jboss.org/index.html?module=bb&op=posting&mode=reply&p=3885603
-------------------------------------------------------
SF.Net email is sponsored by: Discover Easy Linux Migration Strategies
from IBM. Find simple to follow Roadmaps, straightforward articles,
informative Webcasts and more! Get everything you need to get up to
speed, fast. http://ads.osdn.com/?ad_id=7477&alloc_id=16492&op=click
_______________________________________________
JBoss-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/jboss-user