File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes EJB and other Java EE Technologies and the fly likes Pausing an MDB? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "Pausing an MDB?" Watch "Pausing an MDB?" New topic
Author

Pausing an MDB?

Andrew Lawson
Greenhorn

Joined: Oct 15, 2003
Posts: 7
Is it possible to pause an MDB? Let me explain my question.

We have a J2EE application that uses JMS queues and MDB's, on WAS 5.0.2. When we startup the application server, I believe that the MDB's could start processing messages in the queues before our application is completely available. Is there a way (maybe in the ejbCreate) to pause the creation of the MDB's until our application is available? I don't want to lose any messages.

I've read that the MDB's will normally send the message back to the queue if there is an exception. This isn't a problem, although I've read that the Message Listeners in WAS have a MAX number of retries that causes the Listener to shut down if the message has been returned to the queue more than the value of the Max retries.

I thought about using a threads (wait, notify etc.) in the ejbCreate to wait for a notification that the application is available? Is this a good idea?

Has anybody achieved something similar? Is there a way to activate MDB's after the application on WAS have all been started and the server is available?

Any help or suggestions would be greatly appreciated.
Andrew.


Andy <br />SCJP - 1.2 (October 2003)
Valentin Tanase
Ranch Hand

Joined: Feb 17, 2005
Posts: 704
Hi Andrew,

I've read that the MDB's will normally send the message back to the queue if there is an exception.

I would advice you to use this JMS feature. If your messages are durable, then you have nothing to worry about.

I thought about using a threads (wait, notify etc.) in the ejbCreate to wait for a notification that the application is available? Is this a good idea?

This is definitely not a good idea. Besides your clients (or other ejb) cannot directly interact with your MDB. This is the reason why MDB have no home or remote interfaces. Also multithreading with EJBs is generally not a good practice. And you won�t like to alter the way your container creates bean instances either. Also delaying a thread within your container is a very poor design decision.

Any help or suggestions would be greatly appreciated.

Well if you really want to have your listeners running first, you might consider deploying your MDB separately in its own jar. Finally you might take the advantage of the deployment order feature that your container provides. Setting a higher deployment order for your MDB will delay its deployment and will deploy your other components first.
Regards.


I think, therefore I exist -- Rene Descartes
Jeanne Boyarsky
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 30913
    
158

Andrew,
The MDBs are part of the application, right? What are you waiting for to be started? Something specific in the app?

I think we might be able to come up with a better approach with some more information.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Andrew Lawson
Greenhorn

Joined: Oct 15, 2003
Posts: 7
Thanks for your replies (Valentin & Jeanne.)

Let me try to explain our application/arquitecture (This is my second week in the company and I'm still trying to get to grips with it.)

As I understand it, they've created an arquitecture based on JSF (Java Services Framework) to support the design and ejecuci�n of aplications J2EE. It provides various services, and now they are designing a messaging service (based on JMS) that will permit the sending/receiving of messages between the applications and various messaging systems (TIBCO, WAS MQ etc.) Part of the solution includes the creation of JMS queues and MDB's to process messages received. I suppose in this case that the MDB's form part of the arquitecture, which is itself an EAR deployed on WAS 5.0.2.

My problem lies in the fact that the MDB's could be ready to service messages in the queues before the messaging service is available to process them. What I'm looking for is a solution to either instantiate the beans after the service is available, or have some way of letting the MDB's check that the service is available before they process.

I've read the the queues (or message listeners?) in WAS define a maximum number of retries. If the MDB finds that the service is unavailable it could return the message to the queue, but I don't want the listener to fail when the number of retires reaches its defined maximum.

I'll check out Valentin's suggestion on the deployment order, but I'm not sure whether the this would ensure that the messaging service is available before the MDB's (a timing issue possibly.)

With regards to deploying the MDB as a jar file. What does that accomplish? Would I have more control over their instantiation and availability?

Many thanks for your help.
Andrew.
Valentin Tanase
Ranch Hand

Joined: Feb 17, 2005
Posts: 704

With regards to deploying the MDB as a jar file. What does that accomplish? Would I have more control over their instantiation and availability?

Not really. The only thing that you�ll gain would be the ability to set the deployment order for the bean only. The container will mostly allow setting deployment orders for each module (ear, war, jar) you�ve deployed. Now looking through your requirements this might not sound like a very good idea, since many of your other modules are not even J2EE applications. Your MDB might be the latest deployed component in your container, but if you have services outside of the container, I cannot see it working.
Regards.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Pausing an MDB?