java 唤醒线程_java wait后怎么唤醒线程

classss{publicstaticinti1=0;publicstaticinti2=0;privateObjecttask=newObject();}classnumberextendsThread{intm=500;publicstaticnumberx1;//privatestaticObjecttask=newObject(...

class ss{

public static int i1=0;

public static int i2=0;

private Object task = new Object();

}

class number extends Thread

{

int m=500;

public static number x1;

// private static Object task = new Object();

public void run()

{

try

{

while(true)

{

sleep(m);

System.out.println(ss.i1);

ss.i1++;

synchronized(this){

if(ss.i1%7==0&&ss.i1%10==7)

{

this.wait();

}

}

}

}

catch(InterruptedException e)

{return;}

}

}

class letter extends Thread

{

int m=500;

String s=new String("ABCDEFGHIJKLMNOPQRSTUVWXYZ");

public void run()

{

try

{

while(true)

{

sleep(m);

System.out.println(s.charAt(ss.i2));

ss.i2++;

if(ss.i2==26)

{

ss.i2=0;

}

}

}

catch(InterruptedException e)

{return;}

}

}

class hello extends Thread

{

int m=5000;

String s2="hello";

public void run()

{

try

{

while(true)

{

sleep(m);

System.out.println(s2);

}

}

catch(InterruptedException e)

{return;}

}

}

public class ex {

public static void main(String[] args)

{

number tr1 =new number();

letter tr2 = new letter();

hello tr3=new hello();

tr1.start();

tr2.start();

tr3.start();

}

}

number中有个wait()

现在要在letter中加入notify()后继续运行number,怎么改程序

展开

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值