I am setting a flag which is set once by any thread that get to set it. All other threads will at various time, pretty often read this flag repeateadly.
Right now I am using an AtomicBoolean, which works fine, but I know that if it is queried quite often it can be considerably slower than plain boolean, ( not sure if this is true ).
Would it be thread safe to instead change this to a static boolean? Set the flag to true by whoever gets to do that, in fact all of them might be allowed to set the flag several times over.
What I am concerned about is how quickly those reading the flag will be able to spot it? Will it be right of? Or might them not get it right?
Also, how big is the performance hit of using an AtomicBoolean that is queried often?
Also, should I perhaps consider using a volatile boolean over AtomicBoolean since I will pretty much only be setting it once and reading it, and can perform the set operation atomically ( copying the code in AtomicBoolean for getAndSet())