开发者

Can I create an object only used by each Thread in JNI?

开发者 https://www.devze.com 2023-03-28 12:04 出处:网络
In Java I create some Threads, and they call the same native method like: public native String go(String str);

In Java I create some Threads, and they call the same native method like:

public native String go(String str);

In C Language, I have to make an object for each Thread, and the object is only used开发者_如何学Go by each Thread.

Global reference cannot be used because it's shared by all Threads.

I don't want to create the object each time I invoke the JNI method.

How can I implement this?


So you want thread-local Java objects at the JNI side? Just create a ThreadLocal and store it in a global reference.

0

精彩评论

暂无评论...
验证码 换一张
取 消