Skip to content

Commit b59b5f8

Browse files
thread
1 parent 5e82e68 commit b59b5f8

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package com.examplehub.basics;
2+
3+
public class ThreadExample extends Thread {
4+
5+
public ThreadExample(String threadName) {
6+
this.setName(threadName);
7+
}
8+
9+
@Override
10+
public void run() {
11+
while (true) {
12+
try {
13+
printThreadInfo();
14+
Thread.sleep(1000);
15+
} catch (InterruptedException e) {
16+
e.printStackTrace();
17+
}
18+
}
19+
}
20+
21+
public static void printThreadInfo() {
22+
System.out.println(Thread.currentThread().getName() + " is running");
23+
}
24+
25+
public static void main(String[] args) throws InterruptedException {
26+
new ThreadExample("myThread").start();
27+
while (true) {
28+
printThreadInfo();
29+
Thread.sleep(1000);
30+
}
31+
}
32+
}

0 commit comments

Comments
 (0)