0

Directly from this documentation:

In a multithreaded application, attribute changes may occur simultaneously. There is no requirement for the servlet container to synchronize the resulting notifications; the listener classes themselves are responsible for maintaining data integrity in such a situation.

As far as I know all or most applications are multithreaded since the web server creates a new thread for each client's request. The paragraph is just saying that if there are some shared writable resources we need to synchronized right?

Thanks in advance.

Rollerball
  • 12,618
  • 23
  • 92
  • 161

1 Answers1

0

Depends on the frequency of attribute changes and if the writable resources can have an undesired state.
If two notifications arrive at the listener at about the same time, synchronized does not guarantee the order in which the notifications are processed by the listener (see this answer). That could cause the writable resources to reach an undesired state (e.g. a remove is processed before an add). In that case you will need something like a fair lock which comes at a price: the listener will process less notifications in a given time. If that is a problem, you can try to make the writable resources themselves thread-safe, e.g. using a ConcurrentHashMap.

Community
  • 1
  • 1
vanOekel
  • 6,358
  • 1
  • 21
  • 56