欢迎来到易学考试网 易学考试官网
全部科目 > Java认证考试 > SCJP程序员认证考试

单项选择题

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

点击查看答案&解析

相关考题

微信小程序免费搜题
微信扫一扫,加关注免费搜题

微信扫一扫,加关注免费搜题