Following example demonstrates how IO::readln and IO::println are mutually blocking and how IO.println behaved differently than System.out.println in multithreaded code.
```
static void doSomething() {
try {
Thread.sleep(1000);
} catch (InterruptedException ignore) {}
}
void main() {
Thread.ofVirtual().start(() -> {
while (true) {
doSomething();
System.out.println("I do something until you press Enter");
}
});
Thread.ofVirtual().start(() -> {
while (true) {
doSomething();
println("I'm blocked until you press Enter");
}
});
readln("");
}
```
```
static void doSomething() {
try {
Thread.sleep(1000);
} catch (InterruptedException ignore) {}
}
void main() {
Thread.ofVirtual().start(() -> {
while (true) {
doSomething();
System.out.println("I do something until you press Enter");
}
});
Thread.ofVirtual().start(() -> {
while (true) {
doSomething();
println("I'm blocked until you press Enter");
}
});
readln("");
}
```