首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 移动开发 > 移动开发 >

写了一个多线程,看似写的不好。

2012-09-27 
写了一个多线程,貌似写的不好。。。public class TestAppPageThread extends Thread {private static GameCen

写了一个多线程,貌似写的不好。。。
public class TestAppPageThread extends Thread {

private static GameCenterService gameCenterService;

public TestAppPageThread() {

}

public static void main(String[] args) throws IOException {
int threadCount = 10;
ServiceFactory fact = ServiceFactories.getFactory();
gameCenterService = fact.getService(GameCenterService.class);

System.out.println("threadCount:" + threadCount);

testMutiThread(threadCount);
}

public static void testMutiThread(int threadCount)
throws IOException {
read();
        //循环调用线程
for(int i=0; i< threadCount; i++){
//必须调用Thread的start()函数,该函数再调用run()
Thread t = new TestAppPageThread();
t.start();
}
}

@Override
//必须覆盖Thread的run()函数来完成有用的工作
public void run(){

try {
System.out.println("offset:" );
System.out.println("limit:");
       
//ServiceFuture<AppPage> f = gameCenterService.getPage(1, 2);
//ServiceFuture<AppPage[]> f = gameCenterService.getAppPageListByKeyword("僵尸", 0, 10);
        //ServiceFuture<AppPage[]> f =  gameCenterService.getAppPageListByStatus(1, 10);
        ServiceFuture<AppPage[]> f = gameCenterService.getAppPageCategoryList(1, 2, 1,10);
System.out.println(f);
System.out.println(11);
f.submit();


if (f.await(2300)) {
if (f.isSuccess()) {
System.out.println(14);
System.out.println(f.getContent());
AppPage[] pagelist  =  f.getContent();
System.out.print(pagelist.length);
for(AppPage page : pagelist){
long start = System.currentTimeMillis();
System.out.println(page.getId()+"  "+page.getPageName() + "  " + page.getAddTime()
+" time used:" + (System.currentTimeMillis()- start) + "ms");
}

} else {
System.out.println("not success");
}
}
      

} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}


}

public static void read() throws IOException {

System.out.println(9);
}

}

热点排行