-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmultithreading.java
More file actions
45 lines (43 loc) · 1.06 KB
/
multithreading.java
File metadata and controls
45 lines (43 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
import java.util.Random;
class x implements Runnable{
static int random;
Random rand = new Random();
@Override
public void run(){
random =rand.nextInt(10);
System.out.println(random);
}
}
class y implements Runnable{
@Override
public void run(){
if(x.random % 2 ==0){
System.out.println((int)Math.pow(x.random,2));
}
}
}
class z implements Runnable{
@Override
public void run(){
if(x.random % 2 !=0){
System.out.println((int)Math.pow(x.random,3));
}
}
}
public class multithreading {
public static void main(String[] args) {
for(int i=0;i<10;i++){
try {
Thread obj1=new Thread(new x());
Thread obj2=new Thread(new y());
Thread obj3=new Thread(new z());
obj1.start();
obj2.start();
obj3.start();
Thread.sleep(6000);
} catch (Exception e) {
System.out.println(e);
}
}
}
}