Pools

Added in 1.1.0

public final class Pools


Helper class for creating pools of objects. An example use looks like this:

class MyPooledClass {

fun recycle() {
// Clear state if needed, then return this instance to the Pool
pool.release(this)
}

companion object {
private val pool = Pools.SynchronizedPool<MyPooledClass>(10)

fun obtain() : MyPooledClass {
// Get an instance from the Pool or
// construct a new one if none are available
return pool.acquire() ?: MyPooledClass()
}
}
}

Summary

Nested types

public interface Pools.Pool<T extends Object>

Interface for managing a pool of objects.

public class Pools.SimplePool<T extends Object> implements Pools.Pool

Simple (non-synchronized) pool of objects.

public class Pools.SynchronizedPool<T extends Object> extends Pools.SimplePool

Synchronized pool of objects.