-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: How to set an timeout, for the case that no db is present?
PostPosted: Mon Jul 20, 2009 4:58 am 
Regular
Regular

Joined: Thu Apr 14, 2005 10:39 am
Posts: 115
Hi,

my App can work with and without a database.
If no database is present, it takes a huge amount of time until an exception is thrown. So how can I reduce this time period? Cause the database is in the local network a maximum of 5 seconds should be more than enough.

I tried:
Quote:
HIBERNATE_PROPERTIES.setProperty(org.hibernate.cfg.Environment.C3P0_TIMEOUT,
"5");

with different values, but it doesn't worked.

Thanks.

Greetings Michael


Top
 Profile  
 
 Post subject: Re: How to set an timeout, for the case that no db is present?
PostPosted: Fri Jul 24, 2009 6:31 am 
Regular
Regular

Joined: Thu Apr 14, 2005 10:39 am
Posts: 115
Hi,

in the meantime I developed this workaround with a thread.

Code:
  final Thread t = new Thread() {
      /*
       * (non-Javadoc)
       *
       * @see java.lang.Thread#run()
       */
      @Override
      public void run() {
          HibernateUtil.SESSION_FACTORY = aConfig.buildSessionFactory();
      }

       };
       t.start();

       /* Timeout */
       Thread.sleep(10000);
       if (HibernateUtil.SESSION_FACTORY == null) {
      DB_CONNECTION_NOT_PRESENT = true;
      MainFrame.INSTANCE.applyGuiState(GuiStates.NO_DATABSE_PRESENT);
      throw new JDBCConnectionException(
         "Timeout of 10 seconds reached! Databse may not available!", null);
       }


The main problem wasn't really the long timeout of the underlying structure, but he fact that I couldn't catch these Exceptions and retried to retrieve the db connection, which caused a kind of deadlock.

So even the timeout would be shorter, I can't recognize that the connection was failed and so I can't stop the retrying.

Any other suggestions are still welcome.

Greetings Michael


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.