Or do I need a lock to print synchronous output to the screen?
e.g.
//Main
public static void main(String[] args) {
MyThread myThread1 = new MyThread();
MyThread myThread2 = new MyThread();
Thread thread1 = new Thread(myThread1);
Thread thread2 = new Thread(myThread2);
thread1.start();
thread2.start();
}
//Custom thread
public class MyThread() {
public void run() {
System.out.println("Is this method a shared resource that needs to be locked?");
}
}
Will the above be susceptible to race conditions? Or is System.out.println()
implemented with synchronization?