Handling InvalidItemStateException | Community
Skip to main content
Level 3
October 16, 2015
Solved

Handling InvalidItemStateException

  • October 16, 2015
  • 3 replies
  • 1644 views

According to the doc the sesion's save() method can throw InvalidItemStateException exception.

It means that some item that was modified in current session also was modified from other thread and already saved. The transient space of the session cannot be saved

The quesion is what is a best practice in such case? Some code would be really appriciated. I cannot find any examples

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by edubey

Hi,

Whenever you are performing some critical task, lets say scheduler will update few things, same time there can be some common java methods running, I would suggest you can implement design patterns example Singleton design pattern can give good results with session as it will never allow multiple objects to execute and modify.

Somewhat it also depends upon what exactly is the requirement. When ever you makes some changes you can use session.save() in case when you know that another thread is roaming around.

3 replies

Adobe Employee
October 16, 2015

Hi,

my advice would be to find out why two threads are trying to modify the same resource. There may be an issue with the way your code base has been written, only then should you decide how to implement a solution in code. 

Is this for AEM5.x?

Regards,

Opkar

edubey
edubeyAccepted solution
Level 10
October 16, 2015

Hi,

Whenever you are performing some critical task, lets say scheduler will update few things, same time there can be some common java methods running, I would suggest you can implement design patterns example Singleton design pattern can give good results with session as it will never allow multiple objects to execute and modify.

Somewhat it also depends upon what exactly is the requirement. When ever you makes some changes you can use session.save() in case when you know that another thread is roaming around.

joerghoh
Adobe Employee
Adobe Employee
October 16, 2015

Hi,

if you get that exception, you can handle it programatically like this:

  • call session.refresh(true) and retry the session.save() again
  • in case it doesn't work, you can call session.refresh(false) to discard your changes, try to execute your operations and then call session.save().

kind regards,
Jörg