Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SWIG 回调Java每次都创建新线程 #1

Open
GazitGu opened this issue May 24, 2019 · 3 comments
Open

SWIG 回调Java每次都创建新线程 #1

GazitGu opened this issue May 24, 2019 · 3 comments

Comments

@GazitGu
Copy link

GazitGu commented May 24, 2019

示例跑的的就是自带demo,加了Auth验证,用的6.3.13二合一办测试的,6.3.15也一样,如下log所示,每次回调都会创建新线程,请问有什么好办法解决么?
Thread-0: On Trade Front Connected
Send auth ok
Thread-1:Auth success, continue do login.
Send login ok
Thread-2:Login ErrorID[3] ErrMsg[CTP:不合法的登录]
Thread-3:On MD Front Connected
Thread-4:Brokerid[]

@yellow013
Copy link

我之前也发现了每次回调使用新线程的问题。这个似乎是无解的,因为回调是由jni调用的,每次会new一个线程,还没找到怎么能让jni回调使用线程池的方法。jvm会回收生命周期结束的线程实例,不用担心这个问题导致jvm堆溢出,性能肯定是有影响的,但一般量化足够用,做高频不用考虑jni调用。

@nicai0609
Copy link
Owner

nicai0609 commented Sep 2, 2019

这是swig的封装的机制,查阅资料发现swig有宏定义支持不生成新线程回调:
%insert("runtime") %{ #define SWIG_JAVA_ATTACH_CURRENT_THREAD_AS_DAEMON #define SWIG_JAVA_NO_DETACH_CURRENT_THREAD %}
但经过群友测试反馈发现并不好,有时线程增长剧烈也无法释放。而且这样线程的生成和释放在一般高频下也够用,不需要考虑这个的延时。真正的高频建议还是直接用c++。
当然,如果发现有别的更好的方法能解决这个问题,欢迎讨论。

@reanghect
Copy link

找到了一个解决办法,还没测试过,供大家参考。https://www.cnblogs.com/bjguanmu/p/12582258.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants