[java]代码库
public class ThreadControlTest1 implements Runnable
{
private int percent = 0;
private boolean isRun = true;
public void run()
{
while(isRun)
{
System.out.println("传送进度:"+ percent +"%");
try
{
Thread.sleep(1000);
}
catch(Exception ex)
{}
percent += 10;
if(percent == 100)
{
System.out.println("传送完毕");
break;
}
}
}
public static void main(String[] args)
{
ThreadControlTest1 ft = new ThreadControlTest1();
Thread th = new Thread(ft);
th.start();
try
{
Thread.sleep(5000);
}catch(Exception ex)
{}
ft.isRun = false;
System.out.println("暂停一分钟");
try
{
Thread.sleep(1000*60);
}catch(Exception ex)
{}
ft.isRun = true;
th = new Thread(ft);
th.start();
}
}//源代码片段来自云代码http://yuncode.net