Java .parallelStream() with spring annotated methods

后端 未结 2 819
南方客
南方客 2021-02-05 12:04

I try using the parallelStream() in DAO with Spring @Transactional annotations and get so problem:

@Transactional
public void processCo         


        
2条回答
  •  抹茶落季
    2021-02-05 12:23

    The problem is not with parallel stream .In spring transaction is created using AOP.
    When your processCollection method is executed spring create a proxy object of this and transaction is started. Calling anyother method in same class ,spring will not run that method in New transaction even if you specified @Transaction . To get it run move that method process() to new service and then execute your problem.your program will work fine.

提交回复
热议问题