Scenario: Submit the form to server; the request will contain IDs of some tasks. At the server side (servlet) get the task IDs from the request and then run each task in a separate thread and return the chunked response whenever a thread is completed.
场景:将表单提交给服务器;请求将包含某些任务的ID。在服务器端(servlet)从请求中获取任务ID,然后在单独的线程中运行每个任务,并在线程完成时返回分块响应。
Suppose we have 10 threads running, for whichever thread is complete, the execution needs to return the status to browser.
假设我们有10个线程在运行,无论哪个线程完成,执行都需要将状态返回给浏览器。
Could you please suggest the logic?
你能建议逻辑吗?
1 个解决方案
#1
1
I suggest you take the time to integrate a push solution like Spring, Cometd, Atmosphere or whatever you like.
我建议你花点时间整合像Spring,Cometd,Atmosphere或任何你喜欢的推送解决方案。
Otherwise, the simplest approach that gets you up & running in a minute without learning and integrating anything new is the polling one. You need:
否则,最简单的方法是在不学习和整合任何新内容的情况下让您在一分钟内启动并运行,这是一种轮询方法。你需要:
- A servlet to gather input, submit the task to the pool of executors and return the task ID
- A pool of executors
- A servlet that, given a task ID, returns its status - like pending, aborted, succeeded
- A Javascript client that polls the preceding servlet until the work is done (or a timeout expires?)
用于收集输入的servlet,将任务提交到执行程序池并返回任务ID
执行者池
给定任务ID的servlet返回其状态 - 如pending,aborted,success
一个Javascript客户端轮询前面的servlet,直到工作完成(或超时到期?)
#1
1
I suggest you take the time to integrate a push solution like Spring, Cometd, Atmosphere or whatever you like.
我建议你花点时间整合像Spring,Cometd,Atmosphere或任何你喜欢的推送解决方案。
Otherwise, the simplest approach that gets you up & running in a minute without learning and integrating anything new is the polling one. You need:
否则,最简单的方法是在不学习和整合任何新内容的情况下让您在一分钟内启动并运行,这是一种轮询方法。你需要:
- A servlet to gather input, submit the task to the pool of executors and return the task ID
- A pool of executors
- A servlet that, given a task ID, returns its status - like pending, aborted, succeeded
- A Javascript client that polls the preceding servlet until the work is done (or a timeout expires?)
用于收集输入的servlet,将任务提交到执行程序池并返回任务ID
执行者池
给定任务ID的servlet返回其状态 - 如pending,aborted,success
一个Javascript客户端轮询前面的servlet,直到工作完成(或超时到期?)