Assume, we have a web app whose servlets make certain decisions based on the value from some status variable existing on the application level. The servlets themselves may change (update) the status value while processing users requests. Also, there is an interceptor filter, who reads current status upon each request and redirects users to the maintenance page thus temporarily blocking access to the application when it's needed.
The first obvious solution could be using context scoped status attribute, but as far as I understand, context scoped attributes are rarely updated and typically serve as a storage on the application level for the stuff that is loaded once (for example, by ServletContextListener) and then can be shared by servlets mostly for the reading. The classic example of that is DataSoruce object (like JNDI DataSource in Tomcat who allows connection pooling).
However, in a situation described above where the application variable is updated on the relatively regular basis, such strategy seem to be not very good really, since it would inevitably involve a lot of messing up with synchronized blocks or methods to guarantee that no two (or more) servltes may update the status simultaneously at the same moment because, as we know, each servlet runs in a separate thread. To make matters worse, I don't fully understand how to control synchronization in JSP while using EL/JSTL (or should I write a custom tag class for synchronized context scoped attributes reading and setting in JSP).
So, again, the question is: what could be an alternative to context scoped updatable attributes? Maybe using synchronized collections or concurrent maps, database transactions with proper isolation level for storing attributes values?
P.S.
The systematic short overview of the possible strategies with brief pros and cons would be much appreciated.