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,怎么改程序
展开