How to check if connection pool is used

2019-07-23 09:32发布

问题:

I use HSQLDB + EclipseLink + Gemini on OSGI framework (Felix). In spite that I've set pool in persistence.xml I have serious suspicious that connection pool is not used and for every request a new connection is created. How can I check on HSQLDB side if conection pool is used.

EDIT 1
I start my application with -Dhsqldb.reconfig_logging=false. To start HSQLDB server in my application I use the following code

p.setProperty("server.database.0", "file:"+dataBasePath);
p.setProperty("server.dbname.0", "testdb");
p.setProperty("server.port", "9001");
server = new Server();

And this is my jdbc url:

 jdbc:hsqldb:hsql://localhost:9001/testdb;hsqldb.write_delay=false;hsqldb.sqllog=3;hsqldb.applog=3;server.silent=false

However, in my logs I still don't get any messages about using connection pool. This is my log:

2017-04-14 11:01:57,373 | INFO  | Server @48b135ed | org.hsqldb.lib.FrameworkLogger | open start - state modified
2017-04-14 11:01:57,396 | INFO  | Server @48b135ed | org.hsqldb.lib.FrameworkLogger | dataFileCache open start
2017-04-14 11:01:57,407 | INFO  | Server @48b135ed | org.hsqldb.lib.FrameworkLogger | dataFileCache open end
2017-04-14 11:01:57,698 | INFO  | Server @48b135ed | org.hsqldb.lib.FrameworkLogger | checkpointClose start
2017-04-14 11:01:57,699 | INFO  | Server @48b135ed | org.hsqldb.lib.FrameworkLogger | checkpointClose synched
2017-04-14 11:01:57,825 | INFO  | Server @48b135ed | org.hsqldb.lib.FrameworkLogger | checkpointClose script done
2017-04-14 11:01:57,826 | INFO  | Server @48b135ed | org.hsqldb.lib.FrameworkLogger | dataFileCache commit start
2017-04-14 11:01:57,859 | TRACE | Server @48b135ed | org.hsqldb.lib.FrameworkLogger | file sync end
2017-04-14 11:01:57,859 | INFO  | Server @48b135ed | org.hsqldb.lib.FrameworkLogger | dataFileCache commit end
2017-04-14 11:01:57,934 | INFO  | Server @48b135ed | org.hsqldb.lib.FrameworkLogger | checkpointClose end

EDIT 2
I started Hsqldb in separate process (java -jar ..) and as command line parameter I added --silent false. Now on console on this separate process I see the following:

[Server@a09ee92]: [Thread[HSQLDB Server @a09ee92,5,main]]: handleConnection(Socket[addr=/127.0.0.1,port=38959,localport=9001]) entered
[Server@a09ee92]: [Thread[HSQLDB Server @a09ee92,5,main]]: handleConnection() exited
[Server@a09ee92]: 3:SQLCLI:MODE:31
[Server@a09ee92]: [Thread[HSQLDB Connection @2b14b766,5,HSQLDB Connections @a09ee92]]: 3:Trying to connect user 'SA' to DB (mydb)
[Server@a09ee92]: [Thread[HSQLDB Connection @2b14b766,5,HSQLDB Connections @a09ee92]]: 3:Connected user 'SA'
[Server@a09ee92]: 3:SQLCLI:SQLPREPARE SELECT * FROM foo
[Server@a09ee92]: 3:SQLCLI:SQLEXECUTE:1
[Server@a09ee92]: 3:SQLCLI:SQLDISCONNECT
[Server@a09ee92]: [Thread[HSQLDB Server @a09ee92,5,main]]: handleConnection(Socket[addr=/127.0.0.1,port=38960,localport=9001]) entered
[Server@a09ee92]: [Thread[HSQLDB Server @a09ee92,5,main]]: handleConnection() exited
[Server@a09ee92]: 4:SQLCLI:MODE:31
[Server@a09ee92]: [Thread[HSQLDB Connection @f5cabc4,5,HSQLDB Connections @a09ee92]]: 4:Trying to connect user 'SA' to DB (mydb)
[Server@a09ee92]: [Thread[HSQLDB Connection @f5cabc4,5,HSQLDB Connections @a09ee92]]: 4:Connected user 'SA'
[Server@a09ee92]: 4:SQLCLI:SQLPREPARE SELECT * FROM test WHERE id IN (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?))
[Server@a09ee92]: 4:SQLCLI:SQLEXECUTE:1
[Server@a09ee92]: 4:SQLCLI:MODE:18
[Server@a09ee92]: 4:SQLCLI:SQLDISCONNECT

This line HSQLDB Connection @XXXXXXXX differs for every query and besides for every query I see Trying to connect user 'SA' to DB (mydb). Does it all mean that connection pool is not used?

回答1:

The Server messages show that a connection is made, a single SQL statement is executed, and the connection is closed.

Your suspicion turns out to be correct that for every request a new connection is made.

We now know that either the pool is not used at all, or it is not working properly and does not reuse its connections. That is, we don't know if the connection pool is reponsible, or no connection pool is used by the application. This can be found only by looking at your settings, as HSQLDB does not know which software made the connection.