我需要以低于应用程序中所有其他线程的ScheduledExecutorService
优先级(at )运行所有计划任务/线程。MIN_PRIORITY
我一直在按照以下方式执行此操作,但这是完成此操作的正确方法吗?
ScheduledExecutorService schdExctr = Executors.newSingleThreadScheduledExecutor(new ThreadFactory() {
@Override
public Thread newThread(Runnable r) {
Thread t = new Thread(r);
t.setPriority(Thread.MIN_PRIORITY);
return t;
}
});
编辑:
我认为更好的实现是这样的:
private ScheduledExecutorService schdExctr = Executors.newSingleThreadScheduledExecutor(new ThreadFactory() {
@Override
public Thread newThread(Runnable r) {
Thread t = Executors.defaultThreadFactory().newThread(r);
t.setPriority(Thread.MIN_PRIORITY);
return t;
}
});