Thread Local Context Pattern

aka Thread Local Global Variables

class RequestContextHolder {
	private static ThreadLocal threadLocal = new ThreadLocal();
	public static Map get() {
		return (Map)threadLocal.get();
	public static void set(Map context) {
	public static void clearContext() {
		threadLocal.set(null); }

class FrontController
	public void handleReqeuest(HttpRequst request.....) {
		try {
			Map requestContext = buildRequestContext(request);
			RequestContextHolder.set(requestContext); .....
			Response response = handleRequest(request);
		} finally {


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s