-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprg7.java
More file actions
54 lines (47 loc) · 1.06 KB
/
prg7.java
File metadata and controls
54 lines (47 loc) · 1.06 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
53
54
//create two threads that access an one d array containing 10 to 100, thread 1 updates array by inc by 10 and thread 2 decremetns by 2
import java.util.*;
class inc extends Thread{
String t_name;
int[] arr=new int[91];
inc(String name,int[] arr){
this.arr=arr;
t_name=name;
}
public void run()
{
for(int i=0;i<91;i++)
{
arr[i]+=10;
System.out.println(arr[i]);
}
}
}
class dec extends Thread{
String t_name;
int[] arr=new int[91];
dec(String name,int[] arr){
this.arr=arr;
t_name=name;
}
public void run()
{
for(int i=0;i<91;i++)
{
arr[i]-=2;
}
}
}
public class prg7{
public static void main(String args[])
{
int[] arr= new int[91];
for(int i=0;i<91;i++)
arr[i]=i+10;
inc t= new inc("thread",arr);
dec t1=new dec("thread1",arr);
Thread th= new Thread(t);
Thread th1=new Thread(t1);
th.start();
th1.start();
}
}