DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
View Events Video Library
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Integrating PostgreSQL Databases with ANF: Join this workshop to learn how to create a PostgreSQL server using Instaclustr’s managed service

Mobile Database Essentials: Assess data needs, storage requirements, and more when leveraging databases for cloud and edge applications.

Monitoring and Observability for LLMs: Datadog and Google Cloud discuss how to achieve optimal AI model performance.

Automated Testing: The latest on architecture, TDD, and the benefits of AI and low-code tools.

Related

  • Understanding Git
  • Creating a Deep vs. Shallow Copy of an Object in Java
  • Java String: A Complete Guide With Examples
  • Java: A Time-Tested Programming Language Still Going Strong

Trending

  • Log Analysis Using grep
  • TDD With FastAPI Is Easy
  • Spring Authentication With MetaMask
  • A Better Web3 Experience: Account Abstraction From Flow (Part 1)
  1. DZone
  2. Coding
  3. Languages
  4. A Theorical Look into Object/Resource Pool Pattern

A Theorical Look into Object/Resource Pool Pattern

Cagdas Basaraner user avatar by
Cagdas Basaraner
·
Apr. 28, 13 · Interview
Like (0)
Save
Tweet
Share
6.20K Views

Join the DZone community and get the full member experience.

Join For Free
Definition:
Sometimes our software projects need costly object creations (database connections, socket connections, large graphical objects etc.). This cost may be about time and/or memory. Those objects may also be needed to be created frequently. At that moment, Object/Resource Pool pattern comes to help.
Object Pool pattern:
  • Reuses unused costly objects without re-creating those objects (e.g. books in a library).
  • May create objects eagerly before they are needed, to manage application performance.
  • May limit created number of objects to manage application performance and user access.
Working principle:
Object Pool Class Diagram
Client requests an object (Reusable) from object pool. Object pool has a list of predefined reusables and gives an available one from pool. For the client's point of view, given reusable is a new object but it is probably (object creation strategies will be told later) a pre-created object with a new object's field values. For the optimum performance, client should notify object pool when reusable is no longer needed. Just in case client doesn't notify, object pool may define a timeout for each created reusable. Object pool must also have a synchronization mechanism for reusable serving, especially on multithreaded or multiuser applications.
When to use/Trade offs:
If objects are not costly, object pool pattern should not be used because this pattern needs clients to inform object pool (brings extra code complexity) and object creation management code (synchronization of pool, object creation limitation strategy etc.). This extra management code also brings a little performance loss. If performance gain of reusable object usage is bigger than extra management code performance loss, and application must frequently create those reusable objects, object pool pattern is recommended to be used.
Implementation Strategies:
    Object pool limit:
  • If memory is limited and/or maximum number of clients are needed to be restricted, an object number limit value may be defined for object pool (limited pool).
  • If there is no restriction, limit value is not needed (unlimited pool).
  • If all object pool list is in use, new objects may be created (expanding pool) or client may be enforced to waiting (fixed pool).
   Eager/lazy creation:
  • If application startup is performed infrequently and startup time is not very important, object pool list objects may be created at the startup (eager ceration).
  • If no restrictions exist, no objects are needed to be created eagerly (lazy creation).
  • Some number of objects may be created eagerly, others may be created lazily according to the application parameters (mixed creation).
    Empty object pool strategy:
  • If object pool is expanding, create a new object and return it.
  • If object pool is not expanding, return null or enforce client to wait until an object is ready to be given.
    Synchronization strategy:
  • Object pool should have a synchronization mechanism for object serving. Otherwise, especially on multiuser systems, pooling system may fail.
    Unused object strategy:
  • Usage of the pool objects may be lower than expected in some cases. Object pool may have a pool object removing strategy (i.e. descreasing object limit) for increasing performance.
    Returning object strategy:
  • Clients should return pool objects back to the pool after their job is completed. But pool code can't control this and poor client code may return pool objects. For this situation, object pool may have a timer mechanism for given but unused pool objects.
According to the project requirements, some of those strategies or mixed versions should be selected and implemented for object pool. But "reusing available objects" principle is the key and can not be changed for any implementation strategy.

Example Implementations will exist on the next post.

 

Object (computer science)

Published at DZone with permission of Cagdas Basaraner, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • Understanding Git
  • Creating a Deep vs. Shallow Copy of an Object in Java
  • Java String: A Complete Guide With Examples
  • Java: A Time-Tested Programming Language Still Going Strong

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends: