- Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathinterrupt.java
More file actions
Latest commit
24 lines (22 loc) · 523 Bytes
/
Copy pathinterrupt.java
File metadata and controls
24 lines (22 loc) · 523 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
classMyThreadextendsThread {
@Override
publicvoidrun() {
for (inti = 1; i <= 5; i++) {
try {
Thread.sleep(1000);
System.out.println("Iteration " + i);
} catch (InterruptedExceptione) {
System.out.println("Thread interrupted!");
break;
}
}
}
}
publicclassinterrupt{
publicstaticvoidmain(String[] args) throwsInterruptedException {
MyThreadthread = newMyThread();
thread.start();
Thread.sleep(2000);
thread.interrupt();
}
}