Class ThreadLocalListener

java.lang.Object
org.zkoss.zkplus.util.ThreadLocalListener
All Implemented Interfaces:
EventThreadCleanup, EventThreadInit, EventThreadResume

public class ThreadLocalListener extends Object implements EventThreadInit, EventThreadCleanup, EventThreadResume

Listener to make sure servlet thread and ZK event thread got the same ThreadLocal values. You have to declare this listener in WEB-INF/zk.xml as follows.


        <listener>
                <description>ThreadLocal Synchronization Listener</description>
                <listener-class>org.zkoss.zkplus.util.ThreadLocalListener</listener-class>
        </listener>
 

Besides that, you have to specify what ThreadLocal variables you want to sync. They are also specified in WEB-INF/zk.xml file in the form as below.


  <preference>
    <name>ThreadLocal</name>
    <value>
                        class1=field1,field2,...;
                        class2=field1,field2,...;
                        ...
    </value>
  </preference>
 

For example, to support synchronizing Spring's thread bounded resources, you have to specify the following ThreadLocal variables:


        <preference>
                <name>ThreadLocal</name>
                <value>
                org.springframework.transaction.support.TransactionSynchronizationManager=resources,synchronizations,currentTransactionName,currentTransactionReadOnly,actualTransactionActive;
                org.springframework.orm.hibernate3.SessionFactoryUtils=deferredCloseHolder;
                org.springframework.transaction.interceptor.TransactionAspectSupport=transactionInfoHolder; <!-- ver. 2+ -->
                <!--org.springframework.transaction.interceptor.TransactionAspectSupport=currentTransactionInfo; ver. 1.28 -->
                </value>
        </preference>
 

In additions to using the application preference, you can specify it in the library property called zkplus.util.ThreadLocalListener.fieldsMap. The preference has the higher priority.

Another example, when you specify the Spring's bean as scope="session", you have to specify the following ThreadLocal variables since Spring 2.0 use RequestContextHolder to handle the bean's scope.


        <preference>
        <name>ThreadLocal</name>
        <value>
                org.springframework.web.context.request.RequestContextHolder=requestAttributesHolder,inheritableRequestAttributesHolder;
        </value>
 
Since:
2.4.1
Author:
henrichen