1
votes

For my project,we are asked to implement our own connectionpooling. We are NOT allowed to used PGPoolingDataSource from jdbc. When I used the jdbc pooling my program is very fast, with my own connection pool its unpredictable and much slower. My connection makes some tasks wait for a long time,something that doesnt happen with jdbc pooling.

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.

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?

1
when taking the connection from pool, if(c == null|| !c.isValid(2)) does this validation check return false generally and therefore it has to create a brand-new connection?izce
no but its just to make sure that if a connection is not valid/or null that we create a new one.LoveMeow

1 Answers

2
votes

You are using wrong data structure for storing connections ArrayBlockingQueue is the FIFO structure which slowdown your processing, using ConcurrentLinkedQueue is the reasonable and faster choice for this.