1

I have a scheduler in spring boot application, if I use @Transactional(propagation = Propagation.REQUIRES_NEW, rollbackFor = Exception.class) on scheduler method then it works well with only one database session but if I use @Transactional(propagation = Propagation.REQUIRES_NEW, rollbackFor = Exception.class) at DAO level or Service class level, four DAO's/Services based on data it will go to one of the DAO's, it reaching maxConnection limit 16 as we see in database sessions and its stucking/hanging without further process in java. what would be the problem.?

2
  • "what would be the problem.?" - "it reaching maxConnection limit 16"
    – Turing85
    Apr 15, 2021 at 19:39
  • Yes, it was reaching maxConnection limit and application stuck without doing anything.
    – Ramesh
    Apr 16, 2021 at 13:27

2 Answers 2

0

It really depends on the way you are calling the methods.

One test that I would ask you to do is this:

Add in the schedule method this:

@Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)

And then, at Service method, this:

@Transactional(propagation = Propagation.REQUIRES_NEW, rollbackFor = Exception.class)

This way, when the service method ends, it commits the transaction, but there is another transaction scope running in a higher level.

1
  • Thank you Sir, As per your suggestion it has only two sessions and its not increasing any more. Its working for me.
    – Ramesh
    Apr 15, 2021 at 21:04
0

Basically all the processing inside the scheduler method should be managed inside one transaction so the annotation should be on it (the first approach).

In the case you add this annotation in service/DAO methods, so for each method is called inside you caode a new transaction is created, which may explain the problem you are facing.

Finally no need to add "rollbackFor = Exception.class" because this is the default behavior.

1
  • Thank you for reply, yes removed rollback for
    – Ramesh
    Apr 15, 2021 at 21:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.