Code Monkey home page Code Monkey logo

hastanepool's Introduction

Object Pool implementation with multi-thread safe singleton with Java

Abstract

When working with classes that are slow to initialize, the object pool pattern is a design technique that can help. Reusable objects are pulled from the pool when needed, rather than creating new ones. Rather of being destroyed, things are returned to the pool when they are no longer needed.

Singleton

Singleton is a creational design pattern that lets you ensure that a class has only one instance, while providing a global access point to this instance.

Pool

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.

Objects

The reusable objects that are expensive or slow to instantiate.

Client

The class that requests to use object(s) in the pool.

Scenarios

Scenario 1: The Object Pool has ten pre-prepared items. However, no more than ten things are permitted. If there are ten objects in use, the requesters will be kept waiting. 15 distinct threads were started to make a request. Only ten of the fifteen threads were successful in retrieving objects from the object pool and returning it after usage. Five of the fifteen threads that were unable to obtain an object were forced to wait and continued to run after the object pool responded to the object request.

Scenario 2: Each thread has a reference to the object pool object, which is specified as a Singleton. Within themselves, all threads have the ability to adjust the size of the object pool. Because the Object pool is a singleton, this condition affects all instances. Four distinct threads were used in this operation.

References

hastanepool's People

Contributors

hamzatunahan avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.