小编Cam*_*lla的帖子

我想将computeIfPresent和putIfAbsent都放入一个原子函数中

workObjectMap.computeIfPresent(key, (k,v) -> {
    v.memberIdSet.addAll(memberIdSet);
    v.memberPositionSet.addAll(memberPositionSet);
    return v;
});
// If it.remove() in run() is called at this point,
// there is a risk of the same work being done twice
workObjectMap.putIfAbsent(key, new WorkObjectValue(memberIdSet, memberPositionSet));
Run Code Online (Sandbox Code Playgroud)

我有上面的代码。在一个单独的线程中,我可能会从workObjectMap. 我想要一个原子函数,如果键存在,它会修改值,如果不存在,它会放置键/值。

在我当前的代码中,删除有可能发生在computeIfPresent和之间putIfAbsent,以便已添加到地图中的相同项目将再次添加。

如何阻止这两个方法调用之间的任何删除?(computeIfPresentputIfAbsent

java concurrency atomic concurrenthashmap java-8

6
推荐指数
1
解决办法
1067
查看次数

Yahoo YQL yahoo.finance.historicaldata返回空结果

上周,我已经使用此API开发和测试了。今天,我注意到即使从示例查询中也没有收到任何结果。

https://developer.yahoo.com/yql/console/?q=show%20tables&env=store://datatables.org/alltableswithkeys#h=select+Close+from+yahoo.finance.historicaldata+where+符号+%3D + %22EUR%3DX%22 + and + startDate +%3D +%222015-09-11%22 + and + endDate +%3D +%222017-03-10%22

https://query.yahooapis.com/v1/public/yql?q=select%20 *%20from%20yahoo.finance.historicaldata%20where%20symbol%20%3D%20%22YHOO%22%20and%20startDate%20 %3D%20%222009-09-11%22%20and%20endDate%20%3D%20%222010-03-10%22&diagnostics = true&env = store%3A%2F%2Fdatatables.org%2Falltableswithkeys

有人遇到这个吗?

yahoo-api yahoo-finance

4
推荐指数
1
解决办法
1691
查看次数