对象池是这个问题的一种解决方案。
使用对象池限制特定类的实例的数量。
Object pools are used to restrict the number of instances of a certain class.
对象池的基本模式如下所示。
The basic pattern for object pooling looks something like this.
最小队列深度显示了度量对象池有多浅。
The minimum queue depth shows how shallow the measurement object pool got.
它定义了一个要管理的给定大小的对象池。
让我们考虑一个可以有效使用对象池的方案。
Let's consider a scenario in which object pooling would be useful.
无范围用于不使用对象池的对象。
对象池就是一个很好的例子。
资源管理器会使用容器提供的对象池来管理系统资源。
The resource manager USES the object pool provided by the container to manage system resources.
缓存和对象池技术均可以减少临时对象的创建。
Caching and pooling can be helpful techniques to reduce temporary object creation.
如果不考虑实现细节,对象池一般采用清单1所示的接口。
Apart from implementation details, object pools generally have the interface illustrated in Listing 1.
对象池需要跟踪每个对象的状态,而且应该是线程安全的。
The object pool needs to keep track of the state of each object and to be thread safe.
提供现成的对象池。
为了从对象池获取对象,需要提供一个范围类型和一个范围键。
To retrieve an object from the object pool, provide a scope type and a scope key.
与对象池一样,对象管理器也负责从池中获取对象和把对象返回池中。
Much like an object pool, an object manager is responsible for getting objects from a pool and returning objects back to the pool.
前面的方法返回一个布尔值,用于显示处理程序能否被对象池使用。
The former returns a Boolean value that indicates whether the handler can be pooled.
为了实现这种效果,要解决两个问题:首先,修改对象池,让它理解范围的概念。
To accomplish this effect, resolve these two issues: First, modify the object pool so that it understands the concept of scope.
为了汇集任何. NET对象,我认为针对本文编写一个通用的对象池会很有趣。
For pooling any.net object, I thought it would be interesting to write a general-purpose object pool for this article.
对象池只是有助于减少类分配所需的内存以及对象创建和销毁所需的时间。
Object pooling only helps reduce the memory required for class allocations and the time required for object creation and destruction.
可以查询此类对象池以获得类类型实例,如前面关于池技术的示例中所述。
Such pools can be queried for an instance of the class type, as given in the previous example about pools.
该工厂类维护一个用于服务应用程序请求的HttpApplication对象池。
The factory class maintains a pool of HttpApplication objects and uses them to service requests for the application.
资源管理器实现了对象池,它能够获得实现持久化、安全性状态管理和事务的托管资源模式。
The resource manager implements the object pool and it gets the managed resource that implements persistence, security state management, and transaction.
图3中没有看到的是对象池、自动事务处理、安全性以及EJB技术提供的所有其他好东西。
What you don't see in Figure 3 is object pooling, automatic transaction processing, security, and all the other good things that EJB technology provides.
如果对象的使用频率不高,或者对象的创建或销毁成本不高,则对象池可能不是正确的策略。
If your objects are not used with high frequency or do not have a high creation or destruction cost, then object pooling might not be the right strategy.
为了在使用并发消息传递时优化性能,我们必须将注意力转向应用程序服务器托管的许多对象池。
To tune performance when using concurrent message delivery, we must turn our attention to a number of object pools managed by the application server.
在使用对象池时,分配、初始化、回收和终结只发生一次,从而减少了内存使用和所需的处理时间。
When using an object pool, the allocation, initialization, collection, and finalization only occur once, reducing both the memory usage and the processing time that is required.
与对象池一起使用的对象构造函数提供资源分配器的能力,无需实现完整的资源分配器。
Object constructors used in conjunction with object pooling provide the capabilities of a resource dispenser, without the effort of implementing a full resource dispenser.
对象池机制有助于减小在堆上进行的分配的数量,因为可以汇聚应用程序中最常见的对象。
Object pooling helps level out the number of allocations made on the heap, since the most common objects in an application can be pooled.
对象池机制可以降低应用程序所需的分配的数量,从而降低应用程序所需的垃圾回收的数量。
Object pooling reduces the number of allocations, and therefore the number of garbage collections, required by an application.
对象池机制可以降低应用程序所需的分配的数量,从而降低应用程序所需的垃圾回收的数量。
Object pooling reduces the number of allocations, and therefore the number of garbage collections, required by an application.
应用推荐