开发者

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

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜