Sounds like a task for WebSockets . This is part of Java EE 7, so Glassfish should be one of the first ASs to support it.
You can use @PostUpdate and @PostPersist to intercept database @PostPersist . Here is the question link.
There are many ways to do the so-called server push to notify connected clients:
EDIT: There are several frameworks in the Java world in which server push (reverse ajax) is implemented out of the box. If you are familiar with GWT , I would suggest Errai . Another alternative is Atmospere . The drawback of Atmospere is the fact that it requires a standalone launch next to your regular application server with your web application. I played with him a year ago, so this may have been changed since then.
In general, it is difficult to provide you with a specific piece of code, because it depends on the structure you choose. I am familiar with Errai , here is an example:
Server side:
@ApplicationScoped public class TickerService { @Inject private Event<Tick> tickEvent; private void sendTick() { tickEvent.fire(new Tick()); } }
Client side:
@EntryPoint public class TickerClient { public void tickHappened(@Observes Tick tick) {
Other advantages of using Errai are CDI on the server and on the finished client, another thing that is good is the use of web sockets under covers if it is supported and returns to other solutions otherwise.
No matter what you choose, it should match your existing infrastructure and client-side user interface.
Jiri kremser
source share