FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
java-basics/core-java/multithreading/ThreadPools.java at master · CodeForHunger/java-basics · GitHub
CodeForHunger
/
java-basics
Public
forked from
learning-zone/java-basics
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
java-basics
/
core-java
/
multithreading
/
ThreadPools.java
Copy path
More file actions
More file actions
Latest commit
History
History
History
51 lines (42 loc) · 1.22 KB
Breadcrumbs
java-basics
/
core-java
/
multithreading
/
ThreadPools.java
Copy path
File metadata and controls
51 lines (42 loc) · 1.22 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
package
multithreading
;
import
java
.
text
.
SimpleDateFormat
;
import
java
.
util
.
Date
;
import
java
.
util
.
concurrent
.
ExecutorService
;
import
java
.
util
.
concurrent
.
Executors
;
public
class
ThreadPools
implements
Runnable
{
private
String
name
;
public
ThreadPools
(
String
s
) {
name
=
s
;
}
public
void
run
() {
try
{
for
(
int
i
=
0
;
i
<
3
;
i
++) {
if
(
i
==
0
) {
Date
d
=
new
Date
();
SimpleDateFormat
ft
=
new
SimpleDateFormat
(
"hh:mm:ss"
);
System
.
out
.
println
(
"Initialization Time for task name: "
+
name
+
" = "
+
ft
.
format
(
d
));
}
else
{
Date
d
=
new
Date
();
SimpleDateFormat
ft
=
new
SimpleDateFormat
(
"hh:mm:ss"
);
System
.
out
.
println
(
"Executing Time for task name: "
+
name
+
" = "
+
ft
.
format
(
d
));
}
Thread
.
sleep
(
1000
);
}
System
.
out
.
println
(
name
+
" completed"
);
}
catch
(
Exception
e
) {
e
.
printStackTrace
();
}
}
public
static
void
main
(
String
[]
args
) {
final
int
MAX_T
=
3
;
Runnable
r1
=
new
ThreadPools
(
"task 1"
);
Runnable
r2
=
new
ThreadPools
(
"task 2"
);
Runnable
r3
=
new
ThreadPools
(
"task 3"
);
// Create a thread pool
ExecutorService
pool
=
Executors
.
newFixedThreadPool
(
MAX_T
);
pool
.
execute
(
r1
);
pool
.
execute
(
r2
);
pool
.
execute
(
r3
);
pool
.
shutdown
();
}
}
Back
|
FazBrowse Home
|
New Git URL