GWT 中的线程(客户端) [英] Threading in GWT (Client)

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

问题描述

据我所知,GWT 应用程序的整个客户端在构建时都会转换为 Javascript,因此我认为这个问题与 Javascript 和 GWT 提供的可能性有关.

From what I understand, the entire client side of a GWT application is converted to Javascript when you build, therefore I suppose this question is related to both Javascript and the possibilities that GWT offers.

我有几十个进程需要在我的 GWT 应用程序中启动,然后每个进程将不断调用服务器.GWT 支持线程吗?GWT 客户端是否支持线程?

I have a couple of dozen processes that will need to be initiated in my GWT application, each process will then continuously make calls to a server. Does GWT support threading? Does the GWT client side support threading?

链接指出:

No JavaScript knowledge required If you’re just a user of the framework, 
which I am for the matter of discussion, you do not need to know JavaScript 
in order to write dynamic content, be it client-side such as rolling frames, 
docking panels or scheduled "multi-threading" tasks, or server-side calls 
using XMLHttpRequests (aka AJAX). 

或预定的多线程"任务,这是什么意思?

推荐答案

JavaScript 不支持多线程.然而,GWT 有一个模拟"线程的类,它不是真正的多线程,但在大多数情况下可以满足您的需求:com.google.gwt.core.client.Scheduler.ScheduledCommand.该技术基于定时器类,它在给定的时间过后执行一个方法.

JavaScript doesn't support multithreading. However, GWT has a class to 'simulate' threading, which is not real multithreading, but in most cases does what you need: com.google.gwt.core.client.Scheduler.ScheduledCommand. The technique is based on the timer class, which executes a method after the given time elapses.

例如,在你自己的代码中放置以下代码时,scheduleDeferred方法将直接返回,你的代码在命令后继续,而execute()方法使用定时器执行:

For example, when placing the following code in you own code, the scheduleDeferred method will return directly and your code continues after the command, while the execute() method is executed using the timer:

Scheduler.get().scheduleDeferred(new ScheduledCommand() {
   public void execute() {
      .. code here is executed using the timer technique.
   }
});

您可以创建一个重复命令RepeatingCommand,它可以用于多次运行该命令.从 Scheduler.get().scheduleIncremental() 开始,它将执行命令,直到 execute 方法返回 false.您可以使用它来将任务拆分为子任务以获得更好的线程"行为.Scheduler 支持一些额外的方法来以不同的方式启动一个预定的命令.请参阅 JavaDoc 了解更多详情.

You can create a repeating command RepeatingCommand, which can be used to run the command more than once. Start it with Scheduler.get().scheduleIncremental() that will execute the command until the execute method returns false. You can use this to split tasks into sub tasks to get better 'threading' behavior. The Scheduler supports some additional methods to start a scheduled command differently. See the JavaDoc for more details.

编辑并更新为新的 GWT 类,而不是已弃用的 DeferredCommand.

Edited and updated with new GWT class instead of the deprecated DeferredCommand.

这篇关于GWT 中的线程(客户端)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆