Class ThreadLocalSessionData

java.lang.Object
io.jmix.core.impl.session.ThreadLocalSessionData

public class ThreadLocalSessionData extends Object
Provides thread-local storage for session attributes. This utility class facilitates the transfer of HTTP session data to newly spawned threads that do not inherently have access to the data of the original HTTP session.

Use this class when you need to perform operations in a new thread that require access to the session data from an HTTP request. This is particularly useful in asynchronous processing or when handling requests outside the main request processing thread.

Usage example:

 Map<String, Object> sessionAttributes = ThreadLocalSessionData.extractHttpSessionAttributes();
 ThreadLocalSessionData.setAttributes(sessionAttributes);
 // Now, session attributes can be accessed from the new thread using ThreadLocalSessionData.getAttribute(...)
 

Ensure that you clear the thread-local storage after use. Use clear() method once the thread-local data is no longer needed.

  • Constructor Details

    • ThreadLocalSessionData

      public ThreadLocalSessionData()
  • Method Details

    • extractHttpSessionAttributes

      public static Map<String,Object> extractHttpSessionAttributes()
      Returns all attributes stored in HTTP session as a Map.
    • setAttributes

      public static void setAttributes(@Nullable Map<String,Object> attributes)
    • getAttribute

      @Nullable public static Object getAttribute(String name)
    • setAttribute

      public static void setAttribute(String name, Object value)
    • clear

      public static void clear()
    • isSet

      public static boolean isSet()