首页 > 移动平台 > 详细

java_线程的开启与结束(可用于android)

时间:2014-10-21 12:19:21      阅读:260      评论:0      收藏:0      [点我收藏+]
package testJavaAll;


import java.util.Timer;
import java.util.TimerTask;


/**
 * 测试线程开启和停止cancel的
 * 
 * 2014年10月21日 10:34:57
 * 
 * yjbo
 */



public class testThread {
Timer timer;
private int x = 0;


public testThread(int seconds, int seconds2) {
timer = new Timer();
timer.schedule(new RemindTask(), seconds * 1000, seconds2 * 1000);
}


class RemindTask extends TimerTask {
public void run() {
x++;
System.out.println("----xx---" + x);
if (x < 10) {
// 开启线程
System.out.println("Time‘s up!");
} else if (x == 10) {
// 停止线程
timer.cancel(); // Terminate the timer thread
System.out.println("Time‘s up!`````000");
}
}
}


public static void main(String args[]) {
System.out.println("About to schedule task.");
new testThread(1, 2);
System.out.println("Task scheduled.");
}
}
// }

java_线程的开启与结束(可用于android)

原文:http://blog.csdn.net/yangjianbo456/article/details/40341693

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!