Skip to content

提交了修改#65

Open
KAIQIANG-LIU wants to merge 4 commits intomasterfrom
zaker-branch
Open

提交了修改#65
KAIQIANG-LIU wants to merge 4 commits intomasterfrom
zaker-branch

Conversation

@KAIQIANG-LIU
Copy link

  • 这个PR解答了当前仓库中的题目(机器人会自动判题并合并当前PR)
  • 这个PR修复了当前仓库中的一些代码缺陷(机器人不会判题,而是由管理员来处理当前PR)

@hcsp-bot
Copy link
Contributor

🎉 感谢提交Pull Request!请稍等片刻,我们已经将其提交到CI进行检查,一旦有结果会立即通知您!

@hcsp-bot
Copy link
Contributor

你的提交 90874bf ,似乎失败了:Your tests failed on CircleCI

😅 请不要气馁,仔细分析原因,再接再厉!

@hcsp-bot
Copy link
Contributor

你的提交 5387333 ,似乎失败了:Your tests failed on CircleCI

😅 请不要气馁,仔细分析原因,再接再厉!

@hcsp-bot
Copy link
Contributor

你的提交 0943fd9 ,似乎失败了:Your tests failed on CircleCI

😅 请不要气馁,仔细分析原因,再接再厉!

<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.1</version>
<configuration>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里为什么要去掉?

return countResult;
}

private static void mergeResulttoFinal(Map<String, Integer> waitforMerge, Map<String, Integer> countResult) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
private static void mergeResulttoFinal(Map<String, Integer> waitforMerge, Map<String, Integer> countResult) {
private static void mergeResultToFinal(Map<String, Integer> waitForMerge, Map<String, Integer> countResult) {

List<Map<String, Integer>> results = new ArrayList<>();
Map<String, Integer> countResult = new HashMap<>();
buildDetector(threadNum, files, results);
Thread.sleep(100);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

你怎么知道sleep 100毫秒就足够其他线程完成工作?


private static void buildDetector(int threadNum, List<File> files, List<Map<String, Integer>> results, CountDownLatch countDownLatch) {
for (int i = 0; i < threadNum; i++) {
new FileDetector(results, null, files.get(i), countDownLatch).start();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CountDownLatch在FileDetector里根本没用到,那传递进去干什么?

import java.util.Map;
import java.util.concurrent.CountDownLatch;

public class FileDetector extends Thread {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

名字取的不好,明明是读文件的,为啥叫Detector?我看了这个名字的第一反应是用来检测文件是不是存在的。

List<Map<String, Integer>> result;
Object object;
File file;
CountDownLatch countDownLatch;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个CountDownLatch到处都没用到,那它为什么存在?

final CountDownLatch countDownLatch = new CountDownLatch(threadNum);
List<Map<String, Integer>> results = new ArrayList<>();
Map<String, Integer> countResult = new HashMap<>();
buildDetector(threadNum, files, results, countDownLatch);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

我觉得你这里少了countDownLatch.await().

List<Map<String, Integer>> results = new ArrayList<>();
Map<String, Integer> countResult = new HashMap<>();
buildDetector(threadNum, files, results);
Thread.sleep(100);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

同上,为什么100毫秒就够了?假如正在处理的是很大的文件,100毫秒处理不完怎么办?这种拍脑袋的代码(“我猜100毫秒就够了”)请尽量少写。你需要的是正确的线程同步的方法,比如CountDownLatch,但是上面明明创建了CountDownLatch准备用,又没用到,我很迷惑不解。

List<Map<String, Integer>> results = new ArrayList<>();
Map<String, Integer> countResult = new HashMap<>();
buildDetector(threadNum, files, results);
Thread.sleep(100);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

同上。

@hcsp-bot hcsp-bot mentioned this pull request Jan 12, 2020
2 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants