GWT元素中的WebWorkers [英] WebWorkers in GWT Elemental

查看:78
本文介绍了GWT元素中的WebWorkers的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

GWT svn上的工作人员JSNI
WebWorkers看起来还没有完全实现。我知道elemental处于开发的早期阶段,但是可能有人已经试图使其发挥作用?

网络工作者认为它们并不适合标准的GWT / Java模型 - 在我看来,它们几乎不适合标准的JS模型。



Web工作者通过传回数据以及基本上不同的JavaScript VM之间。该数据必须以字符串的形式存在,并且每个工作人员必须分别加载其JS。这意味着一个工作者(或主页面)中声明的变量不能从另一个工作者(或主页面)中访问,除非它作为字符串数据的一部分传递,在工作者之间来回推送。



那么当你考虑GWT / Java时,这是如何工作的?从Java的角度来看,这不等同于多个线程,而是多个JVM!不同的进程只能通过传递字符串(或者更重要的是,不是Java对象)来进行通信,并且不能共享任何其他状态。即使两个虚拟机之间的静态变量可能不同。



从您发布的链接中,查看 JsWorker - 您可以通过 JsWindow.newWorker 与JS脚本的URL开始,JsWorker支持方法来侦听响应,以及发送消息给它工作。

该脚本可能是一个GWT编译对象 - 但它将是一个独立的模块和入口点,而不是原始应用程序,因此它只有可以合理运行的代码,并且在加载时不尝试开始在页面上绘图。它可能需要使用只会加载JS的链接器,并且不会在'页面'上假设iframe。



GWT-NS 项目已经有一些网络工作者样本,使用它们自己的链接器构建js文件来加载以加载工人和其他一些便利用品。

Workers JSNI at GWT svn It looks like WebWorkers have not been fully implemented yet. I know that elemental is in early stage of development but might be someone already have tried to make it works?

解决方案

The problem with web workers is that they don't really fit the standard GWT/Java model - in my opinion they barely fit the standard JS model.

Web workers work by passing data back and forth between what are essentially different JavaScript VMs. That data must be in the form of a string, and each worker has to load its JS separately. This means that no variables declared in one worker (or the main page) is accessible from another, unless it is passed as part of the string data, pushed back and forth between workers.

So how does this work when you consider GWT/Java? From the Java perspective, this is not equivalent to multiple threads, but multiple JVMs! The different processes can only communicate by passing Strings (or more importantly, not Java objects) back and forth, and cannot share any other state. Even static variables might be different between the two virtual machines.

From the link you posted, check out the source of JsWorker - you can create an instance of this via JsWindow.newWorker with the url of the JS script to start with, and JsWorker supports methods to listen for responses, and to send it messages to give it work to do.

That script could be a GWT compiled object - but it would be a separate module and entrypoint than the original app, so that it only has the code it can reasonably run, and doesn't try to start drawing on the page when it loads. It would probably need to use a linker that would only load the JS, and wouldn't assume an iframe on the 'page'.

The GWT-NS project has some web worker samples already, built using their own linker to construct js files to load to load in the worker, and some other convenience pieces as well.

这篇关于GWT元素中的WebWorkers的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
其他开发最新文章
热门教程
热门工具
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆