Volatile Fields

By default all fields are subjects to compiler optimisations
(for example storing simple variables in processor registers)

We can use the volatile keyword to disable these optimisations
If we do not disable this optimisation there is a chance the fields will get incorrect values

If you do not use the volatile keyword the static field will not be shared between the threads.

© 2024 Better Solutions Limited. All Rights Reserved. © 2024 Better Solutions Limited TopPrevNext