I am trying to find the fastest way and less complicated way to perform some union / exclude / intersection operations on Java SE 8 threads.
I'm doing it:
Stream<String> fruitStream = Stream.of("apple", "banana", "pear", "kiwi", "orange");
Stream<String> fruitStream2 = Stream.of("orange", "kiwi", "melon", "apple", "watermelon");
//Trying to create exclude operation
fruitStream.filter(
item -> !fruitStream2.anyMatch(item2 -> item2.equals(item)))
.forEach(System.out::println);
// Expected result: fruitStream - fruitStream2: ["banana","pear"]
I get the following exception:
java.lang.IllegalStateException: thread is already running or closed
If I could perform this operation, I could develop everything else, union, intersection, etc.
So, 2 points:
1) What am I doing wrong in this decision to get this exception?
2) Is there a less complicated way to perform operations between two threads?
Note
I want to use streams to find out about them. Do not want to convert them to arrays or lists.
source
share