试题详情
单项选择题 public class MyLogger {  private StringBuilder logger = new StringBuuilder();  public void log(String message, String user) {  logger.append(message);  logger.append(user);  }  }  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?() 

A、 synchronize the log method

B、 replace StringBuilder with StringBuffer

C、 No change is necessary, the current MyLogger code is already thread-safe.

D、 replace StringBuilder with just a String object and use the string concatenation (+=) within the log method

  • A
  • 关注下方微信公众号,在线模考后查看

热门试题