Created
June 29, 2016 17:18
-
-
Save ivanursul/8b6561a0cd9c0604f80e0b861502389d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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