小编Dan*_*Dan的帖子

Java ConcurrentHashMapcomputeIfAbsent() 方法是否支持基于键的“锁定”?

https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/ConcurrentHashMap.html#computeIfAbsent-K-java.util.function.Function-

假设我们有 10 个线程使用不同的键值调用以下代码。提供给computeIfAbsent方法的“Function”参数是否并行运行,或者computeIfAbsent将“锁定”整个表?

Map<String, String> map = new ConcurrentHashMap<>();
map.computeIfAbsent(key, K -> { // long time operation });
Run Code Online (Sandbox Code Playgroud)

java concurrenthashmap

5
推荐指数
1
解决办法
3317
查看次数

在 Elixir 世界中循环中间返回的替代方法是什么

我还是 Elixir 的新手。我正在尝试创建一个接受请求列表并处理每个请求的方法。如果全部通过则返回 {:ok, "success"} 或 {:error, error_reason} 如果失败则返回。

在其他语言中,我可以做这样的事情。假设流程函数返回 {:ok, "success"} 或 {:error, error_reason}。

def func(requests):
   for request in requests:
       if {:error, error_reason} <- process(request):
           return {:error, error_reason}

   return {:ok, "success"}
end
Run Code Online (Sandbox Code Playgroud)

在 Elixir 世界中这样做的正确方法是什么?

elixir

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

标签 统计

concurrenthashmap ×1

elixir ×1

java ×1