-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathThreadTest.java
More file actions
33 lines (28 loc) · 831 Bytes
/
ThreadTest.java
File metadata and controls
33 lines (28 loc) · 831 Bytes
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
package com.yb.thread;
import java.util.concurrent.CompletableFuture;
import org.junit.Test;
public class ThreadTest {
// @Test
public void RunnableImplementsTest() {
for (int i = 0; i < 10; i++) {
Runnable t = new RunnableImplements(i + "");
new Thread(t).start();
}
}
// @Test
public void ThreadExtendsTest() throws InterruptedException {
for (int i = 0; i < 10; i++) {
Thread t = new ThreadExtends(i + "");
t.start();
}
}
@Test
public void RunnableImplementsCompletableFutureTest() throws InterruptedException {
final CompletableFuture<Integer> future = new CompletableFuture<Integer>();
new Thread(new RunnableImplements(future,"ytain")).start();
// 模拟长时间的计算过程
Thread.sleep(1000);
// 告知完成结果
future.complete(60);
}
}