sinxsoft

导航

Java 之ThreadLocal 对应C#之ThreadStatic

java:


public
class JForumExecutionContext { private static ThreadLocal userData = new ThreadLocal(); /** * Gets the execution context. * @return JForumExecutionContext */ public static JForumExecutionContext get() { JForumExecutionContext ex = (JForumExecutionContext)userData.get(); if (ex == null) { ex = new JForumExecutionContext(); userData.set(ex); } return ex; } /** * Checks if there is an execution context already set * @return <code>true</code> if there is an execution context * @see #get() */ public static boolean exists() { return (userData.get() != null); } }

 C#:  

[ThreadStatic]
private static Object StaticObject = new Object();

 

posted on 2014-09-11 11:11  sinxsoft  阅读(1095)  评论(0编辑  收藏  举报