SHARE
TWEET

EnumSetTearingTest.java

a guest Mar 11th, 2015 175 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import java.util.EnumSet;
  2. import java.util.concurrent.ExecutorService;
  3. import java.util.concurrent.Executors;
  4. import java.util.concurrent.TimeUnit;
  5.  
  6. public class EnumSetTearingTest {
  7.  
  8.     public static void main(String[] args) throws Exception {
  9.         for (int i = 0; i < 100; i++) {
  10.             EnumSet<TestEnum> set = EnumSet.noneOf(TestEnum.class);
  11.             ExecutorService pool = Executors.newFixedThreadPool(4);
  12.             for (TestEnum val : TestEnum.values()) {
  13.                 pool.submit(() -> {
  14.                     set.add(val);
  15.                 });
  16.             }
  17.             pool.shutdown();
  18.             pool.awaitTermination(1, TimeUnit.SECONDS);
  19.  
  20.             if (set.size() != TestEnum.values().length) {
  21.                 System.out.println("Boo!");
  22.             } else {
  23.                 System.out.println("As expected");
  24.             }
  25.  
  26.         }
  27.  
  28.     }
  29.  
  30.     public enum TestEnum {
  31.         A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P;
  32.     }
  33. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top