Skip to content

Instantly share code, notes, and snippets.

@ivanursul
Created June 29, 2016 17:18
Show Gist options
  • Save ivanursul/8b6561a0cd9c0604f80e0b861502389d to your computer and use it in GitHub Desktop.
Save ivanursul/8b6561a0cd9c0604f80e0b861502389d to your computer and use it in GitHub Desktop.
import org.apache.commons.io.IOUtils;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.stream.Collectors;
import java.util.stream.Stream;
public class Main {
public static void main(String[] args) {
String string = Stream.iterate(1L, n -> n + 1)
.limit(10000)
.map(n -> String.format("Number%d", n))
.collect(Collectors.joining(" "));
try (InputStream is = new ByteArrayInputStream(string.getBytes())) {
doSomething(is);
} catch (IOException e) {
e.printStackTrace();
}
}
private static void doSomething(InputStream is) {
try {
String line = IOUtils.toString(is);
System.out.println("main thread line: " + line);
} catch (IOException e) {
e.printStackTrace();
}
Thread t1 = new Thread(() -> {
try {
String line = IOUtils.toString(is);
System.out.println("t1 line: " + line);
} catch (IOException e) {
e.printStackTrace();
}
});
t1.start();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment