读书人

线程池跟SystemClock

发布时间: 2012-06-27 14:20:08 作者: rapoo

线程池和SystemClock

private ExecutorService executorService = Executors.newFixedThreadPool(5); // 固定五个线程来执行任务

?

SystemClock.sleep(2000);这个方法只是封装了Thread.sleep,不会抛出中断异常

?

SystemClock:public static void sleep(long ms)    {        long start = uptimeMillis();        long duration = ms;        boolean interrupted = false;        do {            try {                Thread.sleep(duration);            }            catch (InterruptedException e) {                interrupted = true;            }            duration = start + ms - uptimeMillis();        } while (duration > 0);                if (interrupted) {            // Important: we don't want to quietly eat an interrupt() event,            // so we make sure to re-interrupt the thread so that the next            // call to Thread.sleep() or Object.wait() will be interrupted.            Thread.currentThread().interrupt();        }    }
?

?

?

读书人网 >系统运维

热点推荐