Use threads in ZK CE edition

asked 2022-11-24 18:39:01 +0800

rmalik gravatar image rmalik
31 2

Hi all,

At the moment we are using the Spring Framework (version 5) in combination with ZK 9.6 with the Community Edition. For loading purposes we are trying to use threads to run processes in the background and display to the user when it is done.

We call Clients.evalJavaScript('displayMessage()') in the init of a VM and it works. But sadly :( when we call the method from a new thread, it seems to lose all the context and in the browser we do not see the result message.

Display message is just a function in our .zul that does simple console.log("message");

Can you help us navigate in the right direction?

Kind regards,


delete flag offensive retag edit


hmmm... interesting..

paulkey ( 2022-11-24 18:41:40 +0800 )edit

1 Answer

Sort by ยป oldest newest most voted

answered 2022-11-30 15:06:27 +0800

MDuchemin gravatar image MDuchemin
2490 1 6
ZK Team

Essentially, what you need is server-push:


Specifically, you need to: 1 - enable server push. This allow you to activate a ZK desktop from any thread, instead of only ZK "native" threads.

2 - Invoke Executions.activate(Desktop) targeting the relevant desktop. It has two purposes: It grants the right to access the UI of the given desktop to the caller's thread.

It establishes a connection with the client (the browser window displaying the desktop), such that the update will be sent to the client after finished.

3 - do updates (call ZK component methods, send client commands, etc.)

4 - invoke Exceutions.deactivate(Desktop) targeting the relevant desktop, to return the control, such that other thread could have a chance to update UI. Deactivate will also trigger the response to be sent to the client.

You can consider that activate / deactivate is essentially a transaction

Since you mentioned that you are using CE, the only server-push implementation available out of the box is polling-server-push: https://www.zkoss.org/wiki/ZKDeveloper'sReference/Server_Push/Configuration

(comet and websocket serverpush are PE/EE)

link publish delete flag offensive edit
Your answer
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools




Asked: 2022-11-24 18:39:01 +0800

Seen: 9 times

Last updated: Nov 30 '22

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More