-
Notifications
You must be signed in to change notification settings - Fork 70
/
Copy pathMainProgram.java
65 lines (52 loc) · 1.4 KB
/
MainProgram.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
package com.cdac.collections.threadsafe;
import java.util.ArrayList;
// import com.cdac.collections.bean.Student;
// Applying move method run to main program, decreases the complexity of tread running
public class MainProgram implements Runnable
{
public static void main(String[] args) throws CloneNotSupportedException {
Thread t1 = new Thread();
Thread t2 = new Thread();
t1.start();
t2.start();
ArrayList<String> list = new ArrayList<>();
EmployeeRunnable employeeRunnable = new EmployeeRunnable(list);
StudentRunnable studentRunnable = new StudentRunnable(list);
}
public void run()
{
ArrayList<String> Employeenames = null;
ArrayList<String> Studentnames = null;
for(int i=0;i<100;i++)
{
Employeenames.add("Employee :: "+i);
}
for(int j =100; j<200;j++)
{
Studentnames.add("Student :: "+j);
}
}
}
// class EmployeeRunnable implements Runnable
// {
// ArrayList<String> names;
// public EmployeeRunnable(ArrayList<String> list) {
// this.names = list;
// }
// @Override
// public void run() {
// for(int i=0;i<100;i++)
// names.add("Employee :: "+i);
// }
// }
// class StudentRunnable implements Runnable
// {
// ArrayList<String> names;
// public StudentRunnable(ArrayList<String> list) {
// this.names = list;
// }
// @Override
// public void run() {
// for(int i=100;i<200;i++)
// names.add("Student :: "+i);
// }