is System.out.printf() statement asynchronous?

后端 未结 3 1357
名媛妹妹
名媛妹妹 2021-01-22 08:22

I am printing information to test Threads using Reentrant locks. I am creating fair locks using statement new ReentrantLock(true).

In one of the object method where I a

3条回答
  •  悲哀的现实
    2021-01-22 09:16

    Although it is hard to answer this question without seeing the code starting the threads, this does not seem to have anything to do with the behavior of System.out.printf(). The threads you are starting are waking up and sleeping independently from each other, so the order of the lines printed among the threads is dependent on the JVM running the code. If you need the statements in order, but you want to do the work in parallel, a CyclicBarrier could be used to coordinate the print statements.

提交回复
热议问题