/**
* æ®éthread
* è¿æ¯æ常è§çï¼å建ä¸ä¸ªthreadï¼ç¶å让å®å¨while循ç¯éä¸ç´è¿è¡çï¼
* éè¿sleepæ¹æ³æ¥è¾¾å°å®æ¶ä»»å¡çææãè¿æ ·å¯ä»¥å¿«éç®åçå®ç°ï¼ä»£ç å¦ä¸ï¼
* @author GT
*
*/
public class Task1 {
public static void main(String[] args) {
// run in a second
final long timeInterval = 1000;
Runnable runnable = new Runnable() {
public void run() {
while (true) {
// ------- code for task to run
System.out.println("Hello !!");
// ------- ends here
try {
Thread.sleep(timeInterval);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
};
Thread thread = new Thread(runnable);
thread.start();
}
}
温馨提示:答案为网友推荐,仅供参考