-
Notifications
You must be signed in to change notification settings - Fork 0
/
interrupt.java
40 lines (27 loc) · 937 Bytes
/
interrupt.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import java.io.*;
class mythread extends Thread
{
public mythread(String name)
{
super(name);
}
public void run()
{
int count = 1 ;
while (true)
{
System.out.println(count++);
try{ Thread.sleep(1000 ) ; } catch(Exception e){ System.out.println(e); } //this line will slow down the
// process of printing
//becuse cpu will sleep for some time
}
}
}
public class interrupt {
public static void main(String arg []) throws Exception
{
mythread mt = new mythread("my thread 1");
mt.start();
mt.interrupt(); //interrupts the mt.start() for some time...
}
}