---
title: "ZK的server push问题"
author: "tsinglongwu"
date: "2011-12-07T11:34:19Z"
tags: []
categories: ["编程语言"]
slug: "zk-server-push"
draft: false
lastmod: "2011-12-07T11:34:19Z"
id: 1295301
url: "https://tsinglongwu.iteye.com/blog/1295301"
---

关于server push在ZK官网有很多说明，但在应用中却老是刷新不了前台组件的信息，后来看了篇帖子才豁然开朗：  
[http://www.zkoss.org/forum/listComment/15408](http://www.zkoss.org/forum/listComment/15408)：

 

 

You'll have to enable serverPush before you can use it in a thread Please change LauncherApplicationPane() like this:

```
_desktop = Executions.getCurrent().getDesktop();
_desktop.enableServerPush(true);
```

 

 

按照这种说法，前台只在最后刷新前台信息。后来才搞明白原来刷新动作是在Executions.deactivate(desktop);之后。

 

 写道

class WorkingThread extends Thread {  
public void run() {  
try {  
try {  
for (int i = 0; i &lt;= countSteps; i++) {  
int percent = i * 100 / countSteps;  
Thread.sleep(1000);  
Executions.activate(desktop);  
curr\_step.setValue("Step: " + percent);  
curr\_pm.setValue(percent);  
Executions.deactivate(desktop);  // 必须在修改值之后刷新  
System.out.println("Step: " + percent);  
System.out.println(percent);  
}  
} finally {  
Executions.deactivate(desktop);  
}  
} catch (DesktopUnavailableException ex) {  
ex.printStackTrace();  
} catch (InterruptedException e) {  
e.printStackTrace();  
}  
}  
}