package com.bai.servlet;
import java.io.BufferedReader;
import java.io.IOException;
import java.util.Date;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.bai.vo.KaimenUtil;
/**
* Servlet implementation class RenlianApi
*/
@WebServlet("/RenlianApi")
public class RenlianApi extends HttpServlet {
private static final long serialVersionUID = 1L;
public ExecutorService fixedThreadPool = Executors.newFixedThreadPool(3);
/**
* @see HttpServlet#HttpServlet()
*/
public RenlianApi() {
super();
// TODO Auto-generated constructor stub
}
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
// response.getWriter().append("Served at: ").append(request.getContextPath());
System.out.println("doGet************************");
doPost(request, response);
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
// TODO Auto-generated method stub
System.out.println("doPost");
BufferedReader br=request.getReader();
String line=br.readLine();
System.out.println("line1:"+line+"----"+new Date().toGMTString());
// line:{"type":1,"data":"1224","time":1664258923,"deviceSn":"21C130006"}
this.fixedThreadPool.execute(new Runnable() {
public void run() {
KaimenUtil km=new KaimenUtil();
km.kaimen();
}
});
System.out.println("line2:"+line+"----"+new Date().toGMTString());
response.setCharacterEncoding("utf-8");
response.setContentType("application/json");
// response.getWriter().write("{\"code\":0}");
response.getWriter().write("{\"code\":0,\"message\":\"success\"}");
}
}
FixedThreadPool线程池executor
最新推荐文章于 2024-07-02 20:20:10 发布