package com.jiuqi.mobile.core.thread; import java.net.HttpURLConnection; import java.net.URL; import org.junit.Test; import com.jqmobile.core.utils.thread.AsyncTask; public class ThreadTest extends AsyncTask<Integer, Long>{ private int time; @Test public void testThreadPool(){ // IThreadPool pool = new BaseThreadPool(10, 1000000); // IThreadPool p = BaseThreadPool.getInstance(2, 10, 100000); ThreadTest t; int start = 1; for(int i=0; i<10; i++){ t = new ThreadTest(); t.time = i; t.execute(start,start^2); } long s = System.currentTimeMillis(); while(getTaskCount()>0){ try { Thread.sleep(1000); } catch (InterruptedException e) { e.printStackTrace(); } } System.out.println(getTaskCount()); System.out.println("thread count:"+btp.getThreadCount() ); System.out.println("time:"+(System.currentTimeMillis()-s)); // try { // Thread.sleep(100000); // } catch (InterruptedException e) { // e.printStackTrace(); // } } @Override protected Long doInBackground(Integer... params) throws Throwable { long l = System.currentTimeMillis(); // String s = "abcdefghijklmnopqrstuvwxyz"; // int time=1000; // for(int i : params){ // while(0<i--){ // int i1 = i/100; // int i2 = i%100; //// int i3 = (i-i1*100-i2*100)/100; // d+=(double)i1/(double)i2;///i3; // s+=i; URL url = new URL("http://www.baidu.com"); HttpURLConnection conn = (HttpURLConnection) url.openConnection(); conn.connect(); conn.getResponseCode(); // } // } return System.currentTimeMillis()-l; } @Override protected void onPostExecute(Long result) { System.out.println(time+"\t:time hava: \t"+result); // System.out.println(time+"\t: \t"+result); } }