Java Programming
Accenture PrimermediumJava Programming4. Arrays And Strings

Accenture Java Programming Practice Question

Given: 1. public class MyLogger { 2. private StringBuilder logger = new StringBuuilder(); 3. public void log(String message, String user) { 4. logger.append(message); 5. logger.append(user); 6. } 7. } The programmer must guarantee that a single MyLogger object works properly for a multi-threaded system. How must this code be changed to be thread-safe?

Answer options

A
Replace StringBuilder with just a String object and use the string concatenation (+=) within the log metho
B
Synchronize the log method
C
Replace StringBuilder with StringBuffer
D
No change is necessary, the current MyLogger code is already thread-saf

Correct answer: Replace StringBuilder with StringBuffer

Explanation

Correct answer: Replace StringBuilder with StringBuffer.

Related Accenture Java Programming questions

Practice more Accenture Java Programming questions

PrimerDumps has 1400+ primer questions, 2026 mocks and coding hands-on — all free.