I am developing restful services using resteasy for an application. This application has UI which will consume these rest services.

Now I am having a case where I have to do a server push to UI(Client). Across browsing over internet I see Websockets, atmosphere2.0, etc.., however I am wondering how I can capture all the audience using my application to do a server push to the UI.

Also I have to invalidate the connection or time out the user session if there is no activity detected for 30 min.

How can I achieve this?
I have heard of the observer pattern, not sure how it will help in my case.

1 Answer 1


The old way to do this was to use polling. If you can tolerate some time between the event and the UI seeing it, this might be the easiest way to do it. One thing you could use is a HEAD request on an events resource specific to the client.

If you truly need a push then you probably want to look at something like websockets. I would recommend you limit this to just the event notifications and use standard rest calls to get the data associated with the events.

I took me a little while but I remembered why I have some apprehension about recommending websockets or a similar push approach. The issue I found with websockets was that when everything is connected, it's great but you have to worry about what happens if the connection is dropped. With a polling, if the server is down for a minute or the network hiccups, it will just try again later. It's applicable to this issue for sure but I would make sure you need that level of complexity. I also tried it when it was really new so things could have been done to make it easier.

  • Doesn't polling creates unnecessary network calls though there is no server side event triggered. I want to notify UI(client) only if there is any event/change at the server side (services). Please let me know. Nov 16, 2016 at 20:32
  • 1
    Yes. Polling is a barbaric practice. It is completely inelegant. It's also super easy and robust. The question is whether the extra network calls are going to matter. For most APIs it won't. By using a HEAD request, (I mistakenly said OPTIONS before) you can limit the amount of data that get's transferred. The HEAD request would essentially respond with when the last update occurred. If that is earlier than the last time you pulled events, there's nothing new to get.
    – JimmyJames
    Nov 16, 2016 at 20:54
  • added some elaboration
    – JimmyJames
    Nov 17, 2016 at 14:39
  • I believe "comet" is the keyword for various techniques used for this (old ways).
    – uylmz
    Nov 17, 2016 at 14:45
  • @Reek IIRC comet was emulating websockets with polling but the newer versions of comet actually use websockets. It's a good call to search on this.
    – JimmyJames
    Nov 17, 2016 at 16:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.