multithreading - Java Program output printed in random position in Eclipse console -
i have junit class in eclipse project. following:
import org.slf4j.logger; import org.slf4j.loggerfactory; /*some other imports*/ public class _junittests{ final logger logger = loggerfactory.getlogger(_junittests.class); public void test(int num){ logger.info("**** tests no."+num+" ***"); /* code */ } @test public static void test1() { test(1); } @test public static void test2() { test(2); } @test public static void test3() { test(3); } @test public static void test1() { test(1); } }
when run tests, expecting output such as[class information of info ignored]
**** tests no.1 *** /* somethings */ **** tests no.2 *** /* somethings */ **** tests no.3 *** /* somethings */
however, result shown in console messed like:
**** tests no.1 *** **** tests no.2 *** **** tests /* somethings */ no.3 *** /* somethings */ /* somethings */
this happens lot before other codes when there exception messages.
my guess before stderr , stdout handled in different threads, , result displayed without order.
since info logger red in eclipse console, guess uses stderr display message? case? if so, there way solve problem of messed order? thanks.
which logging framework use slf4j? logging framework configured write log messages asynchronously in background thread.
you can try replace log call system.out.println()
, see if produces output expect. if may want reconfigure logging framework log messages synchronously.
Comments
Post a Comment