-
Notifications
You must be signed in to change notification settings - Fork 0
/
Multithreading.java
74 lines (49 loc) · 1.4 KB
/
Multithreading.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import java.lang.Thread;
import java.lang.Runnable;
/*
public class MyClass extends Thread {
@Override
public void run(){
System.out.println("New thread created");
System.out.println("New thread created");
}
//main thread
public static void main(String args[]) {
MyClass obj = new MyClass();
obj.start();
System.out.println("Inside main thread");
}
}
*/
/*
public class MyClass implements Runnable {
@Override
public void run(){
System.out.println("New thread created");
System.out.println("New thread created");
}
//main thread
public static void main(String args[]) {
MyClass obj = new MyClass();
Thread thread = new Thread(obj);
thread.start();
System.out.println("Inside main thread");
}
}
*/
class Myclass{
//main thread
public static void main(String args[]) {
//Runnable obj = () -> System.out.println("Inside new thread");
Thread thread1 = new Thread(()->{
System.out.println("Inside thread 1");
});
Thread thread2 = new Thread(()->{
System.out.println("Inside thread 2");
});
thread2.setPriority(Thread.MAX_PRIORITY);
//thread.setDaemon(false);
thread1.start();
thread2.start();
}
}