简体   繁体   中英

How to handle an asynchronous response in a java library?

I am developing a library which sends an asynchronous request to a server (in another thread).

Our clients will use this library, and I am thinking of the best way how to get this handled by them. The response might follow in seconds to a minute. I am doing this using the jersey-client and there already exists a listener which will be called in the other "async" thread.

So I have a shared ressource which will be "filled" with the response by the listener, but the main-thread has to call it to retrieve the response.

Is there a better way how the client might access or be "notified" that the response has arrived? Something like an EventNotifier? (If i implement something like this, shouldn't there exist something like polling on the notifier, but this means that there might exist another thread, which has to do this).

I have no influence on the client who is using my library, I can only make their life easier with an appropriate design of the library-functions they call.

What is the servlet container version you are trying to use ? Servlet 3.0 has builtin support for it

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM