-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCallingThread.java
49 lines (40 loc) · 1.23 KB
/
CallingThread.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
package com.basic.threading;
/**
*
* @author hp
*/
/* extends Thread and create a new Thread for supporting own functionality */
class HelloThread extends Thread{
public HelloThread() {
System.out.println(Thread.currentThread().getName());
}
/* run method execute all operation with a new thread */
public void run(){
System.out.println(Thread.currentThread().getName());
}
}
class Runner implements Runnable{
public void run(){
System.out.println(Thread.currentThread().getName());
}
}
public class CallingThread {
public static void main(String[] args) {
/* calling HelloThread extends of Thread */
Thread t1 = new HelloThread();
t1.setName("Hello Thread");
t1.start();
/* calling Runnable Runner in a Thread */
Thread t2 = new Thread(new Runner());
t2.setName("Runner Runnable");
t2.start();
/* calling anonymous Runnable in a Thread */
Thread t3 = new Thread(new Runnable(){
public void run(){
System.out.println(Thread.currentThread().getName());
}
});
t3.setName("anonymous Runnable");
t3.start();
}
}