广州某小公司:你是怎么理解多线程的?

// 请求直接交给线程池来处理
public void push(PushParam pushParam) {
    
    
  try {
    
    
    pushServiceThreadExecutor.submit(() -> {
    
    
      handler(pushParam);
    });
  } catch (Exception e) {
    
    
    logger.error("pushServiceThreadExecutor error, exception{}:", e);
  }
}

public class UnsafeCountingServlet extends GenericServlet implements Servlet {
    
    
    private long count = 0;

    public long getCount() {
    
    
        return count;
    }

    public void service(ServletRequest servletRequest, ServletResponse servletResponse) throws ServletException, IOException {
    
    

        ++count;
        // To something else...
    }
}

欢迎搜索【Java3y】来聊聊Java面试

【对线面试官】系列 一周两篇持续更新中!

Guess you like

Origin blog.csdn.net/Java_3y/article/details/118297607