package hello.Thread;
class thread {
static void loop() throws InterruptedException {
System.out.println(Thread.currentThread().getName());
for (int i = 0; i < 10; i++) {
System.out.println("i=" + i);
Thread.sleep(10);
}
}
public static void main(String[] args) {
new Thread() {
@Override
public void run() {
try {
loop();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}.start();
System.out.println(Thread.currentThread().getName());
}
}
package hello.Thread;
class MyThread extends Thread {
@Override
public void run() {
for (int i = 0; i < 10; i++) {
System.out.println(Thread.currentThread().getName() + " i = " + i);
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}
class MyThread2 implements Runnable {
@Override
public void run() {
}
}
class thread {
static void loop() throws InterruptedException {
System.out.println(Thread.currentThread().getName());
for (int i = 0; i < 10; i++) {
System.out.println("i=" + i);
Thread.sleep(100);
}
}
public static void main(String[] args) throws InterruptedException {
Thread thread = new Thread(new MyThread(), "t1");
thread.start();
thread.join();
for (int i = 0; i < 10; i++) {
System.out.println(Thread.currentThread().getName() + " i = " + i);
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}