草庐IT

concurrent-collections

全部标签

java - WeakHashMap 是否有 java.util.concurrent 等价物?

是否可以不使用Collections.synchronizedMap()重写以下代码,同时在并发时保持正确性?Collections.synchronizedMap(newWeakHashMap());即java.util.concurrent有什么可以代替的吗?请注意,仅替换为newConcurrentHashMap(newWeakHashMap()));显然不行 最佳答案 Guava的CacheBuilder类可以让你轻松做到这一点。CacheBuilder.newBuilder().weakKeys().build()请注意,

java - WeakHashMap 是否有 java.util.concurrent 等价物?

是否可以不使用Collections.synchronizedMap()重写以下代码,同时在并发时保持正确性?Collections.synchronizedMap(newWeakHashMap());即java.util.concurrent有什么可以代替的吗?请注意,仅替换为newConcurrentHashMap(newWeakHashMap()));显然不行 最佳答案 Guava的CacheBuilder类可以让你轻松做到这一点。CacheBuilder.newBuilder().weakKeys().build()请注意,

java - SingleThreadExecutor 中 java.util.concurrent.RejectedExecutionException 的可能原因是什么

我在单例中创建了以下执行器:finalprivateExecutorServiceexecutor=Executors.newSingleThreadExecutor(newThreadFactory(){finalThreadFactorydelegate=Executors.defaultThreadFactory();publicThreadnewThread(RunnableparamAnonymousRunnable){ThreadlocalThread=this.delegate.newThread(paramAnonymousRunnable);localThread.s

java - SingleThreadExecutor 中 java.util.concurrent.RejectedExecutionException 的可能原因是什么

我在单例中创建了以下执行器:finalprivateExecutorServiceexecutor=Executors.newSingleThreadExecutor(newThreadFactory(){finalThreadFactorydelegate=Executors.defaultThreadFactory();publicThreadnewThread(RunnableparamAnonymousRunnable){ThreadlocalThread=this.delegate.newThread(paramAnonymousRunnable);localThread.s

java - google 的 ImmutableList 和 Collections.unmodifiableList() 有什么区别?

来自ImmutableListjavadocs:UnlikeCollections.unmodifiableList(java.util.List),whichisaviewofaseparatecollectionthatcanstillchange,aninstanceofImmutableListcontainsitsownprivatedataandwillneverchange.ImmutableListisconvenientforpublicstaticfinallists("constantlists")andalsoletsyoueasilymakea"defensi

java - google 的 ImmutableList 和 Collections.unmodifiableList() 有什么区别?

来自ImmutableListjavadocs:UnlikeCollections.unmodifiableList(java.util.List),whichisaviewofaseparatecollectionthatcanstillchange,aninstanceofImmutableListcontainsitsownprivatedataandwillneverchange.ImmutableListisconvenientforpublicstaticfinallists("constantlists")andalsoletsyoueasilymakea"defensi

java - 是否有一个 Hamcrest "for each"Matcher 断言 Collection 或 Iterable 的所有元素都匹配单个特定的 Matcher?

给定一个Collection或Iterable项目,是否有任何Matcher(或匹配器组合)可以断言每个项目都匹配一个匹配器?例如,给定这个项目类型:publicinterfacePerson{publicStringgetGender();}我想写一个断言,即Person集合中的所有项目都具有特定的gender值。我在想这样的事情:Iterablepeople=...;assertThat(people,each(hasProperty("gender","Male")));有什么方法可以在不自己编写each匹配器的情况下做到这一点? 最佳答案

java - 是否有一个 Hamcrest "for each"Matcher 断言 Collection 或 Iterable 的所有元素都匹配单个特定的 Matcher?

给定一个Collection或Iterable项目,是否有任何Matcher(或匹配器组合)可以断言每个项目都匹配一个匹配器?例如,给定这个项目类型:publicinterfacePerson{publicStringgetGender();}我想写一个断言,即Person集合中的所有项目都具有特定的gender值。我在想这样的事情:Iterablepeople=...;assertThat(people,each(hasProperty("gender","Male")));有什么方法可以在不自己编写each匹配器的情况下做到这一点? 最佳答案

java - 有没有一种优雅的方法可以在使用 Guava 转换 Collection 时删除空值?

我有一个关于在使用Google集合时简化某些集合处理代码的问题(更新:Guava)。我有一堆“计算机”对象,我想以它们的“资源id”集合结束。这样做是这样的:CollectionmatchingComputers=findComputers();CollectionresourceIds=Lists.newArrayList(Iterables.transform(matchingComputers,newFunction(){publicStringapply(Computerfrom){returnfrom.getResourceId();}}));现在,getResourceId

java - 有没有一种优雅的方法可以在使用 Guava 转换 Collection 时删除空值?

我有一个关于在使用Google集合时简化某些集合处理代码的问题(更新:Guava)。我有一堆“计算机”对象,我想以它们的“资源id”集合结束。这样做是这样的:CollectionmatchingComputers=findComputers();CollectionresourceIds=Lists.newArrayList(Iterables.transform(matchingComputers,newFunction(){publicStringapply(Computerfrom){returnfrom.getResourceId();}}));现在,getResourceId