Skip to content

Commit

Permalink
使用Android 平台的接口设置线程优先级
Browse files Browse the repository at this point in the history
  • Loading branch information
liushuai1 committed Apr 18, 2019
1 parent da39b71 commit daf99e0
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 12 deletions.
1 change: 0 additions & 1 deletion .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -10,36 +10,43 @@
*/
class ThreadFactory {

static final class BackgroundRunnable implements Runnable {
private Runnable runnable;
BackgroundRunnable(Runnable runnable) {
this.runnable = runnable;
}

@Override
public void run() {
Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND);
runnable.run();
}
}

static final java.util.concurrent.ThreadFactory TASKSCHEDULER_FACTORY = new java.util.concurrent.ThreadFactory() {
private final AtomicInteger mCount = new AtomicInteger(1);

@Override
public Thread newThread(Runnable r) {
Thread thread = new Thread(r, "TaskScheduler #" + mCount.getAndIncrement());
thread.setPriority(Process.THREAD_PRIORITY_BACKGROUND);
return thread;
return new Thread(new BackgroundRunnable(r), "TaskScheduler #" + mCount.getAndIncrement());
}
};

static final java.util.concurrent.ThreadFactory TIME_OUT_THREAD_FACTORY = new java.util.concurrent.ThreadFactory() {
static final java.util.concurrent.ThreadFactory TIME_OUT_THREAD_FACTORY = new java.util.concurrent.ThreadFactory() {
private final AtomicInteger mCount = new AtomicInteger(1);

@Override
public Thread newThread(Runnable r) {
Thread thread = new Thread(r, "TaskScheduler timeoutThread #" + mCount.getAndIncrement());
thread.setPriority(Process.THREAD_PRIORITY_BACKGROUND);
return thread;
return new Thread(new BackgroundRunnable(r), "TaskScheduler timeoutThread #" + mCount.getAndIncrement());
}
};

static final java.util.concurrent.ThreadFactory SCHEDULER_THREAD_FACTORY = new java.util.concurrent.ThreadFactory() {
private final AtomicInteger mCount = new AtomicInteger(1);

@Override
public Thread newThread( Runnable r) {
Thread thread = new Thread(r, "TaskScheduler scheduler #" + mCount.getAndIncrement());
thread.setPriority(Process.THREAD_PRIORITY_BACKGROUND);
return thread;
public Thread newThread(Runnable r) {
return new Thread(new BackgroundRunnable(r), "TaskScheduler scheduler #" + mCount.getAndIncrement());
}
};
}

0 comments on commit daf99e0

Please sign in to comment.