【问题标题】:Is it necessary to close JAX-WS port?是否需要关闭 JAX-WS 端口?
【发布时间】:2011-04-17 22:49:52
【问题描述】:

在某些教程中(例如hereherehere)建议通过将其转换为 com.sun.xml.ws.Closeable 来关闭 JAX-WS 端口,例如

MyPortType port = MyService.getMyPort();
... do some operations on WS proxy ...
((com.sun.xml.ws.Closeable) port).close();

这种方法不适用于JaxWsPortProxyFactoryBean 返回的代理,因为它只建议目标 WS 接口和javax.xml.ws.BindingProvider

所以我的问题是:是否有必要关闭端口(考虑到它可以在应用程序中重复使用)?如果关闭端口更好(并且可能取消它?),如何正确组织端口的生命周期(通过实现创建的 Spring 代理将始终是单例)?

【问题讨论】:

    标签: spring jax-ws


    【解决方案1】:

    com.sun.xml.ws.Closeable 的 JavaDoc 内容如下:

    This signals the implementation of certain specs (like WS-ReliableMessaging and
    WS-SecureConversation) to terminate sessions that they create during the life
    time of a proxy object. This is not a mandatory operation, so the application
    does not have to call this method.
    

    还有Closing WSIT Reliable Messaging Connections 注释:

    Calling close() method provides a way for WSIT components, such as Reliable
    Messaging and Secure Conversations to do clean-up activities related to client
    instance. Sometimes calling close() can be avoided without harmful effects.
    

    【讨论】:

      【解决方案2】:

      不,我不认为这是必要的。由 JAX-WS 子系统管理自己的生命周期,端口不需要关闭。

      如果您查看源代码,这与JaxWsPortProxyFactoryBean 的行为一致。它不会尝试在上下文关闭时对端口做任何事情,而 Spring FactoryBeans 通常会这样做。

      【讨论】:

      • 感谢您的回复。浏览更多之后,我发现了更多提示。如果您能说出关闭代理的副作用是什么,那就太好了。
      • @dma_k:据我所知,没有。
      猜你喜欢
      • 1970-01-01
      • 2012-12-28
      • 1970-01-01
      • 2010-12-04
      • 1970-01-01
      • 1970-01-01
      • 2012-08-13
      • 2018-07-24
      • 1970-01-01
      相关资源
      最近更新 更多