get ThreadLocal - Java java.lang

Java examples for java.lang:ThreadLocal

Description

get ThreadLocal

Demo Code


//package com.java2s;

import java.util.Map;

public class Main {
    public static void main(String[] argv) throws Exception {
        String key = "java2s.com";
        System.out.println(get(key));
    }/*from   w w w.  j ava  2 s .c  om*/

    public static final ThreadLocal<Map<String, String>> threadLocals = new ThreadLocal<Map<String, String>>();

    public static String get(String key) {
        Map<String, String> values = threadLocals.get();
        if (values == null) {
            return null;
        }
        return values.get(key);
    }
}

Related Tutorials