One possibility is to use two-step switch.
Imagine you need to perform a maintenance task during which users should not be able to access the database.
You start by changing a flag in a database. This flag is not a maintenance mode flag, but indicates that clients should not use the database any longer since it will soon be put into maintenance mode.
The value of this flag can be cached for, say, five minutes to avoid repeatedly querying the database.
Five minutes later, you start the actual maintenance task.
You're now sure that everyone got their cache invalidated, so either the client already queried for the flag and know that the database is about to go into maintenance mode, or will necessarily query for this value before doing any other queries.
- You should need to wait for several minutes (five in my example) before performing the maintenance task. This is OK if this is a scheduled task or something which can be planned, but would be a problem for maintenance tasks which should be performed as soon as possible, such as changes to configuration related to a newly discovered security issue or measures used to prevent an ongoing attack.
If it is necessarily to be able to perform maintenance tasks quickly without additional planning (see Cons above), you may need to implement a two-ways connection which makes it possible for you—the service provider—to push a message to your clients, notifying them that the service will be switched to maintenance mode.
Although this sort of communication becomes more and more popular for web applications with the support of Web sockets by all major browsers, if I understand well, you're dealing with desktop applications. If Java ecosystem doesn't have a similar technology for desktop apps (I'm pretty sure it does) or if for some reason you can't use it, you may be interested in legacy techniques used in web apps, such as long polling. You may read about those techniques on Comet page, especially how they affect bandwidth and what side effects they have.
- You can perform maintenance task nearly immediately while knowing that the clients are informed that you have switched to maintenance mode.
- Those techniques may be difficult to implement correctly (for example, how would you handle the case where you sent a message to a client, but the client neither haven't responded, nor dropped the connection?)