In Java, CPU cores can cache variables in their registers, which means that in a multi-threaded application, each core can see a different value for the same variable, which can be a source of errors. To prevent this behavior, you can mark a variable volatilefor example:
private volatile int x;
Is this CPU caching behavior fast, and if so, is there an equivalent Java keyword volatileto prevent it?
monty source
share