你能在x秒后让rpc调用超时吗?
如果我有一个进行 RPC 调用的服务(比如 Web 服务、restful 服务,或者只是从 url 中抓取数据等),我是否可以让它在 5 秒后超时?
我不希望它在远程服务关闭时挂起然后崩溃,而是尝试 x 秒,如果它关闭,然后继续下一个远程服务调用。
If I have a service that makes RPC calls (say to web services, or restful services, or just to scrape data from a url, etc), is it possible for me to have it timeout after 5 seconds?
I don't want it to hang and then crash if the remote service is down, rather try for x seconds, if its down, then just carry on to the next remote service call.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
我认为 GWT 的以下链接会有所帮助:
http://code.google.com/webtoolkit/doc/latest/DevGuideCodingBasicsDelayed.html
I think the following link from GWT will be helpful:
http://code.google.com/webtoolkit/doc/latest/DevGuideCodingBasicsDelayed.html
如果它是一个独立的应用程序,那么您可以使用操作系统来安排它(例如 Windows 中的任务计划程序)。如果不是独立的,那么可以将其做成Java Task,使用Java的Timer来调度。
看看 Java.util.Timer
这是一个例子
http://www.java2s.com/Code/Java/Development-类/UsejavautilTimertoscheduleatasktoexecuteonce5secondshavepassed.htm
If it's a stand-alone app then you can use the OS to schedule it (for example Task Scheduler in Windows). If it's not a stand-alone, then you can make it into a Java Task and use Java's Timer to schedule it.
Have a look a Java.util.Timer
and here is an example
http://www.java2s.com/Code/Java/Development-Class/UsejavautilTimertoscheduleatasktoexecuteonce5secondshavepassed.htm
RPC 的客户端库通常具有可选的超时参数。如果请求未在要求的时间内完成,客户端库将简单地关闭连接。这些协议本身可能没有关于超时的内容。
你的 RPC 课程学得怎么样?你正在使用什么库?
Client libraries for RPC usually have optional timeout parameter available. If the request is not finished in required time, the client library simply closes the connection. There is probably nothing about timeouts in those protocols themselves.
How are you doing your RPC class? What libs you are using?
您使用什么协议?是http还是RMI?最好的方法是在连接通道(如 Socket)上实现超时。如果这是您想做的事情,请查看 http://download.oracle.com/javase/1.5.0/docs/guide/net/properties.html
What protocol are you using? It is http or RMI? The best way will be to implement timeout on the connection channel (like Socket). If this is something you want to do take a look at http://download.oracle.com/javase/1.5.0/docs/guide/net/properties.html
如果您使用 Apache HTTP 组件,请执行以下操作:
If you use Apache HTTP Components then do this: