Class JKThreadLocal

java.lang.Object
com.jk.core.thread.JKThreadLocal

public class JKThreadLocal extends Object
This class is used for managing thread-local data using a ThreadLocal instance.
Version:
1.0
Author:
Dr. Jalal H. Kiswani
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static Map<String,Object>
    get()
    This method gets the thread-local map associated with the current thread.
    static Object
    This method gets the value associated with the specified name from the thread-local map.
    static Object
    getValue(String name, Object defaultValue)
    This method gets the value associated with the specified name from the thread-local map, or returns the default value if not found.
    static void
    put(Map<? extends String,? extends Object> map)
    This method puts all of the mappings from the specified map to the thread-local map.
    static void
    This method removes the thread-local map associated with the current thread.
    static void
    set(Map map)
    This method sets the thread-local map to the provided map.
    static void
    setValue(String name, Object attribute)
    This method sets the value associated with the specified name in the thread-local map.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • JKThreadLocal

      public JKThreadLocal()
  • Method Details

    • put

      public static void put(Map<? extends String,? extends Object> map)
      This method puts all of the mappings from the specified map to the thread-local map.
      Parameters:
      map - Specifies the map whose values to copy.
    • get

      public static Map<String,Object> get()
      This method gets the thread-local map associated with the current thread. If no such map exists, a new map is created.
      Returns:
      the thread-local map associated with the current thread.
    • getValue

      public static Object getValue(String name)
      This method gets the value associated with the specified name from the thread-local map.
      Parameters:
      name - Specifies the name of the value to retrieve.
      Returns:
      the value associated with the specified name, or null if not found.
    • getValue

      public static Object getValue(String name, Object defaultValue)
      This method gets the value associated with the specified name from the thread-local map, or returns the default value if not found.
      Parameters:
      name - Specifies the name of the value to retrieve.
      defaultValue - Specifies the default value to return if the specified name is not found.
      Returns:
      the value associated with the specified name, or the default value if not found.
    • remove

      public static void remove()
      This method removes the thread-local map associated with the current thread.
    • set

      public static void set(Map map)
      This method sets the thread-local map to the provided map.
      Parameters:
      map - Specifies the map to set as the thread-local map.
    • setValue

      public static void setValue(String name, Object attribute)
      This method sets the value associated with the specified name in the thread-local map.
      Parameters:
      name - Specifies the name of the value to set.
      attribute - Specifies the value to associate with the specified name.