Given the following program, which alternatives would make good choices to synchronize on at (1)?
public class Preference { private int account1; private Integer account2; public void doIt() { final Double account3 = new Double(10e10); synchronized(/* ___(1)___ */) { System.out.print("doIt"); }/* w w w. j a v a 2 s . c o m*/ } }
Select the two correct answers.
(b) and (d)
We cannot synchronize on a primitive value.
Synchronizing on a local object is useless, as each thread will create its own local object and it will not be a shared resource.