FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
myJava/src/com/myJava/concurrency/FutureTaskTest.java at master · zhyhooo/myJava · GitHub
zhyhooo
/
myJava
Public
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
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
myJava
/
src
/
com
/
myJava
/
concurrency
/
FutureTaskTest.java
Copy path
More file actions
More file actions
Latest commit
History
History
History
43 lines (35 loc) · 1.09 KB
Breadcrumbs
myJava
/
src
/
com
/
myJava
/
concurrency
/
FutureTaskTest.java
Copy path
File metadata and controls
43 lines (35 loc) · 1.09 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
package
com
.
myJava
.
concurrency
;
import
java
.
util
.
Random
;
import
java
.
util
.
concurrent
.
Callable
;
import
java
.
util
.
concurrent
.
ExecutionException
;
import
java
.
util
.
concurrent
.
FutureTask
;
public
class
FutureTaskTest
{
public
static
void
main
(
String
[]
args
) {
// TODO Auto-generated method stub
DiceCallable
dice
=
new
DiceCallable
();
FutureTask
<
Integer
>
future
=
new
FutureTask
<
Integer
>(
dice
);
new
Thread
(
future
).
start
();
try
{
System
.
out
.
println
(
"This is main thread..."
);
Thread
.
sleep
(
5000
);
//do sth
System
.
out
.
println
(
future
.
get
());
}
catch
(
InterruptedException
e
) {
// TODO Auto-generated catch block
e
.
printStackTrace
();
}
catch
(
ExecutionException
e
) {
// TODO Auto-generated catch block
e
.
printStackTrace
();
}
}
}
class
DiceCallable
implements
Callable
<
Integer
> {
@
Override
public
Integer
call
()
throws
Exception
{
// TODO Auto-generated method stub
int
x
=
new
Random
().
nextInt
(
100
);
System
.
out
.
println
(
"start new thread..."
);
Thread
.
sleep
(
3000
);
System
.
out
.
println
(
"new thread end..."
);
return
x
;
}
}
Back
|
FazBrowse Home
|
New Git URL