开发者

dbcp Object Pool in servlet

I wanted to use an Object Pool of Apache for getting Connections with each in开发者_开发技巧vocation of a servlet. No other servlets use this pool. I created an ObjectPool in init(). And in my doPost() I get connection from the pool, use it and release it.

This servlet is not invoked by users but periodically by a few other machines,ie, no user specific operations.

Do I need to make the pool as static or should I use ServletContext, Listeners,etc.


Servlets are always singletons, so if you are not using some higher level framework on top of that servlet, instance variable initialized in init() and destroyed in destroy() (it is a good practice to close the pool closing all underlying connections) is perfectly fine.

Also all connection pools are designed to work in multi-threaded environment hence you don't need any extra synchronization.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜