println("${Thread.currentThread().name} for $n after ${sleepTime}ms")
}.join()
➊
}
➊
使每个线程都等待前一个线程。
现在,输出将类似于以下内容:
Thread-0 for 0 after 687ms
Thread-1 for 1 after 661ms
Thread-2 for 2 after 430ms
Thread-3 for 3 after 412ms
Thread-4 for 4 after 918ms
Thread-5 for 5 after 755ms
当然,这消除了在第一处于线程内部运行的需要,但是它表明你可以在返回的线程上调
用方法。
参阅
第13 章讨论了并发的更多细节。
11.9
使用
TODO
强制完成
问题
如何保证你完成编写特定的功能或测试。
解决方案
如果还未完成某项功能,请使用TODO 函数(具有可选原因),该函数会引发异常。
讨论
开发人员经常给自己留下笔记,以记录他们目前尚无法完成的工作。在大多数语言中,
你可以在注释中添加“TODO”语句,如下例所示:
fun myCleverFunction() {
184
|
第
11
章
// TODO:
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month, and much more.
O’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
I wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
I’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
I'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.