File tree Expand file tree Collapse file tree 1 file changed +11
-6
lines changed
03concurrency/0301/src/main/java/java0/conc0303 Expand file tree Collapse file tree 1 file changed +11
-6
lines changed Original file line number Diff line number Diff line change 1
1
package java0 .conc0303 ;
2
2
3
+ /**
4
+ * 本周作业:(必做)思考有多少种方式,在main函数启动一个新线程或线程池,
5
+ * 异步运行一个方法,拿到这个方法的返回值后,退出主线程?
6
+ * 写出你的方法,越多越好,提交到github。
7
+ *
8
+ * 一个简单的代码参考:
9
+ */
3
10
public class Homework03 {
4
11
5
12
public static void main (String [] args ) {
6
13
14
+ long start =System .currentTimeMillis ();
7
15
// 在这里创建一个线程或线程池,
8
16
// 异步执行 下面方法
9
17
10
-
11
- long start =System .currentTimeMillis ();
12
-
13
18
int result = sum (); //这是得到的返回值
19
+
14
20
// 确保 拿到result 并输出
15
- System .out .println ("异步计算结果为:" +result );
16
-
21
+ System .out .println ("异步计算结果为:" +result );
17
22
18
- System .out .println ("使用时间:" + (System .currentTimeMillis ()-start ) + " ms" );
23
+ System .out .println ("使用时间:" + (System .currentTimeMillis ()-start ) + " ms" );
19
24
20
25
// 然后退出main线程
21
26
}
You can’t perform that action at this time.
0 commit comments