Skip to content

Commit 924141a

Browse files
committed
notes: added JavaQ66
1 parent 9c402b1 commit 924141a

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

notes/questions.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -752,6 +752,15 @@ int Integer
752752
65. Can we make array volatile in Java?
753753
> Yes, you can make an array volatile in Java but only the reference which is pointing to an array, not the whole array. If one thread changes the reference variable to points to another array, that will provide a volatile guarantee, but if multiple threads are changing individual array elements they won't be having happens before guarantee provided by the volatile modifier.
754754
755+
66. Can volatile make a non-atomic operation to atomic?
756+
> Volatile is not about atomicity, but there are cases where you can use a volatile variable to make the operation atomic.
757+
>
758+
> One example is having a long field in your class. If you know that a long field is accessed by more than one thread e.g. a counter, a price field or anything, you better make it volatile.
759+
>
760+
> Why? because reading to a long variable is not atomic in Java and done in two steps;
761+
>
762+
> If one thread is writing or updating long value, it's possible for another thread to see half value (fist 32-bit). While reading/writing a volatile long or double (64 bit) is atomic.
763+
755764
## Spring Boot
756765
1. What is the difference between Java EE and Spring?
757766
> Java EE is standardized (now Jakarta EE), runs on containers like WildFly.<br>

0 commit comments

Comments
 (0)