mirror of
https://github.com/Dichgrem/Java.git
synced 2025-12-16 12:41:58 -05:00
23 lines
527 B
Java
23 lines
527 B
Java
package com.study.demo6;
|
|
|
|
public class ThreadDemo2 {
|
|
static class CountTask implements Runnable {
|
|
@Override
|
|
public void run() {
|
|
for (int i = 1; i <= 10; i++) {
|
|
System.out.println(Thread.currentThread().getName() + " 计数:" + i);
|
|
try {
|
|
Thread.sleep(500);
|
|
} catch (InterruptedException e) {
|
|
e.printStackTrace();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
public static void main(String[] args) {
|
|
Thread t = new Thread(new CountTask(), "计数线程");
|
|
t.start();
|
|
}
|
|
}
|