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

抢分啦-线程有关问题()

2012-01-24 
抢分啦----线程问题(在线等)以下程序中有两个“断点”要求:只有当到达list_3的中断点时,list_1的断点后的程

抢分啦----线程问题(在线等)
以下程序中有两个“断点”
要求:只有当到达list_3的中断点时,list_1的断点后的程序才执行
我不知道怎么设置一个标志来判断list_3中的前面部分程序已经执行
希望大家写出完整的程序,不要用文字来讲道理,谢谢
也可以按照我的思路把重新做一个程序或者修改我的程序
真实要求是:
有四个进程
list_1list_2list_3
要求同时三个进程同时开始

list_1中有方法
list_1_1(打印“list_1_1 需要1秒”)
list_1_2(打印“list_1_2 需要1秒”)(步骤2)
list_1_3(打印“list_1_3 需要1秒”)
执行顺序为:1 2 3 

list_2中有方法
list_2_1(打印“list_2_1 需要2秒”)
list_2_2(打印“list_2_2 需要2秒”)
list_2_3(打印“list_2_3 需要2秒”)
执行顺序为:1 2 3 

list_3中有方法
list_3_1(打印“list_3_1 需要3秒”)(步骤1)
list_3_2(打印“list_3_2 需要3秒”)
list_3_3(打印“list_3_3 需要3秒”)
执行顺序为:1 2 3 

额外要求:只有当(步骤1)完成后(步骤2)才会开始

Java code
class TestThread {    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;        }    //断点    //需要判断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 {    list_3()    {    }      public void run() {        System.out.println("list_3_1 需要3秒");        try {            sleep(3000);// 挂起3000        } catch (InterruptedException e) {            return;        }    //断点    //以上就是(步骤A)如果完成到这里,list_1类的步骤才开始进行    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;        }    }}



--------------------------------
以下内容为自动编辑的内容,并非楼主的发贴内容,此仅用于显示而已,并无任何其他特殊作用
楼主【ilvoehua】截止到2008-08-04 14:30:36的历史汇总数据(不包括此帖):
发帖的总数量:4 发帖的总分数:30 每贴平均分数:7  
回帖的总数量:29 得分贴总数量:14 回帖的得分率:48%  
结贴的总数量:3 结贴的总分数:10  
无满意结贴数:0 无满意结贴分:0  
未结的帖子数:1 未结的总分数:20  
结贴的百分比:75.00 % 结分的百分比:33.33 %  
无满意结贴率:0.00 % 无满意结分率:0.00 %  
楼主加油
取消马甲机器人,请点这里:http://www.java2000.net/mycsdn/robotStop.jsp?usern=ilvoehua

------解决方案--------------------


线程方面偶也不咋懂,帮你顶下````````
[解决办法]
帮顶~
[解决办法]

Java code
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;        }    }} 

热点排行
Bad Request.