为什么我要在并行流中使用并发特性和collect:
List<Integer> list =
Collections.synchronizedList(new ArrayList<>(Arrays.asList(1, 2, 4)));
Map<Integer, Integer> collect = list.stream().parallel()
.collect(Collectors.toConcurrentMap(k -> k, v -> v, (c, c2) -> c + c2));
Run Code Online (Sandbox Code Playgroud)
并不是:
Map<Integer, Integer> collect = list.stream().parallel()
.collect(Collectors.toMap(k -> k, v -> v, (c, c2) -> c + c2));
Run Code Online (Sandbox Code Playgroud)
换句话说,不使用此特性会产生什么副作用,它对内部流操作有用吗?
为什么方法中的累加器参数是Stream::reduce
a BiFunction
而不是BinaryOperator
像combiner参数一样.
为什么是它的类型 BiFunction<U, ? super T, U>
?为什么T
?应该是BiFunction<U, ? extends U, U>
吗?
我有一个带有 where 子句的 SQL 查询,我已经为 where 子句中使用的列创建了索引。如何检查查询是否使用这些列的索引?
我正在使用 JDK 11 和 Spring Boot。我正在实现一个 REST API,有 3 层:
我在数据访问层有针对接口的类,并且在服务层没有任何接口。
我使用 MockMvc、Mockito 等编写集成测试,以测试控制器公开的每个点的整个路径。直到我尝试在服务层引入接口,这才成为问题。
最初,我只嘲笑存储库/Daos。所以类结构如下:
public interface ClientRepo{
......
}
public class ClientRepoImpl implements ClientRepo{
......
}
Run Code Online (Sandbox Code Playgroud)
将返回的数据模拟为:
@MockBean
private ClientRepo client;
....
Mockito.when(client.isExistFkUnitId(Mockito.any(UUID.class))).thenReturn(false);
Run Code Online (Sandbox Code Playgroud)
到目前为止一切都很好。
现在我在服务层引入了接口:
public interface ClientService{
......
}
public class ClientServiceImpl implements ClientService{
......
}
Run Code Online (Sandbox Code Playgroud)
并尝试(尝试调用实际的服务方法):
@MockBean
private ClientService clientService;
....
Mockito.when(clientService.isExistFkUnitId(Mockito.any())).thenCallRealMethod();
Run Code Online (Sandbox Code Playgroud)
但始终只得到 null。
有没有办法让真正的方法调用保持接口不变?
java ×3
java-8 ×2
java-stream ×2
concurrency ×1
mockito ×1
mysql ×1
reduce ×1
spring ×1
spring-boot ×1
sql ×1