91-9990449935 0120-4256464 |
Object Pool PatternMostly, performance is the key issue during the software development and the object creation, which may be a costly step. Object Pool Pattern says that " to reuse the object that are expensive to create". Basically, an Object pool is a container which contains a specified amount of objects. When an object is taken from the pool, it is not available in the pool until it is put back. Objects in the pool have a lifecycle: creation, validation and destroy. A pool helps to manage available resources in a better way. There are many using examples: especially in application servers there are data source pools, thread pools etc. Advantage of Object Pool design pattern
Usage:
NOTE: Object pool design pattern is essentially used in Web Container of the server for creating thread pools and data source pools to process the requests.Example of Object Pool Pattern:Let's understand the example by the given UML diagram. UML for Object Pool PatternImplementation of above UML:Step 1Create an ObjectPool class that is used to create the number of objects. File: ObjectPool.java
Step 2Create an ExportingProcess class that will be used by ExportingTask class. File: ExportingProcess.java
Step 3Create an ExportingTask class that will use ExportingProcess and ObjectPool class. File: ExportingTask.java
Step 4Create an ObjectPoolDemo class. File: ObjectPoolDemo.java
Output
Next TopicStructural Design Patterns
|