Skip to content

Commit 46835e7

Browse files
committed
add homework 0303
1 parent 5080e60 commit 46835e7

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

03concurrency/0301/src/main/java/java0/conc0303/Homework03.java

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,26 @@
11
package java0.conc0303;
22

3+
/**
4+
* 本周作业:(必做)思考有多少种方式,在main函数启动一个新线程或线程池,
5+
* 异步运行一个方法,拿到这个方法的返回值后,退出主线程?
6+
* 写出你的方法,越多越好,提交到github。
7+
*
8+
* 一个简单的代码参考:
9+
*/
310
public class Homework03 {
411

512
public static void main(String[] args) {
613

14+
long start=System.currentTimeMillis();
715
// 在这里创建一个线程或线程池,
816
// 异步执行 下面方法
917

10-
11-
long start=System.currentTimeMillis();
12-
1318
int result = sum(); //这是得到的返回值
19+
1420
// 确保 拿到result 并输出
15-
System.out.println("异步计算结果为:"+result);
16-
21+
System.out.println("异步计算结果为:"+result);
1722

18-
System.out.println("使用时间:"+ (System.currentTimeMillis()-start) + " ms");
23+
System.out.println("使用时间:"+ (System.currentTimeMillis()-start) + " ms");
1924

2025
// 然后退出main线程
2126
}

0 commit comments

Comments
 (0)