提交 8f066970 编写于 作者: CSDN-Ada助手's avatar CSDN-Ada助手

12章题目

上级 391bce2c
{
"type": "code_options",
"author": "clong",
"source": "Apt.md",
"exercise_id": "",
"notebook_enable": true
}
\ No newline at end of file
# Annotation Processing Tool
下列关于 `APT(Annotation Processing Tool)` 的说法正确的是:
## 答案
```
以上说法均正确
```
## 选项
### A
```
注解处理器,是javac的一种处理注释的工具
```
### B
```
自定义处理器都需要继承AbstractProcessor
```
### C
```
APT能够在编译期通过处理注解,生成我们想要的文件
```
{
"node_id": "java-8b0806d4d89948598ac95e5c19b53298",
"keywords": [],
"children": [],
"export": ["apt.json"],
"title": "使用apt处理注解"
}
\ No newline at end of file
{
"node_id": "java-a569056217524d5a8b6ed88fd678b73d",
"keywords": [],
"children": [
{
"Maven介绍": {
"keywords": [],
"children": [],
"node_id": "java-1fbf8f4636ed479aa87548441295c562",
"title": "Maven介绍"
}
},
{
"依赖管理": {
"keywords": [],
"children": [],
"node_id": "java-76e9c3885d4145368c052419f60ecdb5",
"title": "依赖管理"
}
},
{
"使用插件": {
"keywords": [],
"children": [],
"node_id": "java-43be29e168624aff939849f39630bca6",
"title": "使用插件"
}
},
{
"模块管理": {
"keywords": [],
"children": [],
"node_id": "java-7b68f372c5e1489fa451ea520fef7d12",
"title": "模块管理"
}
},
{
"使用mvnw": {
"keywords": [],
"children": [],
"node_id": "java-bc7e72cfd9794593a8043aea050cb8ec",
"title": "使用mvnw"
}
},
{
"发布Artifact": {
"keywords": [],
"children": [],
"export": [],
"node_id": "java-333c0931793049eabb069ae08e5c92d9",
"title": "发布Artifact"
}
}
],
"export": ["MavenDesc.json", "MavenScript.json"],
"title": "Maven基础"
}
\ No newline at end of file
{
"type": "code_options",
"author": "clong",
"source": "Abstract.md",
"exercise_id": "",
"notebook_enable": true
}
\ No newline at end of file
# 并发的定义
下列关于并发和并行的说法正确的是:
## 答案
```
并发的多个任务轮流使用CPU
```
## 选项
### A
```
并发是指同一时刻多个任务同时执行
```
### B
```
并行是指同一时间段多个任务同时执行
```
### C
```
单处理器不存在并行
```
{
"node_id": "java-66090dfe673e48a5a14c6ee846c4fc97",
"keywords": [],
"children": [
{
"更快的执行": {
"keywords": [],
"children": [],
"node_id": "java-4f4e7e1bf6714da0a24705e5cb433e71",
"title": "更快的执行"
}
},
{
"改进代码设计": {
"keywords": [],
"children": [],
"node_id": "569d5e11c4fc5de7844053d9a733c5e8",
"title": "改进代码设计"
}
}
],
"export": ["Abstract.json"],
"title": "并发的定义"
}
\ No newline at end of file
{
"type": "code_options",
"author": "clong",
"source": "Thread.md",
"exercise_id": "",
"notebook_enable": true
}
\ No newline at end of file
# 多线程
下列关于线程的说法错误的是:
## 答案
```
t.join()方法会使其他线程等待t线程执行完毕后才会被唤醒
```
## 选项
### A
```
thread.setDaemon(true)
可以用来设置守护线程
```
### B
```
start()方法可以用来启动一个线程
```
### C
```
线程可以共享资源,因此要注意线程安全问题
```
{
"node_id": "java-785476f0c71e437cadeb502a74dd86ed",
"keywords": [],
"children": [
{
"中断线程": {
"keywords": [],
"children": [],
"node_id": "java-689a856b2abb4cbb93fe6252c2eab816",
"title": "中断线程"
}
},
{
"守护线程": {
"keywords": [],
"children": [],
"node_id": "569d5e11c4fc5de7844053d9a733c5e8",
"title": "守护线程"
}
},
{
"线程名": {
"keywords": [],
"children": [],
"node_id": "569d5e11c4fc5de7844053d9a733c5e8",
"title": "线程名"
}
},
{
"未捕获异常的处理器": {
"keywords": [],
"children": [],
"node_id": "569d5e11c4fc5de7844053d9a733c5e8"
}
}
],
"export": ["Thread.json"],
"title": "线程属性"
}
\ No newline at end of file
{
"type": "code_options",
"author": "clong",
"source": "ThreadStatus.md",
"exercise_id": "",
"notebook_enable": true
}
\ No newline at end of file
# 线程状态
下列关于线程状态的说法错误的是:
## 答案
```
当前线程调用sleep(),进入超时等待状态,并释放对象锁
```
## 选项
### A
```
java线程的状态有5种:新建状态、就绪状态、运行状态、阻塞状态、死亡状态
```
### B
```
当前线程调用wait(),释放对象锁,进入等待队列
```
### C
```
当前线程调用yield(),由运行状态变成就绪状态
```
{
"node_id": "java-7a4a0e08d7424b5896f2325f732bdeee",
"keywords": [],
"children": [
{
"新建线程": {
"keywords": [],
"children": [],
"node_id": "java-f1fece37484743eeab27863607dd9fde",
"title": "新建线程"
}
},
{
"可运行线程": {
"keywords": [],
"children": [],
"node_id": "569d5e11c4fc5de7844053d9a733c5e8",
"title": "可运行线程"
}
},
{
"阻塞和等待线程": {
"keywords": [],
"children": [],
"node_id": "569d5e11c4fc5de7844053d9a733c5e8",
"title": "阻塞和等待线程"
}
},
{
"终止线程": {
"keywords": [],
"children": [],
"node_id": "569d5e11c4fc5de7844053d9a733c5e8"
}
}
],
"export": ["ThreadStatus.json"],
"title": "线程状态"
}
\ No newline at end of file
{
"type": "code_options",
"author": "clong",
"source": "ProductorAndConsumer.md",
"exercise_id": "",
"notebook_enable": true
}
\ No newline at end of file
# 生产者消费者
生产者消费者是软件开发者经常会用到的一种模式,以下代码是一种简单的实现:
```java
class Producter extends Thread {
private BlockingQueue<String> queue;
private String name;
public Producter(String name, BlockingQueue<String> queue) {
this.name = name;
this.queue = queue;
}
@Override
public void run() {
for (int i = 0; i < 3; i++) {
queue.add(name + i);
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}
class Consumer extends Thread {
private BlockingQueue<String> queue;
public Consumer(BlockingQueue<String> queue) {
this.queue = queue;
}
@Override
public void run() {
while (true) {
if (queue.size() > 0) {
String task = queue.poll();
System.out.println(task);
}
}
}
}
public class ThreadTest {
public static void main(String[] args) {
BlockingQueue<String> queue = new LinkedBlockingQueue<String>(20);
// 1
}
}
```
要输出的结果为
```
b0
b1
b2
a0
a1
a2
```
则1处的代码可以是下列选项中的哪一个?
## 答案
```
new Producter("b", queue).start();
try {
Thread.sleep(7000);
} catch (InterruptedException e) {
e.printStackTrace();
}
new Producter("a", queue).start();
new Consumer(queue).start();
```
## 选项
### A
```
new Producter("b", queue).start();
new Producter("a", queue).start();
new Consumer(queue).start();
```
### B
```
new Producter("b", queue).start();
new Consumer(queue).start();
new Producter("a", queue).start();
```
### C
```
new Producter("b", queue).start();
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
e.printStackTrace();
}
new Producter("a", queue).start();
new Consumer(queue).start();
```
{
"node_id": "java-5e82993df31e4989ac4b128c08cf0823",
"keywords": [],
"children": [
{
"wait()与notifyAll()": {
"keywords": [],
"children": [],
"node_id": "java-5c28af969c6b4771825c907aac1480b0",
"title": "wait()与notifyAll()"
}
},
{
"notify()与notifyAll()": {
"keywords": [],
"children": [],
"node_id": "569d5e11c4fc5de7844053d9a733c5e8",
"title": "notify()与notifyAll()"
}
},
{
"生产者与消费者": {
"keywords": [],
"children": [],
"node_id": "569d5e11c4fc5de7844053d9a733c5e8",
"title": "生产者与消费者"
}
},
{
"任务间使用管道进行输入输出": {
"keywords": [],
"children": [],
"node_id": "569d5e11c4fc5de7844053d9a733c5e8"
}
}
],
"export": ["ProductorAndConsumer.json"],
"title": "线程之间的协作"
}
\ No newline at end of file
{
"type": "code_options",
"author": "clong",
"source": "DeakLock.md",
"exercise_id": "",
"notebook_enable": true
}
\ No newline at end of file
# DeadLock
两个线程分别运行以下代码的eatDrink和drinkEat, 会不会发生死锁:
```java
public class DeadLock {
private final String eat = "吃饭";
private final String drink = "喝水";
public void eatDrink() {
synchronized (eat) {
try {
Thread.sleep(3000);
} catch (InterruptedException e) {
e.printStackTrace();
}
synchronized (drink) {
// doSomething
}
}
}
public void drinkEat() {
synchronized (drink) {
try {
Thread.sleep(3000);
} catch (InterruptedException e) {
e.printStackTrace();
}
synchronized (eat) {
// doSomething
}
}
}
}
```
## 答案
```
```
## 选项
### A
```
不会
```
{
"node_id": "java-372114d043a04070ad690f2753b5083b",
"keywords": [],
"children": [],
"export": ["DeakLock.json"],
"title": "死锁"
}
\ No newline at end of file
{
"type": "code_options",
"author": "clong",
"source": "ThreadSafe.md",
"exercise_id": "",
"notebook_enable": true
}
\ No newline at end of file
# 集合线程安全
下列关于集合的线程安全说法错误的是:
## 答案
```
单线程里面使用hashmap同样需要加锁
```
## 选项
### A
```
Collections针对每种集合提供了一种线程安全的包装类
```
### B
```
java.util.concurrent包中的集合也是线程安全的
```
### C
```
java.util.concurrent包优化了加锁的位置,粒度更细,避免锁住整个对象
```
{
"node_id": "java-aa0b95d8960b4d12a2c9d9e90894a793",
"keywords": [],
"children": [
{
"阻塞队列": {
"keywords": [],
"children": [],
"node_id": "java-cc7d9f6eee604e51ad6efead3710b3ab",
"title": "阻塞队列"
}
},
{
"映射条目的原子更新": {
"keywords": [],
"children": [],
"node_id": "569d5e11c4fc5de7844053d9a733c5e8",
"title": "映射条目的原子更新"
}
},
{
"对并发散列映射的批操作": {
"keywords": [],
"children": [],
"node_id": "569d5e11c4fc5de7844053d9a733c5e8",
"title": "对并发散列映射的批操作"
}
},
{
"并发集视图": {
"keywords": [],
"children": [],
"node_id": "569d5e11c4fc5de7844053d9a733c5e8"
}
},
{
"写数组的拷贝": {
"keywords": [],
"children": [],
"node_id": "569d5e11c4fc5de7844053d9a733c5e8"
}
},
{
"并行数组算法": {
"keywords": [],
"children": [],
"node_id": "569d5e11c4fc5de7844053d9a733c5e8"
}
},
{
"较早的线程安全集合": {
"keywords": [],
"children": [],
"node_id": "569d5e11c4fc5de7844053d9a733c5e8"
}
}
],
"export": ["ThreadSafe.json"],
"title": "线程安全的集合"
}
\ No newline at end of file
{
"type": "code_options",
"author": "clong",
"source": "MavenDesc.md",
"exercise_id": "",
"notebook_enable": true
}
\ No newline at end of file
# Maven
以下关于 `Maven` 的说法正确的是:
## 答案
```
以上说法均正确
```
## 选项
### A
```
maven是一个项目管理工具
```
### B
```
maven可以管理项目中的依赖
```
### C
```
maven项目中的pom.xml文件是项目的配置文件
```
{
"type": "code_options",
"author": "clong",
"source": "MavenScript.md",
"exercise_id": "",
"notebook_enable": true
}
\ No newline at end of file
# Maven
以下关于 `Maven` 命令的说法不正确的是:
## 答案
```
mvn test package 运行测试,并打包发布到仓库
```
## 选项
### A
```
mvn compile用于编译源代码
```
### B
```
mvn install 安装项目到本地仓库
```
### C
```
mvn archetype:generate 生成maven项目
```
{
"node_id": "java-baada6303aca42f0b2f7882a3446fdf9",
"keywords": [],
"children": [
{
"压缩文件": {
"keywords": [],
"children": [],
"node_id": "java-67a3780782984dea9eb79248c0fae05c",
"title": "压缩文件"
}
},
{
"解压缩ZIP文件": {
"keywords": [],
"children": [],
"node_id": "569d5e11c4fc5de7844053d9a733c5e8",
"title": "解压缩ZIP文件"
}
}
],
"export": [],
"title": "注解"
}
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册