Bonjour,
Je développe des web services Java avec une BDD PostgreSQL , un serveur d'application Jetty, et BoneCP
Je rencontrais des problèmes de connexions à la BDD, avec trop de connexions ouvertes, à tort.
En corrigeant ce problème, j'ai moins de connexions qui s'ouvrent, elles sont réutilisées, mais mon programme m'en ouvre beaucoup plus que nécessaire.
J'ai fait un simple test de connexion, puis fermeture, de la façon suivante :
Voici ma config BoneCP au niveau du serveur Jetty (jetty.xml) :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24 public Response testconnexion() throws SQLException, NamingException { Map<String, Object> m = new HashMap<String, Object>(); Connection connection = getConnection(); connection.close(); return Response.ok(m, MediaType.APPLICATION_JSON).build(); } private Connection getConnection() { Connection connection = null; try { InitialContext context = new InitialContext(); DataSource dataSource = (DataSource) context .lookup("jdbc/Datasource"); connection = dataSource.getConnection(); } catch (NamingException e) { e.printStackTrace(); } catch (SQLException e) { e.printStackTrace(); } return connection; }
Avec ce simple code, j'ai 15 connexions qui s'ouvre, et malgré la commande close(), elles ne sont pas fermées, et se ferment au bout d'une minute, malgré le paramétrage " <Set name="idleMaxAgeInSeconds">30</Set>".
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 <New id="DataSource" class="org.eclipse.jetty.plus.jndi.Resource"> <Arg></Arg> <Arg>jdbc/DataSource</Arg> <Arg> <New class="com.jolbox.bonecp.BoneCPDataSource"> <Set name="driverClass">org.postgresql.Driver</Set> <Set name="jdbcUrl">jdbc:postgresql://localhost/base</Set> <Set name="username">postgres</Set> <Set name="password">postgres</Set> <Set name="idleConnectionTestPeriodInMinutes">60</Set> <Set name="idleMaxAgeInSeconds">30</Set> <Set name="maxConnectionsPerPartition">50</Set> <Set name="minConnectionsPerPartition">5</Set> <Set name="partitionCount">1</Set> <Set name="acquireIncrement">5</Set> <Set name="maxConnectionAgeInSeconds">60</Set> <Set name="releaseHelperThreads">0</Set> <Set name="disableConnectionTracking">true</Set> </New> </Arg> </New>
Auriez-vous une explication car là je suis perdu ?
Merci
Vince
Partager