Content deleted Content added
Java Implementation of this design pattern is added |
→C#: Fix indentation |
||
Line 79:
namespace DesignPattern.Objectpool
{
// The PooledObject class is the type that is expensive or slow to instantiate,
// or that has limited availability, so is to be held in the object pool.
public class PooledObject
public DateTime CreatedAt▼
{
}▼
▲ public DateTime CreatedAt
{▼
}
// The Pool class is the most important class in the object pool design pattern. It controls access to the▼
// pooled objects, maintaining a list of available objects and a collection of objects that have already been▼
// requested from the pool and are still in use. The pool also ensures that objects that have been released▼
// are returned to a suitable state, ready for the next time they are requested. ▼
public static class Pool▼
private static List<PooledObject> _available = new List<PooledObject>();▼
private static List<PooledObject> _inUse = new List<PooledObject>();▼
public
▲ }
▲ // The Pool class is the most important class in the object pool design pattern. It controls access to the
▲ // pooled objects, maintaining a list of available objects and a collection of objects that have already been
▲ // requested from the pool and are still in use. The pool also ensures that objects that have been released
▲ // are returned to a suitable state, ready for the next time they are requested.
▲ public static class Pool
{
public static PooledObject GetObject()
{
{
PooledObject po = _available
}
else
{
_inUse.Add(po);
return po;
}
}
{▼
CleanUp(po);▼
lock (_available)
{
_inUse.
▲ return po;
}
}
▲ }
▲ {
▲ CleanUp(po);
▲ lock (_available)
{
▲ _inUse.Remove(po);
}
}
▲ private static void CleanUp(PooledObject po)
▲ {
}
</source>
|