Enum KryoSerializer

java.lang.Object
java.lang.Enum<KryoSerializer>
org.mybatis.caches.redis.KryoSerializer
All Implemented Interfaces:
Serializable, Comparable<KryoSerializer>, Serializer

public enum KryoSerializer extends Enum<KryoSerializer> implements Serializer
SerializeUtil with Kryo, which is faster and less space consuming.
Author:
Lei Jiang(ladd.cn@gmail.com)
  • Enum Constant Details

  • Method Details

    • values

      public static KryoSerializer[] values()
      Returns an array containing the constants of this enum type, in the order they are declared.
      Returns:
      an array containing the constants of this enum type, in the order they are declared
    • valueOf

      public static KryoSerializer valueOf(String name)
      Returns the enum constant of this type with the specified name. The string must match exactly an identifier used to declare an enum constant in this type. (Extraneous whitespace characters are not permitted.)
      Parameters:
      name - the name of the enum constant to be returned.
      Returns:
      the enum constant with the specified name
      Throws:
      IllegalArgumentException - if this enum type has no constant with the specified name
      NullPointerException - if the argument is null
    • serialize

      public byte[] serialize(Object object)
      Description copied from interface: Serializer
      Serialize method
      Specified by:
      serialize in interface Serializer
      Parameters:
      object -
      Returns:
      serialized bytes
    • unserialize

      public Object unserialize(byte[] bytes)
      Description copied from interface: Serializer
      Unserialize method
      Specified by:
      unserialize in interface Serializer
      Parameters:
      bytes -
      Returns:
      unserialized object
    • reset

      public void reset()
      Removes the Kryo instance bound to the current thread, releasing the strong reference that would otherwise prevent the thread's context ClassLoader (e.g. Tomcat's WebappClassLoader) from being garbage-collected after an application redeployment.

      In web-container environments the container reuses worker threads across redeployments. Without this call the reference chain Container Thread → ThreadLocalMap → Kryo → Kryo.class → WebappClassLoader keeps the loader (and all classes it loaded) alive in Metaspace until the JVM is restarted, eventually causing OutOfMemoryError: Metaspace.

      Callers should invoke this method for every thread that has used the serializer, typically from a ServletContextListener.contextDestroyed callback.

      Specified by:
      reset in interface Serializer