001/**
002 * Logback: the reliable, generic, fast and flexible logging framework.
003 * Copyright (C) 1999-2015, QOS.ch. All rights reserved.
004 *
005 * This program and the accompanying materials are dual-licensed under
006 * either the terms of the Eclipse Public License v1.0 as published by
007 * the Eclipse Foundation
008 *
009 *   or (per the licensee's choosing)
010 *
011 * under the terms of the GNU Lesser General Public License version 2.1
012 * as published by the Free Software Foundation.
013 */
014package ch.qos.logback.classic.issue;
015
016import java.util.Date;
017import java.util.concurrent.ScheduledThreadPoolExecutor;
018import java.util.concurrent.TimeUnit;
019
020import org.slf4j.Logger;
021import org.slf4j.LoggerFactory;
022
023import ch.qos.logback.classic.LoggerContext;
024import ch.qos.logback.classic.joran.JoranConfigurator;
025import ch.qos.logback.core.joran.spi.JoranException;
026import ch.qos.logback.core.util.StatusPrinter;
027
028public class LBCORE63 extends Thread {
029    private final static String LOGGER_CONFIGURATION_FILE = "./src/test/input/issue/lbcore63.xml";
030    private final Logger logger = LoggerFactory.getLogger(LBCORE63.class);
031
032    private final long start;
033
034    public LBCORE63() throws JoranException {
035        start = new Date().getTime();
036        LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
037        JoranConfigurator configurator = new JoranConfigurator();
038        lc.reset();
039        configurator.setContext(lc);
040        configurator.doConfigure(LOGGER_CONFIGURATION_FILE);
041        StatusPrinter.printInCaseOfErrorsOrWarnings(lc);
042    }
043
044    public void start() {
045        ScheduledThreadPoolExecutor ex1 = new ScheduledThreadPoolExecutor(1);
046        ScheduledThreadPoolExecutor ex2 = new ScheduledThreadPoolExecutor(1);
047        ScheduledThreadPoolExecutor ex3 = new ScheduledThreadPoolExecutor(1);
048        ScheduledThreadPoolExecutor ex4 = new ScheduledThreadPoolExecutor(1);
049        ScheduledThreadPoolExecutor ex5 = new ScheduledThreadPoolExecutor(1);
050        ex1.scheduleAtFixedRate(new Task("EX1"), 10, 10, TimeUnit.MICROSECONDS);
051        ex2.scheduleAtFixedRate(new Task("EX2"), 10, 10, TimeUnit.MICROSECONDS);
052        ex3.scheduleAtFixedRate(new Task("EX3"), 10, 10, TimeUnit.MICROSECONDS);
053        ex4.scheduleAtFixedRate(new Task("EX4"), 10, 10, TimeUnit.MICROSECONDS);
054        ex5.scheduleAtFixedRate(new Task("EX5"), 10, 10, TimeUnit.MICROSECONDS);
055
056        super.start();
057    }
058
059    public void run() {
060        try {
061            while (true) {
062                logger.debug("[MAIN] {}", new Date().getTime() - start);
063                Thread.sleep(10);
064            }
065        } catch (InterruptedException e) {
066            logger.info("[MAIN]: Interrupted: {}", e.getMessage());
067        }
068    }
069
070    public static void main(String[] args) {
071        try {
072            LBCORE63 main = new LBCORE63();
073            main.start();
074        } catch (JoranException e) {
075            System.out.println("Failed to load application: " + e.getMessage());
076        }
077    }
078
079    class Task implements Runnable {
080        private final Logger logger = LoggerFactory.getLogger(Task.class);
081        // private final Logger logger_main = LoggerFactory.getLogger(LBCORE63.class);
082        final String name;
083        private final long start;
084
085        int counter = 0;
086        public long diff;
087
088        public Task(final String name) {
089            this.name = name;
090            start = new Date().getTime();
091        }
092
093        public void run() {
094            counter++;
095            diff = new Date().getTime() - start;
096            logger.debug("counter={}", counter);
097            // logger_main.debug("[MAIN] - [{}] {}", name, new Date().getTime() - start);
098        }
099    }
100}