Skip to content

多线程解决#139

Open
1104049235 wants to merge 1 commit into
hcsp:masterfrom
1104049235:master
Open

多线程解决#139
1104049235 wants to merge 1 commit into
hcsp:masterfrom
1104049235:master

Conversation

@1104049235

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

@hcsp-bot

Copy link
Copy Markdown
Contributor

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

@@ -1,12 +1,112 @@
package com.github.hcsp.multithread;

import com.sun.xml.internal.ws.addressing.WsaActionUtil;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

无用导入 - com.sun.xml.internal.ws.addressing.WsaActionUtil 。

ArrayList<Map<String, Integer>> maps = new ArrayList<>();
ConcurrentHashMap<String, Integer> map = new ConcurrentHashMap<>();
AtomicInteger nums = new AtomicInteger(0);
for (int i = 0; i<threadNum; i++){

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

'<' 后应有空格。
'<' 前应有空格。
'{' 前应有空格。

AtomicInteger nums = new AtomicInteger(0);
for (int i = 0; i<threadNum; i++){
Thread thread = new Thread(() -> {
synchronized (nums){

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

'{' 前应有空格。

Thread thread = new Thread(() -> {
synchronized (nums){
File file = files.get(nums.get());
if (nums.get() !=files.size()){

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

'!=' 后应有空格。
'{' 前应有空格。

thread.start();
}
//主线程等待执行
synchronized (nums){

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

'{' 前应有空格。


for (int i = 0; i<threadNum; i++){
Thread thread = new Thread(() -> {
synchronized (files){

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

'{' 前应有空格。

for (int i = 0; i<threadNum; i++){
Thread thread = new Thread(() -> {
synchronized (files){
System.out.println(""+(countDownLatch.getCount()));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

'+' 后应有空格。
'+' 前应有空格。

Thread thread = new Thread(() -> {
synchronized (files){
System.out.println(""+(countDownLatch.getCount()));
maps.add(MultiThreadWordCount1.merge(files.get((int) (countDownLatch.getCount()-1))));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

'-' 后应有空格。
'-' 前应有空格。

Set<String> strings = stringIntegerMap.keySet();
for (String string : strings) {
Integer num = map.putIfAbsent(string, stringIntegerMap.get(string));
if (num==null){

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

'==' 后应有空格。
'==' 前应有空格。
'{' 前应有空格。

map.put(string, stringIntegerMap.get(string));
} else {
//存在 相加
map.put(string, stringIntegerMap.get(string)+map.get(string));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

'+' 后应有空格。
'+' 前应有空格。

@hcsp-bot

Copy link
Copy Markdown
Contributor

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

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

1 similar comment
@hcsp-bot

Copy link
Copy Markdown
Contributor

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

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

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.

2 participants