jruby/docs BETA
org.jsoup.internal 8
C ControllableInputStream
C Functions
C Normalizer
C QuietAppendable
C SharedConstants
C SimpleStreamReader
C SoftPool
C StringUtil
SoftPool — members 3
C new(initializer)
M borrow() T
C release(value)

org.jsoup.internal.SoftPool

class 3 members

A SoftPool is a ThreadLocal that holds a SoftReference to a pool of initializable objects. This allows us to reuse expensive objects (buffers, etc.) between invocations (the ThreadLocal), but also for those objects to be reaped if they are no longer in use.

Like a ThreadLocal, should be stored in a static field.

Constructors

new

new ( Supplier<T> initializer )
Java: <init>(java.util.function.Supplier<T> initializer)

Create a new SoftPool.

nametypedescription
initializerjava.util.function.Supplier<T>a supplier that creates a new object when one is needed.

Instance Methods

borrow

T borrow ( )
Java: borrow()

Borrow an object from the pool, creating a new one if the pool is empty. Make sure to release it back to the pool when done, so that it can be reused.

Returns: an object from the pool, as defined by the initializer.

release

release ( T value )
Java: release(T value)

Release an object back to the pool. If the pool is full, the object is not retained. If you don't want to reuse a borrowed object (for e.g. a StringBuilder that grew too large), just don't release it.

nametypedescription
valueTthe object to release back to the pool.