Package artofillusion.util

Examples of artofillusion.util.ThreadManager


  {
    final AtomicBoolean flags[] = new AtomicBoolean[1000];
    for (int i = 0; i < flags.length; i++)
      flags[i] = new AtomicBoolean();
    final AtomicBoolean error = new AtomicBoolean();
    ThreadManager tm = new ThreadManager(flags.length, new artofillusion.util.ThreadManager.Task()
    {
      public void execute(int index)
      {
        if (flags[index].get())
          error.set(true);
        flags[index].set(true);
      }
      public void cleanup()
      {
      }
    });
    for (int repeat = 0; repeat < 50; repeat++)
    {
      for (int i = 0; i < flags.length; i++)
        flags[i].set(false);
      error.set(false);
      tm.run();
      assertFalse(error.get());
      for (int i = 0; i < flags.length; i++)
        assertTrue(flags[i].get());
    }
  }
View Full Code Here


  public void testCancel()
  {
    final AtomicBoolean canceled = new AtomicBoolean();
    final AtomicInteger errorCount = new AtomicInteger();
    final ThreadManager tm = new ThreadManager();
    tm.setNumIndices(1000);
    tm.setTask(new ThreadManager.Task()
    {
      public void execute(int index)
      {
        if (canceled.get())
          errorCount.incrementAndGet();
        if (index == 500)
        {
          tm.cancel();
          canceled.set(true);
        }
      }
      public void cleanup()
      {
      }
    });
    for (int repeat = 0; repeat < 50; repeat++)
    {
      canceled.set(false);
      errorCount.set(0);
      tm.run();
      assertTrue(errorCount.get() < Runtime.getRuntime().availableProcessors());
    }
  }
View Full Code Here

TOP

Related Classes of artofillusion.util.ThreadManager

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.