简体   繁体   中英

Caching a JNI varaible in Java

I am creating a Java server code that need to call native methods written by C. The C file will return values to Java. Now I need cache the values and also make it thread-safety as the server code support multiple threads. Static variable doesn't work to me as its value is shared by the threads. So how can I achieve it? Thanks.

Declare your native method with synchronized prefix to make sure the JNI call is thread-safe. For the cached purpose, you could use global reference or other general cache technique in JNI to cache the value.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM