Class SchedulingStrategy
- java.lang.Object
-
- org.apache.maven.surefire.junitcore.pc.SchedulingStrategy
-
- All Implemented Interfaces:
Destroyable
public abstract class SchedulingStrategy extends java.lang.Object implements Destroyable
Specifies the strategy of scheduling whether sequential, or parallel. The strategy may use a thread pool shared with other strategies.
One instance of strategy can be used just by oneScheduler.
The strategy is scheduling tasks inschedule(Runnable)and awaiting them completed infinished(). Both methods should be used in one thread.- Since:
- 2.16
- Author:
- Tibor Digana (tibor17)
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedSchedulingStrategy(org.apache.maven.plugin.surefire.log.api.ConsoleLogger logger)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected booleancanSchedule()protected booleandisable()Persistently disables this strategy.protected abstract booleanfinished()Waiting for scheduled tasks to finish.protected abstract booleanhasSharedThreadPool()protected voidlogQuietly(java.lang.Throwable t)protected abstract voidschedule(java.lang.Runnable task)Schedules tasks ifcanSchedule().protected voidsetDefaultShutdownHandler(Scheduler.ShutdownHandler handler)protected abstract booleanstop()Stops scheduling new tasks (e.g.protected booleanstopNow()Stops scheduling new tasks andinterruptsrunning tasks (e.g.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.apache.maven.surefire.junitcore.pc.Destroyable
destroy
-
-
-
-
Method Detail
-
schedule
protected abstract void schedule(java.lang.Runnable task)
Schedules tasks ifcanSchedule().- Parameters:
task- runnable to schedule in a thread pool or invoke- Throws:
java.util.concurrent.RejectedExecutionException- iftaskcannot be scheduled for executionjava.lang.NullPointerException- iftaskisnull- See Also:
RunnerScheduler.schedule(Runnable),Executor.execute(Runnable)
-
finished
protected abstract boolean finished() throws java.lang.InterruptedExceptionWaiting for scheduled tasks to finish. New tasks will not be scheduled by calling this method.- Returns:
trueif successfully stopped the scheduler, elsefalseif already stopped (a shared thread pool was shutdown externally).- Throws:
java.lang.InterruptedException- if interrupted while waiting for scheduled tasks to finish- See Also:
RunnerScheduler.finished()
-
stop
protected abstract boolean stop()
Stops scheduling new tasks (e.g. byExecutorService.shutdown()on a private thread pool which cannot be shared with other strategy).- Returns:
trueif successfully stopped the scheduler, elsefalseif already stopped (a shared thread pool was shutdown externally).- See Also:
ExecutorService.shutdown()
-
stopNow
protected boolean stopNow()
Stops scheduling new tasks andinterruptsrunning tasks (e.g. byExecutorService.shutdownNow()on a private thread pool which cannot be shared with other strategy).
This method callsstop()by default.- Returns:
trueif successfully stopped the scheduler, elsefalseif already stopped (a shared thread pool was shutdown externally).- See Also:
ExecutorService.shutdownNow()
-
disable
protected boolean disable()
Persistently disables this strategy. Atomically ignoresBalancerto acquire a new permit.
The methodcanSchedule()atomically returnsfalse.- Returns:
trueifcanSchedule()has returntrueon the beginning of this method call.
-
setDefaultShutdownHandler
protected void setDefaultShutdownHandler(Scheduler.ShutdownHandler handler)
-
hasSharedThreadPool
protected abstract boolean hasSharedThreadPool()
- Returns:
trueif a thread pool associated with this strategy can be shared with other strategies.
-
canSchedule
protected boolean canSchedule()
- Returns:
trueunless stopped, finished or disabled.
-
logQuietly
protected void logQuietly(java.lang.Throwable t)
-
-