-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJava_Threads.java
More file actions
32 lines (28 loc) · 849 Bytes
/
Java_Threads.java
File metadata and controls
32 lines (28 loc) · 849 Bytes
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
import java.util.*;
class NewRunnableClass implements Runnable{
int v=0;
NewRunnableClass(int i){
v=i;
}
@Override
public synchronized void run() {
System.out.println("Thread "+v + " "+System.currentTimeMillis());
}
}
class Java_Threads{
public static void main(String [] ags){
Thread[] tarr = new Thread[3];
for(int i=1;i<4;i++){
NewRunnableClass temp = new NewRunnableClass(i);
tarr[i-1] = new Thread(temp);
}
for(int i=0;i<3;i++){
System.out.println((double)System.currentTimeMillis()/1000);
tarr[i].start();
}
}
}
// Thread in array format
// Thread class extension VS Runnable interface impl
// return in try catch finally
// Synchronize method attribute with threads