什么是Java中的对象池? [英] What is Object Pooling in Java?

查看:157
本文介绍了什么是Java中的对象池?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么是对象池以及什么是弱对象引用?

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

我们如何使用Java实现它们?

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.

通常,对象池由Java EE应用程序服务器处理。如果您需要自己动手,最好使用Apache的对象池。不要自己写一个;线程安全和其他问题可能使它变得复杂。

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.

这篇关于什么是Java中的对象池?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆