线程池的使用ExecutorService

线程池的使用ExecutorService
  private ExecutorService executorService = Executors.newFixedThreadPool(5);
  
         // 引入线程池来管理多线程
        private void loadImage3(final String url, final int id) {
                 executorService.submit(new Runnable() {
                         public void run() {
                                 try {
                                       final Drawable drawable = Drawable.createFromStream(
                                                        new URL(url).openStream(), "image.png");
                                        // 模拟网络延时
                                        SystemClock.sleep(2000);
                                        handler.post(new Runnable() {
                                                 public void run() {
                                                        ((ImageView) MainActivity.this.findViewById(id))
                                                                        .setImageDrawable(drawable);
                                                }
                                        });
                                } catch (Exception e) {
                                        throw new RuntimeException(e);
                                }
                         }
                });
         }
线程池的使用ExecutorService

 

线程池的使用ExecutorService,布布扣,bubuko.com

线程池的使用ExecutorService

上一篇:写了一个实用的图像放大缩小程序,但是动画GIF转换后不会显示了,只有第一帧


下一篇:springside出现Description Resource Path Location Type