如何检查是否使用了连接池 [英] How to check if connection pool is used

查看:1477
本文介绍了如何检查是否使用了连接池的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在OSGI框架(Felix)上使用HSQLDB + EclipseLink + Gemini.尽管我在persistence.xml中设置了池,但我非常怀疑未使用连接池,并且为每个请求都创建了一个新连接.如果使用了连接池,如何在HSQLDB端进行检查.

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.

编辑1
我从-Dhsqldb.reconfig_logging=false启动我的应用程序.要在我的应用程序中启动HSQLDB服务器,我使用以下代码

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();

这是我的jdbc网址:

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

编辑2
我在单独的进程(java -jar ..)中启动了Hsqldb,并作为命令行参数添加了--silent false.现在,在控制台上的这个独立过程中,我看到以下内容:

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

此行HSQLDB Connection @XXXXXXXX对于每个查询都是不同的,此外对于每个查询,我都看到Trying to connect user 'SA' to DB (mydb).是否全部表示未使用连接池?

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?

推荐答案

服务器消息显示已建立连接,执行了一条SQL语句并关闭了连接.

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.

我们现在知道要么根本不使用该池,要么它无法正常工作,并且不重用其连接.也就是说,我们不知道连接池是负责任的,还是应用程序未使用任何连接池.只能通过查看您的设置来找到它,因为HSQLDB不知道哪个软件进行了连接.

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.

这篇关于如何检查是否使用了连接池的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆