-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathThreadMethods.java
More file actions
24 lines (19 loc) · 792 Bytes
/
ThreadMethods.java
File metadata and controls
24 lines (19 loc) · 792 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
public class ThreadMethods extends Thread {
public void run() {
System.out.println("Thread started: " + Thread.currentThread().getName());
Thread.yield();
System.out.println("Thread after yield(): " + Thread.currentThread().getName());
try {
Thread.sleep(2000);
System.out.println("Thread after sleep(): " + Thread.currentThread().getName());
} catch (InterruptedException e) {
System.out.println("Thread interrupted while sleeping");
}
Thread.currentThread().stop();
System.out.println("Thread after stop(): " + Thread.currentThread().getName());
}
public static void main(String[] args) {
ThreadMethods thread = new ThreadMethods();
thread.start();
}
}