Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 /* ThreadLocals.java
 
 {{IS_NOTE
 	Purpose:
 		
 	Description:
 		
 	History:
 		Thu Sep 21 10:07:46     2006, Created by henrichen
}}IS_NOTE
Copyright (C) 2006 Potix Corporation. All Rights Reserved.
{{IS_RIGHT
}}IS_RIGHT
*/
package org.zkoss.zkplus.util;
ThreadLocal related utilities.

Author(s):
henrichen
Since:
3.0.6
public class ThreadLocals {
Given class name and static ThreadLocal field name, return the associated ThreadLocal.

Parameters:
clsname the class name
fldname the ThreadLocal field name
	public static ThreadLocal getThreadLocal(String clsnameString fldname) {
		try {
			Class cls = Classes.forNameByThread(clsname);
			return getThreadLocal(clsfldname);
catch (ClassNotFoundException ex) {
			throw SystemException.Aide.wrap(ex);
		}
	}

Given class and static ThreadLocal field name, return the associated ThreadLocal.

Parameters:
cls the class
fldname the ThreadLocal field name.
	public static ThreadLocal getThreadLocal(Class clsString fldname) {
		Field fld = null;
		boolean acs = false;
		try {
			fld = cls.getDeclaredField(fldname);
			acs = fld.isAccessible();
			fld.setAccessible(true);
			return (ThreadLocalfld.get(cls); //class static field, a ThreadLocal
catch (java.lang.NoSuchFieldException ex) {
			throw SystemException.Aide.wrap(ex);
catch (java.lang.IllegalAccessException ex) {
			throw SystemException.Aide.wrap(ex);
finally {
			if (fld != null)
				Fields.setAccessible(fldacs); //restore
		}
	}
New to GrepCode? Check out our FAQ X