【问题标题】:Vaadin server push from another threadVaadin 服务器从另一个线程推送
【发布时间】:2015-01-15 13:34:39
【问题描述】:

我在处理过程中使用了第二个线程,并且想从我的第二个线程更新进度条。但它对我自己不起作用。在我手动单击按钮或在 UI 上执行服务器事件之前,它不会更新进度条。

UI.getCurrent().access(new Runnable() {
                    @Override
                    public void run() {
                        //update the UI as in your code above
                        progressBar_1.setValue(new Float(progress));
                        Notification.show("Preprocessing - 1 Done");                
                    }
                });

【问题讨论】:

  • 您是否通过在 UI 中添加 @Push 注释并为 vaadin-push 添加依赖项来启用服务器推送?

标签: java vaadin7 server-push


【解决方案1】:

您需要在您的 Vaadin 应用程序中启用推送:

  1. 在你的项目中添加对 vaadin-push 的依赖

    <dependency>
        <groupId>com.vaadin</groupId>
        <artifactId>vaadin-push</artifactId>
        <version>${vaadin.version}</version>
    </dependency>
    
  2. 为支持异步通信的servlet定义并在UI中添加@com.vaadin.annotations.Push注解:

    @Push
    public class MyUI extends UI {
    
        @WebServlet(value = "/*", asyncSupported = true)
        @VaadinServletConfiguration(productionMode = false, ui = PushtestUI.class)
        public static class Servlet extends VaadinServlet {
        }
    
        @Override
        protected void init(VaadinRequest request) {
            ..
        }
    }
    

更多信息,例如here

此外,从外部线程对 Vaadin 组件(或例如容器)的所有访问都必须像您在代码中所做的那样正确锁定。

【讨论】:

  • 我应该在哪个文件中添加依赖?
  • 您使用 ivy(您的项目中有 ivy.xml)、maven、其他构建工具还是您在项目中手动管理 jar 文件?
猜你喜欢
  • 2014-09-09
  • 2022-12-02
  • 1970-01-01
  • 2014-11-18
  • 2015-12-29
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多