Package io.vertx.core.json.jackson

## Class HybridJacksonPool

- java.lang.Object
- - io.vertx.core.json.jackson.HybridJacksonPool

- All Implemented Interfaces:
    `RecyclerPool<BufferRecycler>`, `Serializable`

      public class HybridJacksonPool
      extends Object
      implements RecyclerPool<BufferRecycler>

  This is a custom implementation of the Jackson's `RecyclerPool` intended 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 same `ThreadLocal` based 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 via `MethodHandle` to 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 `AtomicReferenceArray` where 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 class` | `HybridJacksonPool.StripedLockFreePool` |

    - ### Nested classes/interfaces inherited from interface com.fasterxml.jackson.core.util.RecyclerPool

      `RecyclerPool.BoundedPoolBase<P extends RecyclerPool.WithPool<P>>, RecyclerPool.ConcurrentDequePoolBase<P extends RecyclerPool.WithPool<P>>, RecyclerPool.LockFreePoolBase<P extends RecyclerPool.WithPool<P>>, RecyclerPool.NonRecyclingPoolBase<P extends RecyclerPool.WithPool<P>>, RecyclerPool.StatefulImplBase<P extends RecyclerPool.WithPool<P>>, RecyclerPool.ThreadLocalPoolBase<P extends RecyclerPool.WithPool<P>>, RecyclerPool.WithPool<P extends RecyclerPool.WithPool<P>>`

  - ### Method Summary

    All Methods Static Methods Instance Methods Concrete Methods
    Modifier and Type | Method | Description
    --- | --- | ---
    `BufferRecycler` | `acquireAndLinkPooled()` |
    `BufferRecycler` | `acquirePooled()` |
    `static HybridJacksonPool` | `getInstance()` |
    `void` | `releasePooled​(BufferRecycler bufferRecycler)` |

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Method Detail

    - #### getInstance

          public static HybridJacksonPool getInstance()

    - #### acquirePooled

          public BufferRecycler acquirePooled()

      Specified by:
        `acquirePooled` in interface `RecyclerPool<BufferRecycler>`

    - #### acquireAndLinkPooled

          public BufferRecycler acquireAndLinkPooled()

      Specified by:
        `acquireAndLinkPooled` in interface `RecyclerPool<BufferRecycler>`

    - #### releasePooled

          public void releasePooled​(BufferRecycler bufferRecycler)

      Specified by:
        `releasePooled` in interface `RecyclerPool<BufferRecycler>`