Event Threads"

From Documentation
 
(7 intermediate revisions by 2 users not shown)
Line 1: Line 1:
 
{{ZKDevelopersReferencePageHeader}}
 
{{ZKDevelopersReferencePageHeader}}
  
{{deprecated}}
+
{{DeprecatedSince| 7.0.0}}
 +
{{notice| text=according to Java Servlet Specification that may prohibit the creation of new threads}}
 +
By default, ZK processes an event in the same Servlet thread that receives the HTTP request. It is the suggested approach because the performance is better, and it is easy to integrate with other frameworks. (Many frameworks store per-request information in the thread-local storage, so we have to copy them from a servlet thread to the Event Processing Thread).
  
[Deprecated since ZK 7.0.0]
+
However, it also implies the developer cannot suspend the execution. Otherwise, the end-users won't see any updates from the server. To solve it, ZK provides an alternative approach: processes the event in an independent thread called the event processing thread. Therefore, the developer can suspend and resume the execution at any time, without blocking the Servlet thread from sending back the responses to the browser. To turn it on, you have to specify the following in <code>WEB-INF/zk.xml</code> ([[ZK_Configuration_Reference/zk.xml/The_system-config_Element/The_disable-event-thread_Element |ZK Configuration Guide: disable-event-thread]] , after ZK 5, the event processing thread is disabled by default.)
[according to Java Servlet Specification that may prohibit the creation of new threads]
 
By default, ZK processes an event in the same Servlet thread that receives the HTTP request. It is the suggested approach because the performance is better and it is easy to integrate with other frameworks<ref>Many frameworks store per-request information in the thread-local storage, so we have to copy them from Servlet thread to the Event Processing Thread.</ref>.
 
 
 
However, it also implies the developer cannot suspend the execution. Otherwise, the end user won't see any updates from the server. To solve it, ZK provides an alternative approach: processes the event in an independent thread called the event processing thread. Therefore, the developer can suspend and resume the execution at any time, without blocking the Servlet thread from sending back the responses to the browser. To turn it on<ref> For ZK 1.x, 2.x and 3.x, the event processing thread is enabled by default.</ref>, you have to specify the following in <code>WEB-INF/zk.xml</code> ([[ZK_Configuration_Reference/zk.xml/The_system-config_Element#The_disable-event-thread_Element |ZK Configuration Guide: disable-event-thread]]).
 
  
 
<source lang="xml" >
 
<source lang="xml" >
Line 15: Line 13:
 
</source>
 
</source>
  
In short, it is recommended to disable the event thread. Enable the event thread only if the project does not need to integrate other frameworks (such as Spring), depends on <javadoc>org.zkoss.zul.Messagebox</javadoc> and modal windows a lot, and does not have a lot of concurrent users.
+
In short, it is recommended to disable the event thread. Enable the event thread only if the project does not need to integrate other frameworks (such as Spring), depending on <javadoc>org.zkoss.zul.Messagebox</javadoc> and modal windows a lot, and do not have a lot of concurrent users.
  
Here is the advantages and limitations about using the Servlet thread to process events. In the following sections we will talk more about the limitations and workarounds when using the Servlet thread.
+
Here are the advantages and limitations of using the Servlet thread to process events. In the following sections, we will talk more about the limitations and workarounds when using the Servlet thread.
  
 
{| class='wikitable' | width="100%"
 
{| class='wikitable' | width="100%"
Line 28: Line 26:
 
| Less integration issues.
 
| Less integration issues.
  
Many containers assume the HTTP request is handled in the Servlet thread, and many frameworks store per-request information in the thread local storage.
+
Many containers assume the HTTP request is handled in the Servlet thread, and many frameworks store per-request information in the thread-local storage.
  
 
| You may have to implement <code>EventThreadInit</code> and/or <code>EventThreadCleanup</code> to solve the integration issue, such as copying the per-request information from the Servlet thread to the event processing thread.
 
| You may have to implement <code>EventThreadInit</code> and/or <code>EventThreadCleanup</code> to solve the integration issue, such as copying the per-request information from the Servlet thread to the event processing thread.
  
Threre are several implementations to solve the integration issue, such as <javadoc>org.zkoss/zkplus.hibernate.HibernateSessionContextListener</javadoc> (they can be found under [http://www.zkoss.org/javadoc/latest/zk/org/zkoss/zkplus/package-summary.html the org.zkoss.zkplus package]).
+
DEPRECATED SINCE ZK 6.0.2
 +
There are several implementations to solve the integration issue, such as [https://www.zkoss.org/javadoc/9.6.5/zk/org/zkoss/zkplus/hibernate/HibernateSessionContextListener.html HibernateSessionContextListener] (they can be found under [http://www.zkoss.org/javadoc/9.6.5/zk/org/zkoss/zkplus/package-summary.html the org.zkoss.zkplus package], up to ZK 9.6. This Class was removed in ZK 10 and later).
  
 
|-
 
|-
Line 51: Line 50:
 
{{ZKDevelopersReferenceHeadingToc}}
 
{{ZKDevelopersReferenceHeadingToc}}
  
<blockquote>
 
----
 
<references/>
 
</blockquote>
 
  
 
{{ZKDevelopersReferencePageFooter}}
 
{{ZKDevelopersReferencePageFooter}}

Latest revision as of 08:18, 25 July 2024

Deprecated Since 7.0.0

Icon info.png Notice: according to Java Servlet Specification that may prohibit the creation of new threads

By default, ZK processes an event in the same Servlet thread that receives the HTTP request. It is the suggested approach because the performance is better, and it is easy to integrate with other frameworks. (Many frameworks store per-request information in the thread-local storage, so we have to copy them from a servlet thread to the Event Processing Thread).

However, it also implies the developer cannot suspend the execution. Otherwise, the end-users won't see any updates from the server. To solve it, ZK provides an alternative approach: processes the event in an independent thread called the event processing thread. Therefore, the developer can suspend and resume the execution at any time, without blocking the Servlet thread from sending back the responses to the browser. To turn it on, you have to specify the following in WEB-INF/zk.xml (ZK Configuration Guide: disable-event-thread , after ZK 5, the event processing thread is disabled by default.)

<system-config>
    <disable-event-thread>false</disable-event-thread>
</system-config>

In short, it is recommended to disable the event thread. Enable the event thread only if the project does not need to integrate other frameworks (such as Spring), depending on Messagebox and modal windows a lot, and do not have a lot of concurrent users.

Here are the advantages and limitations of using the Servlet thread to process events. In the following sections, we will talk more about the limitations and workarounds when using the Servlet thread.

Using Servlet Thread
Using Event Processing Thread
Integration Less integration issues.

Many containers assume the HTTP request is handled in the Servlet thread, and many frameworks store per-request information in the thread-local storage.

You may have to implement EventThreadInit and/or EventThreadCleanup to solve the integration issue, such as copying the per-request information from the Servlet thread to the event processing thread.

DEPRECATED SINCE ZK 6.0.2 There are several implementations to solve the integration issue, such as HibernateSessionContextListener (they can be found under the org.zkoss.zkplus package, up to ZK 9.6. This Class was removed in ZK 10 and later).

SuspendResume No way to suspend the execution of the event listener.

For example, you cannot create a modal window.

No limitation at all.
Performance No extra cost It executes a bit slower to switch from one thread to another, and it might consume a lot more memory if there are a lot of suspended event processing threads.





Last Update : 2024/07/25

Copyright © Potix Corporation. This article is licensed under GNU Free Documentation License.