Option 1 is the simplest, you can use asynchronous EJB methods there:
SERVER
@Asynchronous public Future<String> getUpdatedModel() { //here create blocking process until something interesting happen return new AsyncResult<String>("model has changed!"); }
CUSTOMER
Future<String> updatedModel = bean.getUpdatedModel(); while(true){ String response = updatedModel.get();
Option 2 looks like option 1, but you have to take care of marshaling objects, so don't worry when using a simple servlet.
Option 3 looks interesting, since Web sites will be included in Java EE7 (now you can use open source comet implementations for servlets). In my opinion, it is not intended for communication in corporate applications, but it may be good for your use. There are many JSON serializers available (e.g. gson), I use this kind of connection between JS and java and it works great.
Option 4 violates the basic principles of Java EE (opening your own sockets is prohibited) and I will prevent you from using it.
Option 5 Listen to Xie and use JMS! If you use the JMS theme, you can simply send a message when a specific event occurs and all connected clients will receive the message asynchronously. Naturally, Java EE is a way to solve such problems, without unnecessary transactions, delivery and storage of messages, if necessary.
source share