Example #1
0
 /**
  * Atomically checks if a given flag is set and - if not - sets it. When multiple threads
  * concurrently call this method with the same flag, only one of them will be able to set the flag
  *
  * @param flag
  * @return True if the flag could be set, false if not (was already set)
  */
 public boolean setTransientFlagIfAbsent(byte flag) {
   if (flag > Byte.MAX_VALUE || flag < 0)
     throw new IllegalArgumentException("flag has to be >= 0 and <= " + Byte.MAX_VALUE);
   synchronized (this) {
     if (isTransientFlagSet(flag)) return false;
     else setTransientFlag(flag);
     return true;
   }
 }
Example #2
0
 /**
  * Atomically checks if a given flag is set and - if not - sets it. When multiple threads
  * concurrently call this method with the same flag, only one of them will be able to set the flag
  *
  * @param flag
  * @return True if the flag could be set, false if not (was already set)
  */
 public synchronized boolean setTransientFlagIfAbsent(TransientFlag flag) {
   if (isTransientFlagSet(flag)) return false;
   setTransientFlag(flag);
   return true;
 }