How to test atomicboolean in method

731 views Asked by At

I want to test my method for thread-safety. For that I am using an atomicboolean. If it is true, then an exception is thrown. Now i want to test this function. What is the best way to test this function??

public void startProcess() {
      if(inProcess.compareAndSet(false, true)) {
              service.startProcess();
              inProcess.set(false);
      } else {
          throw new SomeNewException("Process running.");
      }
      inProcess.set(false);
}

thanks in advance

0

There are 0 answers