Expandir minha barra de realizações na Comunidade.

Submissions are now open for the 2026 Adobe Experience Maker Awards.

Mark Solution

Esta conversa foi bloqueada devido à inatividade. Crie uma nova publicação.

SOLUCIONADO

Handling InvalidItemStateException

Avatar

Level 3

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

1 Solução aceita

Avatar

Resposta correta de
Level 10

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.

Ver solução na publicação original

3 Respostas

Avatar

Employee

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

Avatar

Resposta correta de
Level 10

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.

Avatar

Employee Advisor

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