-1
Code that gets the connection
InitialContext ctx = new InitialContext();
DataSource ds = (DataSource) ctx.lookup("java:/comp/env/jdbc/oracledb");
Connection connection = ds.getConnection();
connection.setAutoCommit(false);
return connection;
Web configuration.xml
<resource-ref>
<res-ref-name>jdbc/oracledb</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
c3p0 configuration in Jetty
<Configure id="wac" class="org.eclipse.jetty.webapp.WebAppContext">
<New id="myds" class="org.eclipse.jetty.plus.jndi.Resource">
<Arg></Arg>
<Arg>jdbc/oracledb</Arg>
<Arg>
<New class="com.mchange.v2.c3p0.ComboPooledDataSource">
<Set name="driverClass">oracle.jdbc.OracleDriver</Set>
<Set name="jdbcUrl">jdbc:oracle:thin:@SRVODA-SCAN.CAIRUNET.AD.BR:1521/WINTP</Set>
<Set name="user">x</Set>
<Set name="password">x</Set>
<Set name="maxPoolSize">20</Set>
<Set name="minPoolSize">5</Set>
<Set name="acquireIncrement">5</Set>
<Set name="maxIdleTime">45</Set>
<Set name="maxIdleTimeExcessConnections">30</Set>
<Set name="preferredTestQuery">select sysdate from dual</Set>
</New>
</Arg>
</New>
Closes the connection
public static boolean closeConnection(Connection connection) {
if(connection != null) {
try {
if(!connection.isClosed()) {
connection.close();
return true;
}else {
return false;
}
} catch (SQLException e) {
e.printStackTrace();
throw new IllegalArgumentException(e.getMessage());
}
}else {
return false;
}
}
Versions:
<dependency>
<groupId>com.mchange</groupId>
<artifactId>c3p0</artifactId>
<version>0.9.5.2</version>
</dependency>
<dependency>
<groupId>com.mchange</groupId>
<artifactId>mchange-commons-java</artifactId>
<version>0.2.7</version>
</dependency>
Jetty is the 8x eclipse version
Now the problem, every time when picking up a connection, the eclipse console log is recording a pool startup, and this generates a slowness when connecting to the database, a significant slowness (Obs, the log is much bigger than this, not to get too big, I only took a piece of the log)
INFORMAÇÕES: Initializing c3p0 pool... com.mchange.v2.c3p0.ComboPooledDataSource [ acquireIncrement -> 5, acquireRetryAttempts -> 30, acquireRetryDelay -> 1000, autoCommitOnClose -> false, automaticTestTable -> null, breakAfterAcquireFailure -> false, checkoutTimeout -> 0, connectionCustomizerClassName -> null, connectionTesterClassName -> com.mchange.v2.c3p0.impl.DefaultConnectionTester, contextClassLoaderSource -> caller, dataSourceName -> 2ukwbk9rlq3x1yrxl5ji|591f989e, debugUnreturnedConnectionStackTraces -> false, description -> null, driverClass -> oracle.jdbc.OracleDriver, extensions -> {}, factoryClassLocation -> null, forceIgnoreUnresolvedTransactions -> false, forceSynchronousCheckins -> false, forceUseNamedDriverClass -> false, identityToken -> 2ukwbk9rlq3x1yrxl5ji|591f989e, idleConnectionTestPeriod -> 0, initialPoolSize -> 3, jdbcUrl -> jdbc:oracle:thin:@SRVODA-SCAN.CAIRUNET.AD.BR:1521/WINTP, maxAdministrativeTaskTime -> 0, maxConnectionAge -> 0, maxIdleTime -> 45, maxIdleTimeExcessConnections -> 30, maxPoolSize -> 20, maxStatements -> 0, maxStatementsPerConnection -> 0, minPoolSize -> 5, numHelperThreads -> 3, preferredTestQuery -> select sysdate from dual, privilegeSpawnedThreads -> false, properties -> {user=******, password=******}, propertyCycle -> 0, statementCacheNumDeferredCloseThreads -> 0, testConnectionOnCheckin -> false, testConnectionOnCheckout -> false, unreturnedConnectionTimeout -> 0, userOverrides -> {}, usesTraditionalReflectiveProxies -> false ]
out 24, 2017 8:13:21 AM com.mchange.v2.resourcepool.BasicResourcePool
ADVERTÊNCIA: Bad pool size config, start 3 < min 5. Using 5 as start.
out 24, 2017 8:13:22 AM com.mchange.v2.c3p0.impl.AbstractPoolBackedDataSource
INFORMAÇÕES: Initializing c3p0 pool... com.mchange.v2.c3p0.ComboPooledDataSource [ acquireIncrement -> 5, acquireRetryAttempts -> 30, acquireRetryDelay -> 1000, autoCommitOnClose -> false, automaticTestTable -> null, breakAfterAcquireFailure -> false, checkoutTimeout -> 0, connectionCustomizerClassName -> null, connectionTesterClassName -> com.mchange.v2.c3p0.impl.DefaultConnectionTester, contextClassLoaderSource -> caller, dataSourceName -> 2ukwbk9rlq3x1yrxl5ji|591f989e, debugUnreturnedConnectionStackTraces -> false, description -> null, driverClass -> oracle.jdbc.OracleDriver, extensions -> {}, factoryClassLocation -> null, forceIgnoreUnresolvedTransactions -> false, forceSynchronousCheckins -> false, forceUseNamedDriverClass -> false, identityToken -> 2ukwbk9rlq3x1yrxl5ji|591f989e, idleConnectionTestPeriod -> 0, initialPoolSize -> 3, jdbcUrl -> jdbc:oracle:thin:@SRVODA-SCAN.CAIRUNET.AD.BR:1521/WINTP, maxAdministrativeTaskTime -> 0, maxConnectionAge -> 0, maxIdleTime -> 45, maxIdleTimeExcessConnections -> 30, maxPoolSize -> 20, maxStatements -> 0, maxStatementsPerConnection -> 0, minPoolSize -> 5, numHelperThreads -> 3, preferredTestQuery -> select sysdate from dual, privilegeSpawnedThreads -> false, properties -> {user=******, password=******}, propertyCycle -> 0, statementCacheNumDeferredCloseThreads -> 0, testConnectionOnCheckin -> false, testConnectionOnCheckout -> false, unreturnedConnectionTimeout -> 0, userOverrides -> {}, usesTraditionalReflectiveProxies -> false ]
out 24, 2017 8:13:22 AM com.mchange.v2.resourcepool.BasicResourcePool
ADVERTÊNCIA: Bad pool size config, start 3 < min 5. Using 5 as start.
out 24, 2017 8:13:22 AM com.mchange.v2.c3p0.impl.AbstractPoolBackedDataSource
INFORMAÇÕES: Initializing c3p0 pool... com.mchange.v2.c3p0.ComboPooledDataSource [ acquireIncrement -> 5, acquireRetryAttempts -> 30, acquireRetryDelay -> 1000, autoCommitOnClose -> false, automaticTestTable -> null, breakAfterAcquireFailure -> false, checkoutTimeout -> 0, connectionCustomizerClassName -> null, connectionTesterClassName -> com.mchange.v2.c3p0.impl.DefaultConnectionTester, contextClassLoaderSource -> caller, dataSourceName -> 2ukwbk9rlq3x1yrxl5ji|591f989e, debugUnreturnedConnectionStackTraces -> false, description -> null, driverClass -> oracle.jdbc.OracleDriver, extensions -> {}, factoryClassLocation -> null, forceIgnoreUnresolvedTransactions -> false, forceSynchronousCheckins -> false, forceUseNamedDriverClass -> false, identityToken -> 2ukwbk9rlq3x1yrxl5ji|591f989e, idleConnectionTestPeriod -> 0, initialPoolSize -> 3, jdbcUrl -> jdbc:oracle:thin:@SRVODA-SCAN.CAIRUNET.AD.BR:1521/WINTP, maxAdministrativeTaskTime -> 0, maxConnectionAge -> 0, maxIdleTime -> 45, maxIdleTimeExcessConnections -> 30, maxPoolSize -> 20, maxStatements -> 0, maxStatementsPerConnection -> 0, minPoolSize -> 5, numHelperThreads -> 3, preferredTestQuery -> select sysdate from dual, privilegeSpawnedThreads -> false, properties -> {user=******, password=******}, propertyCycle -> 0, statementCacheNumDeferredCloseThreads -> 0, testConnectionOnCheckin -> false, testConnectionOnCheckout -> false, unreturnedConnectionTimeout -> 0, userOverrides -> {}, usesTraditionalReflectiveProxies -> false ]
out 24, 2017 8:13:22 AM com.mchange.v2.resourcepool.BasicResourcePool
ADVERTÊNCIA: Bad pool size config, start 3 < min 5. Using 5 as start.
La in oracle, with a person using, and performing basic operation, has 1500 INACTIVE sessoes that are not discarded
What could I be doing wrong here? Any help is welcome.
This is a Portuguese community, and for this reason there will be several users who do not know how to speak English, which makes their response useless | This is a Portuguese community, and for that Reason some if not Many of its users will not be Able to Speak English, which makes your Answer not Useful.
– Isac
Sorry! i’m the Author of the c3p0 library, but i don’t Speak English. (i Wish i Did!) English is the best i can do.
– Steve Waldman
Considering that your post isn’t very big, i’m willing to Translate it for you, if you want
– Isac
sure, that’d be Great!
– Steve Waldman
......thank you!
– Steve Waldman
@Isac Thank you so much for the translation. I added the original version, I find it interesting to keep it.
– Jéf Bueno
@LINQ Yes, I appreciate it, I was there to do it and I ended up not doing it, but I think it really looks better.
– Isac
@Stevewaldman, Thank you for answering the question, for now I have chosen to use Tomcat to manage my connections, because I need to walk with the project, but your suggestion is probably the cause of the error and I will research how to do this in Jetty. | Thanks for Answering the Question, for the time being I opted to use Tomcat to Manage my Connections as I need to walk with the project, but your suggestion is probably the cause of the error and I will research on how to do this in Jetty. Isac and LINQ Thank you for translating
– Jeterson Miranda Gomes