/** * Instantiate and run the Once each test with given threadCount. * * @param <T> TestThread subclass type * @param cls TestThread subclass * @param threadCount number of test threads to run */ static <T extends MultiThreadedTest.Once> void runTestThreadsOnce(Class<T> cls, int threadCount) { runTestThreads(cls, threadCount, 300000000000L); // Run for 300 seconds }
/** * Instantiate and run the Once each test with given threadCount. * * @param <T> TestThread subclass type * @param cls TestThread subclass * @param threadCount number of test threads to run */ static <T extends MultiThreadedTest.Once> void runTestThreadsOnce(Class<T> cls, int threadCount) { runTestThreads(cls, threadCount, 300000000000L); // Run for 300 seconds }
/** * Instantiate and run the Loop test. One thread instance for each available processor * * @param <T> TestThread subclass type * @param cls TestThread subclass * @param nanos run duration ns */ static <T extends MultiThreadedTest.Loop> void runTestThreadsLoop(Class<T> cls, long nanos) { int cpus = Runtime.getRuntime().availableProcessors(); runTestThreads(cls, cpus, nanos); }
/** * Instantiate and run the Loop test. One thread instance for each available processor * * @param <T> TestThread subclass type * @param cls TestThread subclass * @param nanos run duration ns */ static <T extends MultiThreadedTest.Loop> void runTestThreadsLoop(Class<T> cls, long nanos) { int cpus = Runtime.getRuntime().availableProcessors(); runTestThreads(cls, cpus, nanos); }
/** * Runs test threads. * * @param <T> TestThread subclass type * @param cls TestThread subclass * @param threadCount number of test threads to run * @param nanos run duration ns */ static <T extends MultiThreadedTest.TestThread> void runTestThreads(Class<T> cls, int threadCount, long nanos) { // on your mark long startTime = System.nanoTime() + 200000000L; // now + 0.2 sec List<TestThread> threads = new ArrayList<>(); for (int threadNumber = 0; threadNumber < threadCount; threadNumber++) { MultiThreadedTest.TestThread thread; try { thread = cls.newInstance(); } catch (InstantiationException | IllegalAccessException e) { throw new RuntimeException(e); } thread.setName("TestThread-" + threadNumber); thread.startTime = startTime; thread.stopTime = startTime + nanos; thread.testId = threadNumber; threads.add(thread); } runTestThreads(threads); }
/** * Runs test threads. * * @param <T> TestThread subclass type * @param cls TestThread subclass * @param threadCount number of test threads to run * @param nanos run duration ns */ static <T extends MultiThreadedTest.TestThread> void runTestThreads(Class<T> cls, int threadCount, long nanos) { // on your mark long startTime = System.nanoTime() + 200000000L; // now + 0.2 sec List<TestThread> threads = new ArrayList<>(); for (int threadNumber = 0; threadNumber < threadCount; threadNumber++) { MultiThreadedTest.TestThread thread; try { thread = cls.newInstance(); } catch (InstantiationException | IllegalAccessException e) { throw new RuntimeException(e); } thread.setName("TestThread-" + threadNumber); thread.startTime = startTime; thread.stopTime = startTime + nanos; thread.testId = threadNumber; threads.add(thread); } runTestThreads(threads); }