2 Questions:
- str field is shared between two instance of A type [line 2]
- What's implications according to following code ?
class A implements Runnable {
String str = "hello"; // line 2.
public void run(){
Synchronized(str){
System.out.println(str+" "+Thread.currentThread().getName());
Thread.sleep(100);
System.out.println(str+" "+Thread.currentThread().getName());
//anything
}
}
public void static main(String[] args){
Thread one = new Thread(new A(),"one").start();
Thread two = new Thread(new A(),"two").start();
}}