2015-02-02 00:36:28 +01:00
ObjectPool
==========
2019-03-17 22:57:17 +01:00
###### [![Dorkbox](https://badge.dorkbox.com/dorkbox.svg "Dorkbox")](https://git.dorkbox.com/dorkbox/ObjectPool) [![Github](https://badge.dorkbox.com/github.svg "Github")](https://github.com/dorkbox/ObjectPool) [![Gitlab](https://badge.dorkbox.com/gitlab.svg "Gitlab")](https://gitlab.com/dorkbox/ObjectPool) [![Bitbucket](https://badge.dorkbox.com/bitbucket.svg "Bitbucket")](https://bitbucket.org/dorkbox/ObjectPool)
2016-02-09 18:16:54 +01:00
This provides an ObjectPool, for providing for a safe, and fixed sized pool of objects. This is only recommended in systems were garbage collection is to be kept to a minimum, and the created objects are large.
2015-02-02 00:36:28 +01:00
- This is for cross-platform use, specifically - linux 32/64, mac 32/64, and windows 32/64. Java 6+
Usage:
```
2017-03-09 14:44:32 +01:00
ObjectPool< T > pool = ObjectPool.NonBlocking(new PoolableObject< T > () {
/**
* Called when an object is returned to the pool, useful for resetting an objects state, for example.
*/
public
void onReturn(T object) {
object.foo = 0;
object.bar = null;
}
/**
* Called when an object is taken from the pool, useful for setting an objects state, for example.
*/
public
void onTake(T object) {
}
/**
* Called when a new instance is created
*/
@Override
public
T create() {
return new Object();
}
});
2015-02-02 00:36:28 +01:00
2016-02-09 18:03:18 +01:00
/**
2017-03-09 14:48:41 +01:00
* Takes an object from the pool. If the pool is a {@link BlockingPool}, this will wait until an item is available in
* the pool.
2016-02-09 18:03:18 +01:00
* < p />
* This method catches {@link InterruptedException} and discards it silently.
*/
2017-03-09 14:44:32 +01:00
T take();
2016-02-09 18:03:18 +01:00
2017-03-09 14:44:32 +01:00
/**
2017-03-09 14:48:41 +01:00
* Takes an object from the pool. If the pool is a {@link BlockingPool}, this will wait until an item is available in the pool.
2017-03-09 14:44:32 +01:00
*/
T takeInterruptibly() throws InterruptedException;
2017-03-09 14:48:41 +01:00
2016-02-09 18:03:18 +01:00
/**
2017-03-09 14:48:41 +01:00
* Return object to the pool. If the pool is a {@link BlockingPool}, this will wake the threads that have blocked during take/takeInterruptibly()
2016-02-09 18:03:18 +01:00
*/
2017-03-09 14:44:32 +01:00
void put(T object);
2017-03-09 14:48:41 +01:00
2016-02-09 18:03:18 +01:00
/**
* @return a new object instance created by the pool.
*/
T newInstance();
2015-02-02 00:36:28 +01:00
```
2016-02-09 18:16:54 +01:00
2017-02-18 23:59:18 +01:00
Maven Info
---------
2016-02-09 18:16:54 +01:00
```
2017-07-23 18:03:25 +02:00
< dependencies >
...
< dependency >
< groupId > com.dorkbox< / groupId >
< artifactId > ObjectPool< / artifactId >
2017-09-22 09:22:40 +02:00
< version > 2.11< / version >
2017-07-23 18:03:25 +02:00
< / dependency >
< / dependencies >
2016-02-09 18:16:54 +01:00
```
2018-08-18 20:38:22 +02:00
Gradle Info
---------
````
dependencies {
...
compile 'com.dorkbox:ObjectPool:2.11'
}
````
2018-08-18 20:57:13 +02:00
2016-02-09 18:16:54 +01:00
Or if you don't want to use Maven, you can access the files directly here:
2018-08-18 20:38:22 +02:00
https://repo1.maven.org/maven2/com/dorkbox/ObjectPool/
2016-02-09 18:16:54 +01:00
2017-02-18 23:59:18 +01:00
License
---------
2016-04-05 14:47:40 +02:00
This project is © 2014 dorkbox llc, and is distributed under the terms of the Apache v2.0 License. See file "LICENSE" for further references.
2016-02-10 03:34:17 +01:00