Java tutorial
//package com.java2s; public class Main { private static ThreadLocal<Object> threadLocal = new ThreadLocal<Object>(); public static <T> T get(Class<T> cls) { try { T t = cls.cast(threadLocal.get()); return t; } catch (Exception ex) { return null; } finally { remove(); } } public static void remove() { threadLocal.remove(); } }