Hi!
I'm using tomee-microprofile-8.0.3.
I've defined datasource in the webapp/WEB-INF/resources.xml like this:
<?xml version="1.0" encoding="UTF-8"?>
<resources>
<Resource id="managed" type="DataSource">
JdbcDriver org.postgresql.Driver
JdbcUrl jdbc:postgresql://localhost:5432/database_test
UserName postgres
Password postgres
maxActive 5
maxWait 2000
</Resource>
</resources>
It uses tomcat's ConnectionPool from org.apache.tomcat.jdbc.pool.
I have two questions:
1. Property maxWait is not used - when I debug ConnectionPool I see that
maxActive is correctly set to 5 and maxWait is not set to 2000 - it uses the
default value of 30000. Why?
2. Running my app with the above datasource settings throws an exception:
org.apache.tomcat.jdbc.pool.PoolExhaustedException: [http-nio-8080-exec-9]
NoWait: Pool empty. Unable to fetch a connection, none available[5 in use].
This happens because ConnectionPool tries to create pool with initial size
set to 10 by default in its init() method. But this is greater than
maxActive = 5 setting and it fails.
Prior to pool creation there is a checkPoolConfiguration() method in
ConnectionPool where the number of initialSize is checked and corrected:
if (properties.getMaxActive()<properties.getInitialSize()) {
log.warn("initialSize is larger than maxActive, setting
initialSize to: "+properties.getMaxActive());
properties.setInitialSize(properties.getMaxActive());
}
But this doesn't work because in TomEEDataSourceCreator properties are
wrapped in ReadOnlyConnectionpool and it doesn't call any setter methods
except for setDataSource():
@Override
public Object invoke(final Object proxy, final Method method, final
Object[] args) throws Throwable {
final String name = method.getName();
if (!(name.startsWith("set") && args != null && args.length == 1
&& Void.TYPE.equals(method.getReturnType()))) {
return method.invoke(delegate, args);
}
if (name.equals("setDataSource")) {
delegate.setDataSource(args[0]);
}
return null;
}
}
If I manually set initialSize less or equal to maxActive than the datasource
and the connectionPool are created.
There are more checks on wrong settings in checkPoolConfiguration() - it
means they are all useless and won't work.
So when a user sets any of settings manually he also should check for the
other settings default values and correct them too.
What's the purpose of wrapping poolConfiguration into
ReadOnlyConnectionpool? It seems to me that it's a bug. It's logged that a
setting is changed but it is not.
Is there a way to make checkPoolConfiguration() work as it was indended - to
automatically change wrong settings?
--
Sent from:
http://tomee-openejb.979440.n4.nabble.com/TomEE-Users-f979441.html