小编J J*_*ohn的帖子

为什么使用parallelStream访问和修改Collection得到不同的结果?

我对以下代码感到困惑

  public static void main(String[] args) throws InterruptedException
  {
    Integer[] intArray = {1, 2, 3, 4, 5, 6, 7, 8};
    List<Integer> listOfIntegers =
            new ArrayList<>(Arrays.asList(intArray));
    List<Integer> parallelStorage = new ArrayList<>();//Collections.synchronizedList(new ArrayList<>());
    listOfIntegers
            .parallelStream()
            // Don't do this! It uses a stateful lambda expression.
            .map(e -> {
                parallelStorage.add(e);
                return e;
            })
            .forEachOrdered(e -> System.out.print(e + " "));
    System.out.println();
    parallelStorage
            .stream()
            .forEachOrdered(e -> System.out.print(e + " "));
    System.out.println();
    System.out.println("Sleep 5 sec");
    TimeUnit.SECONDS.sleep(5);
    parallelStorage
            .stream()
            .forEachOrdered(e -> System.out.print(e + " "));
}
Run Code Online (Sandbox Code Playgroud)

EveryTime执行它我得到了不同的结果,这让我很困惑,这里有一些结果: …

java parallel-processing multithreading java-8

2
推荐指数
1
解决办法
925
查看次数

Git Bash无法初始化

在此输入图像描述

当我使用git bash时,它说"无法分叉子进程:资源暂时不可用.可能需要DLL rebasing.请参阅'rebaseall --help'." 我该如何解决这个问题?

当我使用tortoiseGit来存储时,我得到了一些这样的消息

> git.exe stash save -- "12"

0 [main] sh (7224) D:\Program Files (x86)\Git\usr\bin\sh.exe: *** fatal error - cygheap base mismatch detected - 0x1360400/0x12F0400.
This problem is probably due to using incompatible versions of the cygwin DLL.
Search for cygwin1.dll using the Windows Start->Find/Search facility
and delete all but the most recent version.  The most recent version *should*
reside in x:\cygwin\bin, where 'x' is the drive on which you have
installed the cygwin distribution.  Rebooting …
Run Code Online (Sandbox Code Playgroud)

git bash dll

1
推荐指数
2
解决办法
1万
查看次数

标签 统计

bash ×1

dll ×1

git ×1

java ×1

java-8 ×1

multithreading ×1

parallel-processing ×1