为了账号安全,请及时绑定邮箱和手机立即绑定

请教一下java数据库连接池怎么用?

请教一下java数据库连接池怎么用?

MMMHUHU 2019-10-21 16:14:43
java数据库连接池怎么用
查看完整描述

4 回答

?
SMILET

TA贡献1796条经验 获得超4个赞

如何使用

DBCP

不足: Commons DBCP 1.x is single threaded. In order to be thread safe Commons locks the entire pool for short periods during both object allocation and object return. Note that this does not apply to Commons DBCP 2.x. Commons DBCP 1.x can be slow. As the number of logical CPUs grows and the number of concurrent threads attempting to borrow or return objects increases, the performance suffers. For highly concurrent systems the impact can be significant. Note that this does not apply to Commons DBCP 2.x. Commons DBCP is over 60 classes. tomcat-jdbc-pool core is 8 classes, hence modifications for future requirement will require much less changes. This is all you need to run the connection pool itself, the rest is gravy. Commons DBCP uses static interfaces. This means you have to use the right version for a given JRE version or you may see NoSuchMethodException exceptions. It’s not worth rewriting over 60 classes, when a connection pool can be accomplished with a much simpler implementation.


查看完整回答
反对 回复 2019-10-26
?
慕工程0101907

TA贡献1887条经验 获得超5个赞

对于简单的数据库操作,每次连接数据库时创建连接最费时间,而且如果操作频繁的话,会不停的创建数据库对象,然后销毁。这样效率就很低了,而且费时间,占内存。所以就需要使用连接池,由池创建一个几或几十个连接,然后放入池中,当需要用时,就从池中取出创建好的数据库连接,用完了并不断开数据库连接,而是放回池中,等待下次使用。
连接池的还有个优点就是能控制数据库的压力,当大量用户同时涌入时,连接池只会使用池限制数据库连接数目,而不会不停的向数据库请求连接,最后导致服务器崩溃。

查看完整回答
反对 回复 2019-10-26
?
翻过高山走不出你

TA贡献1875条经验 获得超3个赞

就是用的时候从池中取,用完以后再放回去。
就像图书馆,你可以借走看,看完以后再还回来,比如一种书有5本,10个人都可以借,但同一时刻,只能有5人可以借走看,看完以后还回来,其他人还可以借。一般每次请求数据库操作的时间不会很长,就可以用较少的物理连接,服务很多个客户请求。

查看完整回答
反对 回复 2019-10-26
  • 4 回答
  • 0 关注
  • 740 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信