FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
java-programs/Multithread_Application/mul.java at main · IntScription/java-programs · GitHub
IntScription
/
java-programs
Public
Notifications
You must be signed in to change notification settings
Fork
0
Star
1
Code
Issues
0
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
java-programs
/
Multithread_Application
/
mul.java
Copy path
More file actions
More file actions
Latest commit
History
History
History
62 lines (57 loc) · 1.26 KB
Breadcrumbs
java-programs
/
Multithread_Application
/
mul.java
Copy path
File metadata and controls
62 lines (57 loc) · 1.26 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
/*
Write a Java program that implements a multithreaded application that has three threads.
First thread generates a random integer for every 1 second;
second thread computes the square of the number and prints;
third thread will print the value the cube of the number.
*/
package
Multithread_Application
;
import
java
.
util
.*;
class
Square
extends
Thread
{
private
int
num
;
Square
(
int
n
){
num
=
n
;
}
public
void
printSquare
() {
System
.
out
.
println
(
"Square of "
+
num
+
" is "
+ (
num
*
num
));
}
public
void
run
() {
printSquare
();
}
}
class
Cube
extends
Thread
{
private
int
num
;
Cube
(
int
n
){
num
=
n
;
}
public
void
printCube
() {
System
.
out
.
println
(
"Cube of "
+
num
+
" is "
+ (
num
*
num
*
num
));
}
public
void
run
() {
printCube
();
}
}
class
RandInt
extends
Thread
{
public
void
printRandom
()
throws
InterruptedException
{
Random
rd
=
new
Random
();
while
(
true
) {
int
rnum
=
rd
.
nextInt
(
10
);
System
.
out
.
println
(
"Random Number is"
+
rnum
);
Thread
.
sleep
(
3000
);
Square
s
=
new
Square
(
rnum
);
Cube
c
=
new
Cube
(
rnum
);
s
.
start
();
c
.
start
();
}
}
public
void
run
() {
try
{
printRandom
();
}
catch
(
InterruptedException
e
) {}
}
}
public
class
mul
{
public
static
void
main
(
String
[]
args
) {
RandInt
ob1
=
new
RandInt
();
ob1
.
start
();
}
}
Back
|
FazBrowse Home
|
New Git URL