尝试编写将运行、挂起和恢复 3 个线程的程序。
这是编码:
class Connectthread implements Runnable
{
public void run()
{
for(int j=0;j<90;j+=10)
System.out.println("Connecting..." + j + " Secs");
}
}
class DLoadthread implements Runnable
{
public void run()
{
for(int d=0;d<60;d+=10)
System.out.println("Downloading..." + d + " Secs");
}
}
class Runthread implements Runnable
{
public void run()
{
for(int r=0;r<120;r+=10)
System.out.println("Running..." + r + " Secs");
}
}
class EHAunitThread
{
Connectthread ct=new Connectthread();
DLoadthread dt=new DLoadthread();
Runthread rt=new Runthread();
public void main(String arg[])
{
//putting threads into ready state.
System.out.print("Starting threads\n");
ct.start();
dt.start();
rt.start();
System.out.print("Sleeping 3 seconds\n");
safeSleep(3000, "Threads first sleep time interrupted\n");
System.out.print("Suspending threads\n");
ct.suspend();
dt.suspend();
rt.suspend();
System.out.print("Sleep 5 seconds\n");
safeSleep(5000, "Threads second sleep time interrupted\n");
System.out.print("Resume threads\n");
ct.resume();
dt.resume();
rt.resume();
try
{
ct.join();
dt.join();
rt.join();
}
catch (InterruptedException e)
{
System.out.print("Join interrupted");
}
System.out.print("Testcase Completed");
System.exit(0);
}
}
error:cannot find symbol
当我尝试编译它时,它不断给我 14 条这样的消息。
据我所知,就语法而言,编码看起来是正确的。我在这里做错了什么?