-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy paththreadDemo.java
More file actions
41 lines (34 loc) · 1.04 KB
/
threadDemo.java
File metadata and controls
41 lines (34 loc) · 1.04 KB
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
41
public class threadDemo extends Thread{
private String n;
private String name;
@Override
public void run()
{
for(int i=0;i<10;i++)
{
System.out.println(Thread.currentThread().getName());
System.out.println(Thread.currentThread().getPriority());
System.out.println("Child thread is paused");
try {
Thread.sleep(3000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
System.out.println("Child thread is started");
}
public static void main(String [] args)
{
threadDemo t=new threadDemo();
Thread th1=new Thread(t);
th1.setName("firstThread");
th1.start();
th1.setPriority(2);
System.out.println(Thread.currentThread().getName());
System.out.println(Thread.currentThread().getPriority());
for(int i=0;i<10;i++)
{
System.out.println("main thread");
}
}
}