据我所知.stream(),我可以使用链操作.filter()或使用并行流.但是如果我需要执行小操作(例如,打印列表的元素),它们之间的区别是什么?
collection.stream().forEach(System.out::println);
collection.forEach(System.out::println);
Run Code Online (Sandbox Code Playgroud) 我尝试使用parallelStream()带有Spring @Transactional注释的DAO 并得到这样的问题:
@Transactional
public void processCollection(Collection<Object> objects) {
objects.parallelStream()
.forEach(this::processOne); //throw exception
}
@Transactional
public void processOne(Object o) {
...
}
Run Code Online (Sandbox Code Playgroud)
工作正确:
@Transactional
public void processCollection(Collection<Object> objects) {
objects.stream()
.forEach(this::processOne); //work correctly
}
@Transactional
public void processOne(Object o) {
...
}
Run Code Online (Sandbox Code Playgroud)
例外:
org.hibernate.HibernateException: No Session found for current thread
org.springframework.orm.hibernate4.SpringSessionContext.currentSession(SpringSessionContext.java:106)
org.hibernate.internal.SessionFactoryImpl.getCurrentSession(SessionFactoryImpl.java:978)
Run Code Online (Sandbox Code Playgroud)
我如何使用带@Transactional注释的方法parallelStream()?
更新 为什么会发生这种情况Spring事务管理器和多线程 但是我希望Spring 4支持java 8可以为此提供一些解决方案.有任何想法吗?
我想尝试一些在运行时需要参数名称的框架功能,所以我需要编译我的应用程序,-parameters它将在JVM字节代码中存储参数的名称.
除了jar/war的大小之外,这个参数用法存在哪些缺点?