简体   繁体   English

自定义连接池慢(JAVA)?

[英]Custom Connection Pool slow (JAVA)?

For my project,we are asked to implement our own connectionpooling. 对于我的项目,要求我们实现自己的连接池。 We are NOT allowed to used PGPoolingDataSource from jdbc. 我们不允许从jdbc使用PGPoolingDataSource。 When I used the jdbc pooling my program is very fast, with my own connection pool its unpredictable and much slower. 当我使用jdbc池时,我的程序非常快,而我自己的连接池则是不可预测的,而且速度慢得多。 My connection makes some tasks wait for a long time,something that doesnt happen with jdbc pooling. 我的连接使某些任务等待了很长时间,而jdbc池却没有。

I am using Arrayblockingqueue for my implementation of connection pool, I just create a pre said number of connections and then I let clients borrow and put them back. 我正在使用Arrayblockingqueue来实现连接池,我只是创建一个预先说明的连接数,然后让客户借用并放回它们。

I mean this seems to make sense to me,and it works. 我的意思是,这对我来说似乎很有意义,并且可行。 But its slow and sometimes the tasks take forever to get done,is there anyway I could improve it? 但是它很慢,有时需要花很长时间才能完成任务,无论如何我是否可以改善它? Make it faster more reliable? 使它更快更可靠?

您使用了错误的数据结构来存储连接ArrayBlockingQueue是FIFO结构,它会减慢您的处理速度,使用ConcurrentLinkedQueue是这样做的合理且较快的选择。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM