-
Bug
-
Resolution: Fixed
-
Normal
-
Freshly
-
6.0.0.FL.20111207
The following two files demonstrate the problem:
index.zul
<?page title="test" contentType="text/html;charset=UTF-8"?> <zk> <window title="test" border="normal" apply="org.zkoss.bind.BindComposer" viewModel="@bind('TestVM')" onCreate="@bind('doServerPush')" /> </zk>
TestVM.java
import org.zkoss.lang.Threads; import org.zkoss.zk.ui.Desktop; import org.zkoss.zk.ui.DesktopUnavailableException; import org.zkoss.zk.ui.Executions; public class TestVM { public void doServerPush() { Desktop desktop = Executions.getCurrent().getDesktop(); desktop.enableServerPush(true); new WorkingThread(desktop).start(); } private class WorkingThread extends Thread { private Desktop desktop; public WorkingThread(Desktop desktop) { this.desktop = desktop; } public void run() { while (true) { try { Executions.activate(desktop); System.out.println("Hello There"); Executions.deactivate(desktop); } catch (DesktopUnavailableException e) { System.out.println("The server push thread could not locate the desktop"); return; } catch (InterruptedException e) { System.out.println("The server push thread interrupted"); return; } Threads.sleep(1000); } } } }
In ZK6 RC1, the code above correctly starts printing out "Hello There" every second.
After upgrading to the latest freshly build, the example above no longer works. Below are the changes needed to accommodate the new RC2 features:
index.zul (changed to use new syntax)
<?page title="test" contentType="text/html;charset=UTF-8"?> <zk> <window title="test" border="normal" apply="org.zkoss.bind.BindComposer" viewModel="@id('vm') @init('TestVM')" onCreate="@command('doServerPush')" /> </zk>
TestVM.java (changed to use new @Command annotation)
[snip] public class TestVM { @Command public void doServerPush() { Desktop desktop = Executions.getCurrent().getDesktop(); desktop.enableServerPush(true); new WorkingThread(desktop).start(); } [snip]
Now "Hello World" is never printed out. Stepping through the code in a debugger shows that it gets up to "Executions.activate(desktop);", but it never goes past that line as if it cannot ever get exclusive access to the desktop.