我很难与function toTimeZone(time, zone) {
var format = 'YYYY/MM/DD HH:mm:ss ZZ';
return moment(time, format).tz(zone).format(format);
}
进行交流:
HashMap<String, Future<DPSImporterServiceImpl>>
我的地图包含两个条目: for (Entry<String, Future<DPSImporterServiceImpl>> entry : map.entrySet()) {
logger.debug("Thread: " + entry.getKey() + "/"
+ entry.getValue());
Future<DPSImporterServiceImpl> fut = entry.getValue();
try {
DPSImporterServiceImpl imp = fut.get();
logger.debug("Waiting over for: " + imp.toString());
} catch (InterruptedException e) {
e.printStackTrace();
} catch (ExecutionException e) {
e.printStackTrace();
}
}
这是我的记录器结果:
{1435748953925=java.util.concurrent.FutureTask@705f23aa, 1435748971395=java.util.concurrent.FutureTask@761ea788}
正如您所见,地图被正确迭代,因为以Thread: 1435748953925/java.util.concurrent.FutureTask@705f23aa
Waiting over for: Thread busy with 1435748971395.
Thread: 1435748971395/java.util.concurrent.FutureTask@761ea788
Waiting over for: Thread busy with 1435748971395.
开头的日志语句是地图中的日志语句。
Thread...
方法虽然无法正常工作,因为它显然是从同一个对象调用的(两个时间来自第二个带有键get()
的条目)。
这对我来说很困惑,因为地图肯定不包含任何标识对象。
你能告诉我这里可能有什么问题吗?谢谢!
答案 0 :(得分:0)
嗯,以下代码段按预期工作:
Map<String, Future<String>> map = new HashMap<>();
ExecutorService service = new ScheduledThreadPoolExecutor(1);
Future<String> future1 = service.submit(() -> {
Thread.sleep(1000);
return "1";
});
Future<String> future2 = service.submit(() -> {
Thread.sleep(1000);
return "2";
});
map.put("1", future1);
map.put("2", future2);
for (Map.Entry<String, Future<String>> entry : map.entrySet()) {
System.out.println("Thread: " + entry.getKey() + "/" + entry.getValue());
Future<String> fut = entry.getValue();
try {
String imp = fut.get();
System.out.println("Waiting over for: " + imp);
} catch (InterruptedException | ExecutionException e) {
e.printStackTrace();
}
}
service.shutdown();
在我看来,问题可能出在DPSImporterServiceImpl或地图中这些期货的获取方式。