- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSample15.java
More file actions
Latest commit
52 lines (44 loc) · 1.41 KB
/
Copy pathSample15.java
File metadata and controls
52 lines (44 loc) · 1.41 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
42
43
44
45
46
47
48
49
50
51
52
importjava.util.ArrayList;
importjava.util.Scanner;
publicclassSample15extendsThread
{
ArrayList<Integer> al=newArrayList<Integer>();
publicvoidadd(Integerx)
{
al.add(x);
System.out.println(al);
}
publicvoidremove( Integerx)
{
if(al.contains(x))
{
al.remove(x);
}
System.out.println(al);
}
publicvoidrun()
{
this.add(100);
this.remove(100);
}
publicstaticvoidmain(String[] args) throwsInterruptedException {// thread is a light weight component which perform unit of work
// because different objects of thread class contains same memory allocation.
Sample15obj=newSample15();
Sample15obj2=newSample15();
Sample15obj3=newSample15();
// System.out.println(obj.getName());
// System.out.println(obj.getId());
// System.out.println(obj.getPriority());
// obj.setName("New_Thread");
// System.out.println(obj.getName());
// System.out.println(obj.isAlive());
// System.out.println(obj.getName());
obj.start();
obj.setName("t1");
obj.join();
obj2.start();
obj2.setName("t2");
obj3.setName("t3");
obj3.start();
}
}