public ResponseEntity get()

in log4j-spring-cloud-config-sample-application/src/main/java/org/apache/logging/log4j/spring/cloud/config/sample/controller/SampleController.java [41:84]


    public ResponseEntity<String> get(
            @RequestParam(name = "threads", defaultValue = "1") int threads,
            @RequestParam(name = "messages", defaultValue = "100000") int count) {
        if (threads < 1) {
            threads = 1;
        }
        if (count < threads) {
            count = threads * 10000;
        }
        if ((count * threads) > MAX_MESSAGES) {
            count = MAX_MESSAGES / threads;
        }
        String msg = "";
        if (threads == 1) {
            Timer timer = new Timer("sample");
            timer.start();
            for (int n = 0; n < count; ++n) {
                LOGGER.info("Log record " + n);
            }
            timer.stop();
            StringBuilder sb = new StringBuilder("Elapsed time = ");
            timer.formatTo(sb);
            msg = sb.toString();
        } else {
            ExecutorService service = Executors.newFixedThreadPool(threads);
            Timer timer = new Timer("sample");
            timer.start();
            for (int i = 0; i < threads; ++i) {
                service.submit(new Worker(i, count));
            }
            service.shutdown();
            try {
                service.awaitTermination(2, TimeUnit.MINUTES);
                timer.stop();
                StringBuilder sb = new StringBuilder("Elapsed time = ");
                timer.formatTo(sb);
                msg = sb.toString();
            } catch (InterruptedException ex) {
                msg = "Max time exceeded";
            }
        }

        return ResponseEntity.ok(msg);
    }