xxxx18一60岁hd中国/日韩女同互慰一区二区/西西人体扒开双腿无遮挡/日韩欧美黄色一级片 - 色护士精品影院www

  • 大小: 1.27 KB
    文件類型: .rar
    金幣: 1
    下載: 0 次
    發(fā)布日期: 2024-09-15
  • 語言: Java
  • 標(biāo)簽: 多線程??同步??JAVA??編程??

資源簡介

自己學(xué)著編寫的一個(gè)JAVA多線程程序,該程序?qū)崿F(xiàn)的功能是:在主線程main中創(chuàng)建兩個(gè)子線程,A和B,線程A先運(yùn)行,再運(yùn)行B線程,當(dāng)兩個(gè)子線程都運(yùn)行完畢后,才運(yùn)行主線程,并最終結(jié)束整個(gè)程序的運(yùn)行。

希望該程序?qū)Τ鯇W(xué)JAVA線程的朋友有幫助...

資源截圖

代碼片段和文件信息

package?thread;
/**
?*?write?by?agan?
?*?E-mail:gsqsunny@gmain.com
?*?2009.1.3
?*?通過實(shí)現(xiàn)?Runnable?接口實(shí)現(xiàn)多線程
?*?description:
?*?????????????We?create?two?subThreads?(thread?A?and?thread?B?)in?the?main?thread.
?*?????????????The?main?thread?is?started?firstly?then?the?thread?A?is?started.?
?*?????????????When?the?thread?A?run?over?the?thread?B?is?started.
?*?????????????The?main?thread?run?over?until?the?two?subThreads?are?over?.
?*/
public?class?TestMitiThreadrunable?implements?Runnable{

/**
?*?@param?args
?*/
public?static?void?main(String[]?args)?{
//?TODO?Auto-generated?method?stub
System.out.println(Thread.currentThread().getName()?+?“?線程運(yùn)行開始!“);
System.out.println(“----------------------------------------“);
TestMitiThreadrunable?test?=?new?TestMitiThreadrunable();
????????Thread?thread1?=?new?Thread(test);
????????Thread?thread2?=?new?Thread(test);
????????thread1.setName(“A“);
????????thread1.start();
????????thread2.setName(“B“);
????????//?wait?for?thread1?is?over?then?startup?thread2
????????try?{
thread1.join();
}?catch?(InterruptedException?e)?{
//?TODO?Auto-generated?catch?block
e.printStackTrace();
}
????????thread2.start();
????????if(thread2.isAlive())
try?{
Thread.currentThread().sleep(1000);
}?catch?(InterruptedException?e)?{
//?TODO?Auto-generated?catch?block
e.printStackTrace();
}
System.out.println(“----------------------------------------“);
????????System.out.println(Thread.currentThread().getName()?+?“?線程運(yùn)行結(jié)束!“);
}

public?void?run(){
System.out.println(“----------------------------------------“);
System.out.println(Thread.currentThread().getName()+“?線程運(yùn)行開始!“);
System.out.println(“ThreadName????:“+Thread.currentThread().getName());
System.out.println(“ThreadID??????:“+Thread.currentThread().getId());
System.out.println(“ThreadPriority:“+Thread.currentThread().getPriority());
System.out.println(“ThreadGroup???:“+Thread.currentThread().getThreadGroup());
for?(int?i?=?0;?i? System.out.println(i?+?“?“?+?Thread.currentThread().getName());
try?{
Thread.sleep((int)?Math.random()?*?10);
}?catch?(InterruptedException?e)?{
//?TODO?Auto-generated?catch?block
e.printStackTrace();
}
}
System.out.println(Thread.currentThread().getName()?+?“?線程運(yùn)行結(jié)束!“);
System.out.println(“----------------------------------------“);
}
}

?屬性????????????大小?????日期????時(shí)間???名稱
-----------?---------??----------?-----??----

?????文件???????2475??2009-01-03?14:30??java?多線程實(shí)例\TestMitiThreadrunable.java

?????文件????????684??2009-01-03?14:30??java?多線程實(shí)例\運(yùn)行結(jié)果.txt

?????目錄??????????0??2009-01-03?14:31??java?多線程實(shí)例

-----------?---------??----------?-----??----

?????????????????3159????????????????????3


評(píng)論

共有 條評(píng)論