If I have a long waiting request (e.g. the thread handling it is blocked until another provides some data), then by the time the response is ready, the client could have disconnected. Is there a way to discover this in the method that handles the request? That is, not return the response and see jetty/jersey throw IO exceptions.
Share
You can’t tell a connection is down until you try sending something over the connection and it fails (throws
IOException).I’m storing a map of
LinkedBlockingDeques (mapped by the ID of the external system receiving the live stream) in a singleton EJB. When some event occurs that needs to be published to the live feed, I simply enqueue the event via that singleton bean. At the other end of the queue – if connected – is a JAX-RS web service waiting for an item to become available. Now, the reason I use a deque instead of a queue is that anIOExceptionmay be thrown while writing to and/or flushing theOutputStream, indicating that the client has most probably disconnected. The dequeue simply allows me to put back that item so that it will be the first to be taken the next time that external system connects.