Skip to content

Instantly share code, notes, and snippets.

@amitshekhariitbhu
Created July 10, 2016 16:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save amitshekhariitbhu/9bc3f1e384b6a437051708d8e12e214e to your computer and use it in GitHub Desktop.
Save amitshekhariitbhu/9bc3f1e384b6a437051708d8e12e214e to your computer and use it in GitHub Desktop.
public class PriorityThreadFactory implements ThreadFactory {
private final int mThreadPriority;
public PriorityThreadFactory(int threadPriority) {
mThreadPriority = threadPriority;
}
@Override
public Thread newThread(final Runnable runnable) {
Runnable wrapperRunnable = new Runnable() {
@Override
public void run() {
try {
Process.setThreadPriority(mThreadPriority);
} catch (Throwable t) {
}
runnable.run();
}
};
return new Thread(wrapperRunnable);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment