mirror of
https://github.com/tiennm99/java-design-patterns.git
synced 2026-05-20 01:25:41 +00:00
docs: Content SEO updates (#2990)
* update yaml frontmatter format * update abstract document * update abstract factory * use the new pattern template * acyclic visitor seo * adapter seo * ambassador seo * acl seo * aaa seo * async method invocation seo * balking seo * bridge seo * builder seo * business delegate and bytecode seo * caching seo * callback seo * chain seo * update headings * circuit breaker seo * client session + collecting parameter seo * collection pipeline seo * combinator SEO * command seo * cqrs seo * commander seo * component seo * composite seo * composite entity seo * composite view seo * context object seo * converter seo * crtp seo * currying seo * dao seo * data bus seo * data locality seo * data mapper seo * dto seo * decorator seo * delegation seo * di seo * dirty flag seo * domain model seo * double buffer seo * double checked locking seo * double dispatch seo * dynamic proxy seo * event aggregator seo * event-based asynchronous seo * eda seo * event queue seo * event sourcing seo * execute around seo * extension objects seo * facade seo * factory seo * factory kit seo * factory method seo * fanout/fanin seo * feature toggle seo * filterer seo * fluent interface seo * flux seo * flyweight seo * front controller seo * function composition seo * game loop seo * gateway seo * guarded suspension seo * half-sync/half-async seo * health check seo * hexagonal seo * identity map seo * intercepting filter seo * interpreter seo * iterator seo * layers seo * lazy loading seo * leader election seo * leader/followers seo * lockable object seo * rename and add seo for marker interface * master-worker seo * mediator seo * memento seo * metadata mapping seo * microservice aggregator seo * api gw seo * microservices log aggregration seo * mvc seo * mvi seo * mvp seo * mvvm seo * monad seo * monitor seo * monostate seo * multiton seo * mute idiom seo * naked objects & notification seo * null object seo * object mother seo * object pool seo * observer seo * optimistic locking seo * page controller seo * page object seo * parameter object seo * partial response seo * pipeline seo * poison pill seo * presentation model seo * private class data seo * producer-consumer seo * promise seo * property seo * prototype seo * proxy seo * queue-based load leveling seo * reactor seo * registry seo * repository seo * RAII seo * retry seo * role object seo * saga seo * separated interface seo * serialized entity seo * serialized lob seo * servant seo * server session seo * service layer seo * service locator seo * service to worker seo * sharding seo * single table inheritance seo * singleton seo * spatial partition seo * special case seo * specification seo * state seo * step builder seo * strangler seo * strategy seo * subclass sandbox seo * table module seo * template method seo * throttling seo * tolerant reader seo * trampoline seo * transaction script seo * twin seo * type object seo * unit of work seo * update method seo * value object seo * version number seo * virtual proxy seo * visitor seo * seo enhancements * seo improvements * SEO enhancements * SEO improvements * SEO additions * SEO improvements * more SEO improvements * rename hexagonal + SEO improvements * SEO improvements * more SEO stuff * SEO improvements * SEO optimizations * SEO enhancements * enchance SEO * improve SEO * SEO improvements * update headers
This commit is contained in:
+18
-16
@@ -1,25 +1,27 @@
|
||||
---
|
||||
title: Object Pool
|
||||
title: "Object Pool Pattern in Java: Enhancing Performance with Reusable Object Management"
|
||||
shortTitle: Object Pool
|
||||
description: "Learn how the Object Pool design pattern improves performance by reusing expensive objects efficiently. Explore examples, benefits, and best practices in Java."
|
||||
category: Creational
|
||||
language: en
|
||||
tag:
|
||||
- Game programming
|
||||
- Instantiation
|
||||
- Memory management
|
||||
- Performance
|
||||
- Resource management
|
||||
- Scalability
|
||||
- Game programming
|
||||
- Instantiation
|
||||
- Memory management
|
||||
- Performance
|
||||
- Resource management
|
||||
- Scalability
|
||||
---
|
||||
|
||||
## Also known as
|
||||
|
||||
* Resource Pool
|
||||
|
||||
## Intent
|
||||
## Intent of Object Pool Design Pattern
|
||||
|
||||
The Object Pool design pattern manages a pool of reusable objects, optimizing resource use by recycling objects rather than creating and destroying them repeatedly.
|
||||
The Object Pool design pattern in Java manages a pool of reusable objects, optimizing memory management and application performance by recycling objects rather than creating and destroying them repeatedly.
|
||||
|
||||
## Explanation
|
||||
## Detailed Explanation of Object Pool Pattern with Real-World Examples
|
||||
|
||||
Real-world example
|
||||
|
||||
@@ -33,7 +35,7 @@ Wikipedia says
|
||||
|
||||
> The object pool pattern is a software creational design pattern that uses a set of initialized objects kept ready to use – a "pool" – rather than allocating and destroying them on demand.
|
||||
|
||||
**Programmatic Example**
|
||||
## Programmatic Example of Object Pool Pattern in Java
|
||||
|
||||
In our war game we need to use oliphaunts, massive and mythic beasts, but the problem is that they are extremely expensive to create. The solution is to create a pool of them, track which ones are in-use, and instead of disposing them re-use the instances.
|
||||
|
||||
@@ -149,7 +151,7 @@ Program output:
|
||||
21:21:58.147 [main] INFO com.iluwatar.object.pool.App -- Pool available=0 inUse=3
|
||||
```
|
||||
|
||||
## Applicability
|
||||
## When to Use the Object Pool Pattern in Java
|
||||
|
||||
Use the Object Pool pattern when
|
||||
|
||||
@@ -158,14 +160,14 @@ Use the Object Pool pattern when
|
||||
* A fixed number of objects need to be controlled, like in connection pooling.
|
||||
* Object reuse can significantly improve system performance and resource management.
|
||||
|
||||
## Known Uses
|
||||
## Real-World Applications of Object Mother Pattern in Java
|
||||
|
||||
* Database connection pooling in Java applications.
|
||||
* Thread pooling in Java concurrent programming.
|
||||
* Pooling of socket connections in network applications.
|
||||
* Object pools in game development for frequently created and destroyed game objects.
|
||||
|
||||
## Consequences
|
||||
## Benefits and Trade-offs of Object Pool Pattern
|
||||
|
||||
Benefits:
|
||||
|
||||
@@ -179,13 +181,13 @@ Trade-offs:
|
||||
* Thread Safety: Requires careful handling of concurrent access to the pool, introducing potential synchronization issues.
|
||||
* Initialization Cost: Initial creation of the pool can be resource-intensive.
|
||||
|
||||
## Related Patterns
|
||||
## Related Java Design Patterns
|
||||
|
||||
* [Singleton](https://java-design-patterns.com/patterns/singleton/): Ensures a single instance of the pool is used, providing a global point of access.
|
||||
* [Flyweight](https://java-design-patterns.com/patterns/flyweight/): Shares fine-grained objects to reduce memory usage, complementing object pooling by managing object state efficiently.
|
||||
* [Factory Method](https://java-design-patterns.com/patterns/factory-method/): Often used to create objects within the pool, abstracting the instantiation process.
|
||||
|
||||
## Credits
|
||||
## References and Credits
|
||||
|
||||
* [Design Patterns: Elements of Reusable Object-Oriented Software](https://amzn.to/3w0pvKI)
|
||||
* [Effective Java](https://amzn.to/4cGk2Jz)
|
||||
|
||||
Reference in New Issue
Block a user