抢分啦----线程问题(在线等) 本帖最后由 java2000_net 于 2008-08-04 14:30:40 编辑 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 class Test{ public static void main(String[] args) { Thread list_1=new list_1(); Thread list_2=new list_2(); Thread list_3=new list_3(); list_1.start(); list_2.start(); list_3.start(); }}class list_1 extends Thread { list_1() { } public void run() { System.out.println("list_1_1 需要1秒"); try { sleep(1000);// 挂起1000 } catch (InterruptedException e) { return; } while(!list_3.key){ try { sleep(100); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } } //断点 //需要判断list_3中的(步骤A)有没有完成,如果完成了,就执行以下的程序,如果没有就等到完成后再执行 System.out.println("list_1_2 需要1秒"); try { sleep(1000);// 挂起1000 } catch (InterruptedException e) { return; } System.out.println("list_1_3 需要1秒"); try { sleep(1000);// 挂起1000 } catch (InterruptedException e) { return; } }}class list_2 extends Thread { list_2() { } int i=0; public void run(){ System.out.println("list_2_1 需要2秒"); try { sleep(2000);// 挂起2000 } catch (InterruptedException e) { return; } System.out.println("list_2_2 需要2秒"); try { sleep(2000);// 挂起2000 } catch (InterruptedException e) { return; } System.out.println("list_2_3 需要2秒"); try { sleep(2000);// 挂起2000 } catch (InterruptedException e) { return; } }}class list_3 extends Thread { public static boolean key = false; list_3() { } public void run() { System.out.println("list_3_1 需要3秒"); try { sleep(3000);// 挂起3000 } catch (InterruptedException e) { return; } //断点 //以上就是(步骤A)如果完成到这里,list_1类的步骤才开始进行 key = true; System.out.println("list_3_2 需要3秒"); try { sleep(3000);// 挂起3000 } catch (InterruptedException e) { return; } System.out.println("list_3_3 需要3秒"); try { sleep(3000);// 挂起3000 } catch (InterruptedException e) { return; } }} 线程同步?不懂,我是今天才接触线程的还在头晕ING能不能写个例子? java API中,没有对数组降序排序的方法? 关于 返回值的问题 通过按钮促发treeModel.reload()后,怎么重新聚焦? Jcreator 4 太不爽了,每次都自动加注释,可以不可以消掉他 java中对声音和动画的处理 谁能告诉我这里面car.super()有什么用? 用何软件能方便地(向vb一样)实现窗体设计。 请问大家JBoss的稳定性和效率如何? JavaCC从哪里可以下载到? 汉字与字母的区分? 这是什么问题? java Socket问题。贴出源程序。大家帮忙看看。
{
public static void main(String[] args)
{
Thread list_1=new list_1();
Thread list_2=new list_2();
Thread list_3=new list_3();
list_1.start();
list_2.start();
list_3.start();
}
}class list_1 extends Thread
{
list_1()
{
}
public void run() {
System.out.println("list_1_1 需要1秒");
try {
sleep(1000);// 挂起1000
} catch (InterruptedException e) {
return;
}
while(!list_3.key){
try {
sleep(100);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
//断点
//需要判断list_3中的(步骤A)有没有完成,如果完成了,就执行以下的程序,如果没有就等到完成后再执行
System.out.println("list_1_2 需要1秒");
try {
sleep(1000);// 挂起1000
} catch (InterruptedException e) {
return;
}
System.out.println("list_1_3 需要1秒");
try {
sleep(1000);// 挂起1000
} catch (InterruptedException e) {
return;
}
}
}class list_2 extends Thread
{
list_2()
{
}
int i=0;
public void run(){
System.out.println("list_2_1 需要2秒");
try {
sleep(2000);// 挂起2000
} catch (InterruptedException e) {
return;
}
System.out.println("list_2_2 需要2秒");
try {
sleep(2000);// 挂起2000
} catch (InterruptedException e) {
return;
}
System.out.println("list_2_3 需要2秒");
try {
sleep(2000);// 挂起2000
} catch (InterruptedException e) {
return;
}
}
}class list_3 extends Thread
{
public static boolean key = false;
list_3()
{
} public void run() {
System.out.println("list_3_1 需要3秒");
try {
sleep(3000);// 挂起3000
} catch (InterruptedException e) {
return;
}
//断点
//以上就是(步骤A)如果完成到这里,list_1类的步骤才开始进行
key = true;
System.out.println("list_3_2 需要3秒");
try {
sleep(3000);// 挂起3000
} catch (InterruptedException e) {
return;
}
System.out.println("list_3_3 需要3秒");
try {
sleep(3000);// 挂起3000
} catch (InterruptedException e) {
return;
}
}
}
还在头晕ING
能不能写个例子?