On 9.10.2015 20:05, Martin Buchholz wrote:


On Thu, Oct 8, 2015 at 11:51 PM, Jaroslav Bachorik
<jaroslav.bacho...@oracle.com <mailto:jaroslav.bacho...@oracle.com>> wrote:

    On 8.10.2015 18:56, Martin Buchholz wrote:

        Hi Jaroslav,

        we all keep writing finalization code like this... welcome to
        the club!

            I think it would be better :
        - never use currentTimeMillis to measure elapsed time; use
        nanoTime instead


    Ok. I suppose this would be because currentTimeMillis() is dependent
    on the OS time, right?

        - why use complex Phaser when simple CountDownLatch will do?


    The logic is more complex than just waiting for the finalization to
    happen. I need to make sure the finalization happened due to
    GC.run_finalization command and not because of an ordinary GC run or
    JVM shutdown. I will update the test comments to make this clear.


Oh, now I see what you're doing - you need to block the regular
finalizer thread to make sure there will be objects available for the
secondary finalizer thread to process.  Although Phaser works for this,
I like using simple latches - CountDownLatch(1) - because they are
easier to understand.

CountDownLatch done = new CountDownLatch(1);

in primary finalizer thread, call done.await
in secondary finalizer thread, call done.countDown to release the
primary finalizer thread

Ok, I took a look at the test from distance and simplified it a bit. Did a test run of 500 iterations in tight loop without failure.

http://cr.openjdk.java.net/~jbachorik/8135188/webrev.02

-JB-

Reply via email to