【发布时间】:2015-06-18 19:01:35
【问题描述】:
我有一个 web 服务 (cxf),它在每次调用耗时的方法时创建一个新线程,向客户端返回一个 ID,作为令牌传递给另一个 web 方法以检查该特定线程的执行状态:
public String doWork(){
String id = /***randomnly generates an ID****/
executor.execute(**some runnable**);
// need to save the guy above
return id;
}
public String checkStatus(String id){
/* Here I would basically access to an hashmap
of tasks, pick the one identified by that ID
and check its state */
}
正如您在上面看到的,我的问题是保留对任务的引用,以便我可以跟踪其执行情况。我想出的想法如下:
@Webservice
public class MyService{
private static HashMap<String, Future> futures = new HashMap<String,Future>();
但是有更好的方法吗?此外,这种选择可能存在哪些缺点?
【问题讨论】: