When a Java program calls System.out.println () or a Scala program calls println (), is a thread block executed?
I am writing a Scala program with a huge number of subtasks. Each subtask is performed inside the Future. It is recommended that the code inside participants and futures not be blocked, so that subsequent tasks should also not wait. But I want to print on the console.
And if it's a lock operation: what can I do to optimize performance?
- Should I use a dedicated thread to output the console so that the thread is the only one that blocks?
- Any other tips?
Of course, I could try to reduce the output or collect some result in a StringBuilder and print it together in a batch, which reduces the number of output operations.
java multithreading scala nonblocking blocking
user573215
source share