简体   繁体   English

来自客户端的Java SE异步调用

[英]Java SE asynchrous call from client

I have the following problem: 我有以下问题:

I have a list of elements on the client side and am supposed to send them to the server one by one, through the same port, but not block the client while waiting for the server to respond. 我在客户端有一个元素列表,应该通过相同的端口将它们一个一个地发送到服务器,但是在等待服务器响应时不阻止客户端。

I have been going through various posts on here as well as JAVA SE documentation, but am not sure I have found the answer. 我一直在浏览这里的各种帖子以及JAVA SE文档,但不确定是否找到了答案。 I thought I could start a new Callable for each request, but have been unable to find a non-blocking way to send and receive those messages. 我以为可以为每个请求启动一个新的Callable,但是一直找不到发送和接收这些消息的非阻塞方式。

From what I read, using Sockets and Output/Input streams would result in blocking, please correct me if I'm wrong. 根据我的阅读,使用套接字和输出/输入流会导致阻塞,如果我错了,请纠正我。

I by no means expect a full solution, but any pointers on where to look at would be greatly appreciated. 我绝不会期望一个完整的解决方案,但是任何关于在哪里查看的指示都将不胜感激。

You can implement these asynchronous calls using the non-blocking APIs NIO AND NIO.2. 您可以使用非阻塞API NIO和NIO.2实现这些异步调用。 Theres is a great article about it on javaworld.com: 在javaworld.com上有一篇很棒的文章:

http://www.javaworld.com/article/2853780/core-java/socket-programming-for-scalable-systems.html http://www.javaworld.com/article/2853780/core-java/socket-programming-for-scalable-systems.html

I don't know if you have this option, but you can also implement this on a higher level using HTTP services. 我不知道您是否具有此选项,但是您也可以使用HTTP服务在更高级别上实现此选项。 Once I answered a question like this for web services. 一旦我回答了这样的Web服务问题。 You can take a look here: 您可以在这里看看:

Asynchronous call from java web service to .net application 从Java Web服务到.net应用程序的异步调用

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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