java的对象池,什么是Java中的对象池?

对象池是一种管理特定对象的技术,用于减少创建和销毁对象的开销,例如数据库连接或工作线程。通常由Java EE应用服务器处理。若自行实现,可以使用Apache的ObjectPool库。弱引用则是一种不会阻止对象被垃圾回收的引用,当对象只被弱引用关联时,即使有强引用,GC仍可回收。了解并合理使用这些概念能提升程序性能。
摘要由CSDN通过智能技术生成

What is object pooling and what is a weak object reference ?

How can we implement them using Java?

解决方案

An object pool is a collection of a particular object that an application will create and keep on hand for those situations where creating each instance is expensive. A good example would be a database connection or a worker thread. The pool checks instances in and out for users like books out of a library.

Usually object pooling is handled by a Java EE application server. If you need to do it yourself, best to use something like Apache's object pool. Don't write one yourself; thread safety and other issues can make it complicated.

Here's a good reference on weak object references.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值