码头优先治疗健康检查?

时间:2018-05-21 19:12:28

标签: jetty health-monitoring

My Jetty正在为/ myservice / *

提供服务

我的问题是,当服务器的队列变满时,/ healthcheck上的运行状况检查请求开始失败。

是否可以为我的运行状况检查设置单独的队列,还是有其他方法可以执行此操作?import java.io.IOException;

以下是一个示例服务器:

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.servlet.ServletHandler;
import org.eclipse.jetty.util.thread.QueuedThreadPool;

/**
 * Based on:
 * https://www.eclipse.org/jetty/documentation/9.4.x/embedded-examples.html
 */
public class HealthCheckServer
{
    public static void main( String[] args ) throws Exception
    {
        Server server = new Server(8086);

        QueuedThreadPool qtp = (QueuedThreadPool) server.getThreadPool();
        qtp.setMaxThreads(6);

        ServletHandler handler = new ServletHandler();
        server.setHandler(handler);


        handler.addServletWithMapping(HelloServlet.class, "/hello");
        handler.addServletWithMapping(HealthServlet.class, "/health");

        server.start();

        server.join();
    }

    @SuppressWarnings("serial")
    public static class HelloServlet extends HttpServlet
    {
        @Override
        protected void doGet( HttpServletRequest request,
                              HttpServletResponse response ) throws ServletException,
                                                            IOException
        {
            try {
                Thread.sleep(10*1000); // 10 sec
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            response.setContentType("text/html");
            response.setStatus(HttpServletResponse.SC_OK);
            response.getWriter().println("<h1>Hello from HelloServlet</h1>");
        }
    }

    @SuppressWarnings("serial")
    public static class HealthServlet extends HttpServlet
    {
        @Override
        protected void doGet( HttpServletRequest request,
                              HttpServletResponse response ) throws ServletException,
                                                            IOException
        {
            response.setContentType("text/html");
            response.setStatus(HttpServletResponse.SC_OK);
            response.getWriter().println("all good captain");
        }
    }
}

如果您点击http://localhost:8086/hello 4次,则http://localhost:8086/health将无法响应。

0 个答案:

没有答案