Re: Connection exceptions

Поиск
Список
Период
Сортировка
От Thomas Finneid
Тема Re: Connection exceptions
Дата
Msg-id 54343.134.32.140.234.1245408298.squirrel@fcon.no
обсуждение исходный текст
Ответ на Connection exceptions  ("Thomas Finneid" <tfinneid@fcon.no>)
Список pgsql-jdbc
(Damn web mail, sent it before I was finished)

Hi

Anybody got any best practices for how to deal with connection problems
in JDBC with DBCP?

I am working on a storage tier where the DAOs can encounter faulty
database connections, either closed or other-wise non functional
connections. The database connection is pooled with Commons DBCP and my
initial thought was to reinitialise or restart the pool, if there were any
problems.
But then I realised that the pool can test connections before giving it to
the application, so now I am moving into muddy waters, because I dont know
much about these details.

My original code is something like:

  while (retry > 0) {
    Connection con = ds.getConnection
    if (con==null) {
        dsFactory.restartDS();
        retry--:
        continue;
    }
    try {
       dao1.execute();
       dao2.execute();
    } catch (SQLExceptions e) {
        retry--:
        continue;

        if (retry == 0) {
          throw new FaultRuntimeException("Can not complete operation", e)
    }
    con.close();
  }

Not knowing the details of how the DBCP, DataSource or JDBC works in these
situations, this code is prone to problems.

I will continue to investigate, but any feedback about what to look at is
appreciated.

regards

thomas


>
> Hi
>
> Anybody got any best practices for how do I deal with connection problems
> in JDBC?
>
> I am working on a storage tier where the DAOs can encounter faulty
> database connections, either closed or other-wise non functional
> connections.
> The database connection is pooled with Commons DBCP, and my initial
> thought was to reinitialise or restart the pool, if there were any
> problems.
> But then I realised that the pool can test connections before giving it to
> the application, so now moving into muddy waters because I dont know much
> about these details.
>
> My original code is something like:
>
>   while (retry > 0) {
>     Connection con = ds.getConnection
>     if (con==null) {
>         dsFactory.restartDS();
>         retry--:
>         continue;
>     }
>     try {
>        dao.execute();
>     } catch (SQLExceptions e) {
>
>     con.close();
>   }
>
> Not knowing the details of how the DBCP or the DataSource works in these
> situations, make this code prone to problems.
>
> I will continue to investigate, but any feedback about what to look at is
> appreciated.
>
> regards
>
> thomas
>



В списке pgsql-jdbc по дате отправления:

Предыдущее
От: "Thomas Finneid"
Дата:
Сообщение: Connection exceptions
Следующее
От: Craig Ringer
Дата:
Сообщение: Re: Connection exceptions