标签:
public void perform(){ ScheduledExecutorService schedulePool=Executors.newScheduledThreadPool(1); long initialDelay=10; long period=3; schedulePool.scheduleAtFixedRate(new Runnable(){ @Override public void run() { HttpClient client = new DefaultHttpClient(); String url="http://localhost:8080/member/....../test.do"; HttpUriRequest get=new HttpGet(url); try { HttpResponse res = client.execute(get); System.out.println(EntityUtils.toString(res.getEntity(),"utf-8")); } catch (ClientProtocolException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); }finally{ if(client!=null){ client.getConnectionManager().shutdown(); } } } }, initialDelay, period, TimeUnit.SECONDS); }
监控资源发现,方法内部的线程池关不关闭都无所谓(ExecutorService.shutdown()),
细细想来,也是这个道理:方法跑完的时候方法内所有内部的变量都会被标记为清楚,所以线程池也被标记为清楚了,所以不会占用资源。
标签:
原文地址:http://www.cnblogs.com/shoubianxingchen/p/5555696.html