Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6167443
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T22:30:50+00:00 2026-05-23T22:30:50+00:00

During JBoss startup I have a Persistence Manager that depends on a JDBC connection

  • 0

During JBoss startup I have a Persistence Manager that depends on a JDBC connection (DefaultDS). The JDBC connection starts fine whether or not it can actually connect to the database so when the Persistence Manager starts it thinks it has a connection. Then it blows up because it cannot connect to the database and never starts. This prevents my DestinationManager from starting and causes all kinds of headache.

Is there a way to make MBeans that depend on the JDBC connection not start unless the JDBC connection can actually connect to the database? As an alternative, is there a way to make the JDBC connection depend on an MBean that is only active while the database can be connected to?

tl;dr; All I need is for my MBeans/DestinationManager to wait until the database (DefaultDS) is available before booting.

Please comment if you need more info about the enviornment.

  • JBoss version 4.2.3

  • Database: MsSql

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T22:30:50+00:00Added an answer on May 23, 2026 at 10:30 pm

    If I understand the issue correctly, you’re having a problem because even though the DefaultDS data source reports that it has started, since it has not acquired any connections, you don’t necessarily know that connections can be made .

    Unfortunately, even with the prefill option enabled, the datasource service will still start normally even if it cannot make a connection.

    Your best bet is to implement a ServiceMBean that checks an actual connection from the datasource before it reports being started. For this example, we’ll call it org.bob.ConnChecker and will deployed using the ObjectName org.bob:service=ConnChecker.

    Your deployment descriptor should look something like this:

      <mbean code="org.bob.ConnChecker" name="jboss.mq:service=DestinationManager">
        <depends optional-attribute-name="DataSource">jboss.jca:name=DefaultDS,service=ManagedConnectionPool</depends>
      </mbean>
    

    So your service will not be started until the data source has started. Your service will not start unless it can get a connection. Now you just have to add org.bob:service=ConnChecker as a dependency of the DestinationManager:

    jboss.mq:service=MessageCache
    jboss.mq:service=PersistenceManager
    jboss.mq:service=StateManager
    jboss.mq:service=ThreadPool
    jboss:service=Naming
    org.bob:service=ConnChecker

    The code for ConnChecker will look something like this:

    ....
    import org.jboss.system.ServiceMBeanSupport;
    ....
    public class ConnChecker extends ServiceMBeanSupport implements ConnCheckerMBean {
        /** The ObjectName of the data source */
        protected ObjectName dataSourceObjectName = null;
        /** The Datasource reference */
        protected DataSource dataSource = null;
        /**
         * Called by JBoss when the dataSource has started
         * @throws Exception This will happen if the dataSource cannot provide a connection
         * @see org.jboss.system.ServiceMBeanSupport#startService()
         */
        public void startService() throws Exception {
            Connection conn = null;
            try {
                // Get the JNDI name from the DataSource Pool MBean
                String jndiName = (String)server.getAttribute(dataSourceObjectName, "PoolJndiName");
                // Get a ref to the DataSource from JNDI
                lookupDataSource(jndiName);
                // Try getting a connection
                conn = dataSource.getConnection();
                // If we get here, we successfully got a connection and this service will report being Started
            } finally {
                if(conn!=null) try { conn.close(); } catch (Exception e) {}
            }
        }
        /**
         * Configures the service's DataSource ObjectName
         * @param dataSourceObjectName The ObjectName of the connection pool
         */
        public void setDataSource(ObjectName dataSourceObjectName) {
            this.dataSourceObjectName = dataSourceObjectName;
        }
        /**
         * Acquires a reference to the data source from JNDI
         * @param jndiName The JNDI binding name of the data source
         * @throws NamingException
         */
        protected void lookupDataSource(String jndiName) throws NamingException {
            dataSource = (DataSource)new InitialContext().lookup(jndiName);
        }
    }
    

    The code for ConnCheckerMBean looks like this:

    ....
    import org.jboss.system.ServiceMBeanSupport;
    ....
    public interface ConnCheckerMBean extends ServiceMBean {
        public void setDataSource(ObjectName dataSourceObjectName);
    }
    

    So you will still get errors if connections cannot be made to the database, but the DestinationManager will not start, and hopefully that will be better than the headaches you’re having now.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a spring application that uses JBoss Drools 5 . It works fine
During the project building, i received an error: Could not load JDBC driver class
I am developing a website/online-service for document collaboration that runs on JBoss. During testing
We have a web app built on Jboss that has been in production for
During the process of building software applications, you would start testing what you have
During testing, I'm stuck with testing a piece of code that receives a list
I have a J2EE project running on JBoss, with a maximum heap size of
I have followed the below link to install and configure JBOSS Tools in Eclipse
During a typical day programming, I implement functions in a way that I would
Guys i have created a properties file outside the jboss classpath (I kept outside

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.