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

协程中不能用jvm->AttachCurrentThread吗 #317

Open
kamylee opened this issue Apr 12, 2023 · 2 comments
Open

协程中不能用jvm->AttachCurrentThread吗 #317

kamylee opened this issue Apr 12, 2023 · 2 comments

Comments

@kamylee
Copy link

kamylee commented Apr 12, 2023

我在ndk中的Native函数中成功的调用jvm->AttachCurrentThread(主线程)。可以正常的调用java的clashh方法。
也能在std::thread线程中成功获取:
std::thread nativeThread([B]() { // 将子线程附加到Java虚拟机上 JavaVM* pJvm = JniHelper::getJavaVM(); JNIEnv *envSub = nullptr; pJvm->AttachCurrentThread(&envSub, nullptr);
但是在http::Server().on_req(cb).start()中的cb函数中却无法获取,是协程不支持吗,无法获取线程ID造成的吗?

@idealvin
Copy link
Owner

http::Server 内部可能有多个线程,cb 可能被多个线程调用

@kamylee
Copy link
Author

kamylee commented Apr 13, 2023

那有没有解决方法啊?我实际上是把一个Http连接升级成了websocket。然后一直保持着连接(循环收发信息)。按理此时就只是一个线程来处理这个CB吧?有什么办法支持jvm->AttachCurrentThread吗?

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

2 participants