do I need to use synchronized on setvalue(int)? : Java thread



do I need to use synchronized on setvalue(int)? : Java thread..

Answer / Shashi Ranjan

"In this specific case, since there's no shared resource being manipulated, synchronization is not strictly required. However, for simplicity and safety, it might be beneficial to wrap the method in a synchronized block or use an atomic data type if the setValue() method is declared volatile."n

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More Core Java Interview Questions

What are command line arguments?

5 Answers  


what is recursion in java

1 Answers   Cap Gemini,


Explain about vector, dictionary,hash table, property classes?

1 Answers   Patni,


What is the difference between Static and final?

1 Answers  


What is the purpose of the enableevents() method in java programming?

1 Answers  


Can we declare variables inside a method as Final Variables?

3 Answers  


Can we nested try statements in java?

1 Answers  


What is method in java with example?

1 Answers  


What is use of super keyword in java?

1 Answers  


How many unicode characters are there?

1 Answers  


Tell me the Importent classes in net package?

1 Answers  


How do constructors use this() and super()?

1 Answers  


Categories