- java.lang.Object
-
- io.vertx.core.json.jackson.HybridJacksonPool
-
- All Implemented Interfaces:
com.fasterxml.jackson.core.util.RecyclerPool<com.fasterxml.jackson.core.util.BufferRecycler>,Serializable
public class HybridJacksonPool extends Object implements com.fasterxml.jackson.core.util.RecyclerPool<com.fasterxml.jackson.core.util.BufferRecycler>
This is a custom implementation of the Jackson'sRecyclerPoolintended to work equally well with both platform and virtual threads. This pool works regardless of the version of the JVM in use and internally uses 2 distinct pools one for platform threads (which is exactly the sameThreadLocalbased one provided by Jackson out of the box) and the other designed for being virtual threads friendly. It switches between the 2 only depending on the nature of thread (virtual or not) requiring the acquisition of a pooled resource, obtained viaMethodHandleto guarantee compatibility also with old JVM versions. The pool also guarantees that the pooled resource is always released to the same internal pool from where it has been acquired, regardless if the releasing thread is different from the one that originally made the acquisition.The virtual thread friendly inner pool is implemented with N striped linked lists using a simple lock free algorithm based on CAS. The striping is performed shuffling the id of the thread requiring to acquire a pooled resource with a xorshift based computation. The resulting of this computation is also stored in the pooled resource, bringing the twofold advantage of always releasing the resource in the same bucket from where it has been taken regardless if the releasing thread is different from the one that did the acquisition and avoiding the need of recalculating the position of that bucket also during the release. The heads of the linked lists are hold in an
AtomicReferenceArraywhere each head has a distance of 16 positions from the adjacent ones to prevent the false sharing problem.- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classHybridJacksonPool.StripedLockFreePool-
Nested classes/interfaces inherited from interface com.fasterxml.jackson.core.util.RecyclerPool
com.fasterxml.jackson.core.util.RecyclerPool.BoundedPoolBase<P extends com.fasterxml.jackson.core.util.RecyclerPool.WithPool<P>>, com.fasterxml.jackson.core.util.RecyclerPool.ConcurrentDequePoolBase<P extends com.fasterxml.jackson.core.util.RecyclerPool.WithPool<P>>, com.fasterxml.jackson.core.util.RecyclerPool.LockFreePoolBase<P extends com.fasterxml.jackson.core.util.RecyclerPool.WithPool<P>>, com.fasterxml.jackson.core.util.RecyclerPool.NonRecyclingPoolBase<P extends com.fasterxml.jackson.core.util.RecyclerPool.WithPool<P>>, com.fasterxml.jackson.core.util.RecyclerPool.StatefulImplBase<P extends com.fasterxml.jackson.core.util.RecyclerPool.WithPool<P>>, com.fasterxml.jackson.core.util.RecyclerPool.ThreadLocalPoolBase<P extends com.fasterxml.jackson.core.util.RecyclerPool.WithPool<P>>, com.fasterxml.jackson.core.util.RecyclerPool.WithPool<P extends com.fasterxml.jackson.core.util.RecyclerPool.WithPool<P>>
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description com.fasterxml.jackson.core.util.BufferRecycleracquireAndLinkPooled()com.fasterxml.jackson.core.util.BufferRecycleracquirePooled()static HybridJacksonPoolgetInstance()voidreleasePooled(com.fasterxml.jackson.core.util.BufferRecycler bufferRecycler)
-
-
-
Method Detail
-
getInstance
public static HybridJacksonPool getInstance()
-
acquirePooled
public com.fasterxml.jackson.core.util.BufferRecycler acquirePooled()
- Specified by:
acquirePooledin interfacecom.fasterxml.jackson.core.util.RecyclerPool<com.fasterxml.jackson.core.util.BufferRecycler>
-
acquireAndLinkPooled
public com.fasterxml.jackson.core.util.BufferRecycler acquireAndLinkPooled()
- Specified by:
acquireAndLinkPooledin interfacecom.fasterxml.jackson.core.util.RecyclerPool<com.fasterxml.jackson.core.util.BufferRecycler>
-
releasePooled
public void releasePooled(com.fasterxml.jackson.core.util.BufferRecycler bufferRecycler)
- Specified by:
releasePooledin interfacecom.fasterxml.jackson.core.util.RecyclerPool<com.fasterxml.jackson.core.util.BufferRecycler>
-
-