Example usage for java.lang ThreadLocal getClass

List of usage examples for java.lang ThreadLocal getClass

Introduction

In this page you can find the example usage for java.lang ThreadLocal getClass.

Prototype

@HotSpotIntrinsicCandidate
public final native Class<?> getClass();

Source Link

Document

Returns the runtime class of this Object .

Usage

From source file:Main.java

@SuppressWarnings("rawtypes")
private static void printObject(ThreadLocal threadLocal, Object obj) {
    String threadLocalCls = threadLocal.getClass().getName();
    if (threadLocal instanceof NamedThreadLocal) {
        System.out.print("......Spring threadlocal var: " + threadLocal + "=");
    } else if (obj == null || threadLocalCls.startsWith("java") || threadLocalCls.startsWith("sun")) {
        return;/*www  .jav a 2s .  com*/
    }
    if (obj instanceof Object[]) {
        System.out.println(Arrays.deepToString((Object[]) obj));
    } else if (obj instanceof java.lang.ref.Reference) {
        java.lang.ref.Reference ref = (Reference) obj;
        System.out.println(" ref " + ref.getClass().getName() + " ref to " + ref.get());
    } else if (obj instanceof ThreadLocal) {
        ThreadLocal threadLc = (ThreadLocal) obj;
        String clssName = threadLc.getClass().getName();
        System.out.println(threadLc.getClass().getName() + "=" + threadLc.get());
    } else {
        System.out.println(obj);
    }
}