You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@dubbo.apache.org by "xcorpio (GitHub)" <gi...@apache.org> on 2019/01/11 10:39:10 UTC

[GitHub] [incubator-dubbo] xcorpio opened issue #3204: 通过 API 编程进行泛化调用时如何销毁Consumer(ReferenceConfig)所关联的线程池

Dubbo 版本:2.6.5

示例代码:https://github.com/apache/incubator-dubbo-samples/blob/master/dubbo-samples-generic/src/main/java/org/apache/dubbo/samples/generic/APIGenericConsumer.java

调用:`com.alibaba.dubbo.config.ReferenceConfig.destroy()` 后
```
HelloService helloService = (HelloService) reference2.get();
String result = helloService.hello("community");
reference2.destroy();
```
这个 `ReferenceConfig` 所关联的线程并没有退出,如图:
<img width="971" alt="2019-01-11 6 33 50" src="https://user-images.githubusercontent.com/4575409/51028847-a14b7000-15cf-11e9-8ee7-467792d7b3ae.png">

有什么显示的办法可以让`ReferenceConfig`所持有的资源(线程,链接...)释放。

[ Full content available at: https://github.com/apache/incubator-dubbo/issues/3204 ]
This message was relayed via gitbox.apache.org for notifications@dubbo.apache.org

[GitHub] [incubator-dubbo] manzhizhen commented on issue #3204: 通过 API 编程进行泛化调用后如何销毁Consumer(ReferenceConfig)所关联的线程

Posted by "manzhizhen (GitHub)" <gi...@apache.org>.
@xcorpio 

In fact, I think you are worried that the thread should not be destroyed, but should it be a long link? The link of the generalization call is saved in the ReferenceConfig. Like the scenario of the gateway, the ReferenceConfig needs to be cached. We can manage the ReferenceConfig in the LRU mode to prevent the long connection maintained by the gateway from being too much. When destroying, directly the ReferenceConfig.destory () can be, I hope to help you.

其实我认为你担心应该不是线程有没有被销毁,而应该是长链接吧?泛化调用的链接是在ReferenceConfig中保存的,像网关这种场景,ReferenceConfig是需要缓存的,我们可以将ReferenceConfig以LRU的方式管理起来,以防止网关维护的长连接过多,销毁时直接ReferenceConfig.destory()即可,希望对你有帮助。


[ Full content available at: https://github.com/apache/incubator-dubbo/issues/3204 ]
This message was relayed via gitbox.apache.org for notifications@dubbo.apache.org

[GitHub] [incubator-dubbo] zonghaishang commented on issue #3204: 通过 API 编程进行泛化调用后如何销毁Consumer(ReferenceConfig)所关联的线程

Posted by "zonghaishang (GitHub)" <gi...@apache.org>.
有些线程确认不会被销毁,jvm退出会自动销毁,因为线程池是static共享的,不会因为ReferenceConfig多就产生更多线程

[ Full content available at: https://github.com/apache/incubator-dubbo/issues/3204 ]
This message was relayed via gitbox.apache.org for notifications@dubbo.apache.org

[GitHub] [incubator-dubbo] tswstarplanet commented on issue #3204: 通过 API 编程进行泛化调用后如何销毁Consumer(ReferenceConfig)所关联的线程

Posted by "tswstarplanet (GitHub)" <gi...@apache.org>.
java又不是c++,不存在显示销毁一个对象这种说法。你定义一个对象,当它脱离了引用链,就有可能被gc回收。线程Thread对象也不例外

[ Full content available at: https://github.com/apache/incubator-dubbo/issues/3204 ]
This message was relayed via gitbox.apache.org for notifications@dubbo.apache.org

[GitHub] [incubator-dubbo] zonghaishang commented on issue #3204: 通过 API 编程进行泛化调用后如何销毁Consumer(ReferenceConfig)所关联的线程

Posted by "zonghaishang (GitHub)" <gi...@apache.org>.
Close first, reopen if there is a problem

[ Full content available at: https://github.com/apache/incubator-dubbo/issues/3204 ]
This message was relayed via gitbox.apache.org for notifications@dubbo.apache.org


[GitHub] [incubator-dubbo] tswstarplanet commented on issue #3204: 通过 API 编程进行泛化调用后如何销毁Consumer(ReferenceConfig)所关联的线程

Posted by "tswstarplanet (GitHub)" <gi...@apache.org>.
java又不是c++,不存在显式销毁一个对象这种说法。你定义一个对象,当它脱离了引用链,就有可能被gc回收。线程Thread对象也不例外,当你定义一个Thread对象,当它运行完了,并且脱离了引用链就会被销毁了。线程池里的Thread被创建出来,只要不超过core size就会一直被线程池对象持有,所以不会被gc

[ Full content available at: https://github.com/apache/incubator-dubbo/issues/3204 ]
This message was relayed via gitbox.apache.org for notifications@dubbo.apache.org

[GitHub] [incubator-dubbo] tswstarplanet commented on issue #3204: 通过 API 编程进行泛化调用后如何销毁Consumer(ReferenceConfig)所关联的线程

Posted by "tswstarplanet (GitHub)" <gi...@apache.org>.
I think Dubbo use thread pool to execute an RPC invoke, when the invoke ends, the threads of thread pool does not exit because it is used to execute following RPC invokes.

[ Full content available at: https://github.com/apache/incubator-dubbo/issues/3204 ]
This message was relayed via gitbox.apache.org for notifications@dubbo.apache.org


[GitHub] [incubator-dubbo] zonghaishang closed issue #3204: 通过 API 编程进行泛化调用后如何销毁Consumer(ReferenceConfig)所关联的线程

Posted by "zonghaishang (GitHub)" <gi...@apache.org>.
[ issue closed by zonghaishang ]

[ Full content available at: https://github.com/apache/incubator-dubbo/issues/3204 ]
This message was relayed via gitbox.apache.org for notifications@dubbo.apache.org


[GitHub] [incubator-dubbo] wuwenhui0917 commented on issue #3204: 通过 API 编程进行泛化调用后如何销毁Consumer(ReferenceConfig)所关联的线程

Posted by "wuwenhui0917 (GitHub)" <gi...@apache.org>.
这些是连接导致的(长连接)ReferenceConfig里面调用使用的的是代理(里面有负载均衡计算哪个服务端链接(与服务端的长连接保持)

@xcorpio  
manzhizhen 说的很对

[ Full content available at: https://github.com/apache/incubator-dubbo/issues/3204 ]
This message was relayed via gitbox.apache.org for notifications@dubbo.apache.org

[GitHub] [incubator-dubbo] xcorpio commented on issue #3204: 通过 API 编程进行泛化调用后如何销毁Consumer(ReferenceConfig)所关联的线程

Posted by "xcorpio (GitHub)" <gi...@apache.org>.
> I think Dubbo use thread pool to execute an RPC invoke, when the invoke ends, the threads of thread pool does not exit because it is used to execute following RPC invokes.

没问题,我想要一种可以显示释放线程池的方法,但调用 `destroy` 没效果,想知道其他有什么方法。我的应用场景是类似做一个Dubbo的代理网关(测试用),假设我们公司有1K+个Dubbo服务,每个创建一个`ReferenceConfig` ,这样如果没有释放关联线程的机制会很伤.

[ Full content available at: https://github.com/apache/incubator-dubbo/issues/3204 ]
This message was relayed via gitbox.apache.org for notifications@dubbo.apache.org