求个java多线程小程序 最好是以前文曲星上的猜数字

来源:百度知道 编辑:UC知道 时间:2024/07/09 02:45:32
如题 其他java小程序也可以 多线程的就好 越简单月号
最好能说明下做的是啥

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;

/**
* 一个通过实现Runnable接口,来创建的进程
*
* @author Administrator
*/
public class TimeThread implements Runnable {
private DateFormat df = new SimpleDateFormat("hh:mm:ss");

//
// The run() method will be invoked when the thread of this runnable object
// is started.
//
public void run() {
while (true) {
Calendar calendar = Calendar.getInstance();
System.out.format("Now is: %s.%n", df.format(calendar.getTime()));

try {
Thread.sleep(1000);
}
catch (InterruptedException e) {
e.printStackTrace();
}
}
}

public static void main(String[] args ) {
TimeThread time = new TimeThread();

Thread thread = new Thread(time);
thread.start();
}