Are their value being changed from different Java threads which calls same native method?
Sure, the global variables will be shared by all virtual machine then by threads as well, let's write a very simple example to proof that:
counter.c
#include<stdio.h>
int counter = 0;
int incrementAndGet(){
counter++;
return counter;
}
Calling it in java using JNA
final ExecutorService executorService = Executors.newFixedThreadPool(5);
for (int i = 0; i < 20; i++) {
executorService.submit(() -> {
try {
TimeUnit.MILLISECONDS.sleep((long) (Math.random() * 1000));
} catch (InterruptedException e) {}
System.out.printf("thread=%s, counter=%d%n", Thread.currentThread().getName(), CounterLib.INSTANCE.incrementAndGet());
});
}
executorService.awaitTermination(10, TimeUnit.SECONDS);
executorService.shutdown();
output
thread=pool-1-thread-2, counter=1
thread=pool-1-thread-4, counter=2
thread=pool-1-thread-1, counter=3
thread=pool-1-thread-5, counter=4
thread=pool-1-thread-2, counter=5
thread=pool-1-thread-3, counter=6
thread=pool-1-thread-2, counter=7
thread=pool-1-thread-4, counter=8
thread=pool-1-thread-1, counter=9
thread=pool-1-thread-2, counter=10
thread=pool-1-thread-5, counter=11
thread=pool-1-thread-3, counter=12
thread=pool-1-thread-5, counter=13
....
You also must worry about concurrency at this global variables, or at java or at c, in the two is not necessary, then if you are just reading values from the global variables then you must not worry about concurrency.