提交 cd9890f8 编写于 作者: M Mars Liu

reflection for orders

上级 d0b99132
{
"type": "code_options",
"author": "clong",
"source": "ScheduledExecutor.md",
"exercise_id": "",
"notebook_enable": true
}
\ No newline at end of file
# ScheduledExecutor
项目中经常与遇到定时执行任务的情况,可以使用 `ScheduledExecutor` 来实现,以下代码运行后制台输出正确的是:
```java
import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
class Task implements Runnable {
private String name;
public Task(String name) {
this.name = name;
}
@Override
public void run() {
System.out.println(name);
}
}
public class ScheduledExecutorTest {
public static void main(String[] args) {
ScheduledThreadPoolExecutor schedule = new ScheduledThreadPoolExecutor(10);
for (int i = 5; i > 0; i--) {
Task worker = new Task("task-" + i);
schedule.schedule(worker, i*2, TimeUnit.SECONDS);
}
}
}
```
## 答案
```
task-1
task-2
task-3
task-4
task-5
```
## 选项
### A
```
task-5
task-4
task-3
task-2
task-1
```
### B
```
task-5
task-4
task-1
task-2
task-3
```
### C
```
task-1
task-2
task-3
task-5
task-4
```
{
"node_id": "java-5a49d27c4caa4300936968edb642186c",
"keywords": ["CountDownLatch", "CyclicBarrier", "DelayQueue", "PriorityBlockingQueue", "ScheduledExecutor", "Semaphore", "Exchanger"],
"children": [
{
"CountDownLatch": {
"keywords": [],
"children": [],
"node_id": "java-9a7cb3066def45889807e133e5eb7736",
"title": "CountDownLatch"
}
},
{
"CyclicBarrier": {
"keywords": [],
"children": [],
"node_id": "java-626f8873229c4ebcbf9535893b3a2636",
"title": "CyclicBarrier"
}
},
{
"DelayQueue": {
"keywords": [],
"children": [],
"node_id": "java-d78ab239f1af4ea9a947bb073e25466f",
"title": "DelayQueue"
}
},
{
"PriorityBlockingQueue": {
"keywords": [],
"children": [],
"node_id": "java-ba4040d7af8d408aa6f26827ce977b93",
"title": "PriorityBlockingQueue"
}
},
{
"ScheduledExecutor": {
"keywords": [],
"children": [],
"node_id": "java-7a2655c558a94868acfd5c47605c19df",
"title": "ScheduledExecutor"
}
},
{
"Semaphore": {
"keywords": [],
"children": [],
"node_id": "java-c696f5c80c8f49eab7d45be97d02a9b4",
"title": "Semaphore"
}
},
{
"Exchanger": {
"keywords": [],
"children": [],
"node_id": "java-0b97e56a58b94d2da9dd53bb9b1baac6",
"title": "Exchanger"
}
}
],
"export": ["ScheduledExecutorTest.json"],
"title": "新类库中的构件"
}
\ No newline at end of file
......@@ -3760,21 +3760,6 @@
]
}
},
{
"新类库中的构件": {
"node_id": "java-5a49d27c4caa4300936968edb642186c",
"keywords": [
"CountDownLatch",
"CyclicBarrier",
"DelayQueue",
"PriorityBlockingQueue",
"ScheduledExecutor",
"Semaphore",
"Exchanger"
],
"children": []
}
},
{
"注解": {
"node_id": "java-baada6303aca42f0b2f7882a3446fdf9",
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册