简体   繁体   中英

Can you do asynchronous communications with Java and REST web services?

Can you do asynchronous communications with Java on a client that is consuming a REST web service that sometimes takes several minutes to return a value?

I think not, after reviewing the below. C# however does allow this

user1019776

Which way is preferred when doing asynchronous WCF calls? and WCF asynchronous callback

but do they apply to REST? Probably not.

Re client: How do you make a WCF Client asynchronous?

Answer: to handle asychronous WCF events,you make the client asynchronous via an Event method, see: http://msdn.microsoft.com/en-us/library/wewwczdw.aspx

(but make sure it is an Asychronous “fire and forget” event), see also this thread on Java (more of a Publisher/subscriber synchronous model: Does Java have native support for events, similar to that of C#? )

There are some many ways to send data to a TCP socket asynchronously, I don't know what type you are referring to. Can you clarify what you are trying to do and what doesn't work for you? What sort of service takes several minutes? Perhaps you should worry about fixing the service. – Peter Lawrey 8 hours ago FYI REST communications take a while on the handshake on the first call to establish a communication. Often 30 times longer than subsequent calls. This is well known. Thanks.

The answer to the question you asked is simply "yes, of course." Are you looking for how to do it inside a web container environment? Help with how to program a solution using only JavaSE? How to use Apache Async HttpClient? – Affe 8 hours ago * Affe, yes, that would be helpful. The client is an Android phone. Any links appreciated. *

You can do it with Java IO, NIO and NIO2 in different ways. Not to mention ways of doing it with various libraries. There are so many libraries to do this, it is hard to know which one to recommend. – Peter Lawrey 8 hours ago Please recommend one. Thanks.

Ok, Java doesn't have a thing called an "event" or a "delegate" However it supports asynchronous communication in various ways. – Peter Lawrey 8 hours ago how?

FWIW, WCF doesn't need to use SOAP. You can use other RESTful protocols under it. @PeterLawrey gives you the answer you need for Java. – ssamuel 7 hours ago I specifically asked for REST in my OP

** I want to thank the volunteers here at stackoverflow. Given that no money is being paid the service provided is outstanding. Thanks and I'll check this thread later for any subsequent replies. **

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