Multiple choice technology programming languages

7) How will you declare a timer variable that will be accessed by multiple threads very frequently?

  1. Declare the variable as volatile.

  2. not possible

  3. By java.util.*;

  4. By final keyword

Reveal answer Fill a bubble to check yourself
A Correct answer
Explanation

The volatile keyword tells the JVM that a variable may be modified by multiple threads asynchronously. This prevents threads from caching the variable's value in CPU registers, ensuring all reads and writes go directly to main memory where all threads can see the latest value.