Untitled

mail@pastecode.io avatar
unknown
plain_text
2 months ago
595 B
0
Indexable
Never
    public static class HighPriorityThreadFactory implements ThreadFactory {
        @Override
        public Thread newThread(Runnable r) {
            Thread thread = new Thread(r);
            thread.setPriority(Thread.MAX_PRIORITY);
            return thread;
        }
    }

    public static final Executor HIGH_PRIORITY_EXECUTOR = new ThreadPoolExecutor(
            5, 128, 1, TimeUnit.SECONDS, null, new HighPriorityThreadFactory());

    // Execute AsyncTask using high priority executor
    public void executeHighPriority() {
        executeOnExecutor(HIGH_PRIORITY_EXECUTOR);
    }
Leave a Comment