如何在GWT服务器端编码?
在GWT中,我将使用G图表在浏览器中呈现数据,在gwt服务器端我将需要一个线程来生成随机数据,其他线程将数据及时地呈现给客户端(浏览器),比如每2次之后秒(同步),我如何在服务器端编码? 任何形式的帮助都是值得赞赏的。 提前致谢
In GWT, I will use G chart to present data in the browser, in the gwt server side i will need one thread will generate random data, other threads will represent the data to the client(browser) in a timely manner say after every 2 sec(synchronously),How can i code in the server side ??
Any kind of help is appreciable..
Thanks in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在 GWT 的服务器端编写代码实际上与在没有 GWT 的情况下编写 java 代码完全相同。换句话说,一旦您掌握了客户端在 RemoteServiceServlet 实现中发送的数据,您就可以自由地使用任何 Java 代码、库和/或框架来处理该数据。
根据您的描述,听起来您需要启动另一个线程来生成随机数据,然后立即响应客户端。您可能想阅读有关在 java 中创建新线程的信息: http://download.oracle .com/javase/tutorial/essential/concurrency/。
有几个库可以使运行作业变得更容易。我熟悉
石英
。您可以使用像 quartz 这样的调度程序来调度一个在客户端请求时生成随机数据的作业?或者也许它可以经常生成随机数据?从客户端来看,您可能需要每 2 秒轮询一次以检查是否有新数据要显示。这是另一个线程,提供了一些从 gwt 轮询的选项:
GWT 中的客户端回调
Writing code in the server side of GWT is really exactly the same as writing java code without GWT. In other words, once you get a hold of the data that the client sent inside your implementation of
RemoteServiceServlet
, then you are free to use whatever java code, libs, and/or frameworks to process that data.From your description, it sounds like you need to kick off another thread to generate random data and then respond immediately to the client. You might want to read about creating new threads in java: http://download.oracle.com/javase/tutorial/essential/concurrency/.
There are several libraries that make it easier to run jobs. I'm familiar with
quartz
. You could use a scheduler like quartz to schedule a job that generates random data when the client requests? Or maybe it could just generate random data every so often?From the client side, you'll probably want to poll every 2 seconds to check whether there is new data to display. Here'a another thread that gives some options for polling from gwt:
Client side Callback in GWT