-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmulti_thread.java
More file actions
41 lines (37 loc) · 1.32 KB
/
multi_thread.java
File metadata and controls
41 lines (37 loc) · 1.32 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
class MyThreadRunnable1 implements Runnable{
public void run(){
try
{
for(int i=0; i<10;i++){
System.out.println("I am a thread 1 not a threat 1");
Thread.sleep(10);
}
}
catch(Exception e){
System.out.println("I am fine ji .....");
}
}
}
class MyThreadRunnable2 implements Runnable{
public void run(){
for(int i=0; i<10;i++)
System.out.println("I am a thread 2 not a threat 2");
}
}
public class multi_thread {
public static void main(String[] args) {
MyThreadRunnable1 th1 = new MyThreadRunnable1();
Thread th11 = new Thread(th1);
MyThreadRunnable2 th2 = new MyThreadRunnable2();
Thread th22 = new Thread(th2);
System.out.println("t1 thread priority : "+ th11.getPriority());
System.out.println("t1 thread priority : "+ th22.getPriority());
th22.setPriority(3);
th11.setPriority(8);
System.out.println("t1 thread priority : "+ th11.getPriority());
System.out.println("t1 thread priority : "+ th22.getPriority());
th11.start();
th22.start();
System.out.println( "main thread priority : "+ Thread.currentThread().getPriority());
}
}