代码
public class useExample extends Thread
{
public Usethread1 us;
public useExample()
{
us=new Usethread1 ();
}
public static void main(String str[])
{
useExample ue=new useExample ();
Thread.sleep(1000);//等待us的线程终止 知道要有try省略
ue.us.reStart();// 重新唤醒 us 的线程。出错。
}
public void run()
{
system.out.println("useExample 线程");
}
}
class Usethread1 implements Runnable
{
public Thread1()
{
new Thread(this).start();
}
int i=0;
public void run()
{
while(true)
{
aa();
}
}
private synchronized void aa()
{
if(i++<10)
{
this.waite();
}
system.out.println("Usethread1 线程:"+i);
}
public void reStart()
{
this.notify();
}
}
请问如何唤醒这个线程
public class useExample extends Thread
{
public Usethread1 us;
public useExample()
{
us=new Usethread1 ();
}
public static void main(String str[])
{
useExample ue=new useExample ();
Thread.sleep(1000);//等待us的线程终止 知道要有try省略
ue.us.reStart();// 重新唤醒 us 的线程。出错。
}
public void run()
{
system.out.println("useExample 线程");
}
}
class Usethread1 implements Runnable
{
public Thread1()
{
new Thread(this).start();
}
int i=0;
public void run()
{
while(true)
{
aa();
}
}
private synchronized void aa()
{
if(i++<10)
{
this.waite();
}
system.out.println("Usethread1 线程:"+i);
}
public void reStart()
{
this.notify();
}
}
请问如何唤醒这个线程