dubbo SimpleMonitor写入日志细节

上报流程

		    private final ConcurrentMap> statisticsMap = new ConcurrentHashMap>();
    // 定时任务执行器
    private final ScheduledExecutorService scheduledExecutorService = Executors.newScheduledThreadPool(3, new NamedThreadFactory("DubboMonitorSendTimer", true));

		
		  this.monitorInterval = monitorInvoker.getUrl().getPositiveParameter("interval", 60000);
        // 启动统计信息收集定时器-每分钟上报一次
        sendFuture = scheduledExecutorService.scheduleWithFixedDelay(new Runnable() {
            public void run() {
                // 收集统计信息
                try {
                    send();
                } catch (Throwable t) { // 防御性容错
                    logger.error("Unexpected error occur at send statistic, cause: " + t.getMessage(), t);
                }
            }
        }, monitorInterval, monitorInterval, TimeUnit.MILLISECONDS);
		










写入流程

单例执行

    // 定时任务执行器
    private final ScheduledExecutorService scheduledExecutorService = Executors.newScheduledThreadPool(1, new NamedThreadFactory("DubboMonitorTimer", true)); 
	//阻塞队列
    private final BlockingQueue queue;

        //设置队列长度
        queue = new LinkedBlockingQueue(Integer.parseInt(ConfigUtils.getProperty("dubbo.monitor.queue", "100000")));
		
		//第一次延迟一秒执行,后边没300秒执行一次
        chartFuture = scheduledExecutorService.scheduleWithFixedDelay(new Runnable() {
            public void run() {
                try {
                    draw(); // 绘制图表
                } catch (Throwable t) { // 防御性容错
                    logger.error("Unexpected error occur at draw stat chart, cause: " + t.getMessage(), t);
                }
            }
        }, 1, 300, TimeUnit.SECONDS);


		
		//拿出
		queue.take();
		//放入
		queue.offer(statistics);
		















你可能感兴趣的:(java,架构设计)