commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ottobackwards <...@git.apache.org>
Subject [GitHub] commons-lang issue #311: LANG-1373 Stopwatch based capability for nested, na...
Date Tue, 27 Feb 2018 14:08:25 GMT
Github user ottobackwards commented on the issue:

    https://github.com/apache/commons-lang/pull/311
  
    the static factory, is pretty straight forward.
    The try with resources, less so.  What ends up happening is you cannot stop the watch
before visiting the nodes.
    
    For example, this is what you want to do if you are going to time, but visit later:
    
    ```java
     @Test
        public void testTryWithResources() {
            final StopWatch stopWatch = new StopWatch();
            
            try(StackWatch<String,String> watch = new StackWatch<>("testStackWatch"))
{
                watch.start();
                stopWatch.start();
                stopWatch.stop();
            }
            watch.visit(new StackWatch.TimingVisitor<String,String>() {
                @Override
                public void visitTiming(int level, List<String> path, StackWatch.Timing<String,String>
node) {
                    assertTrue(node.getStopWatch().getNanoTime() > stopWatch.getNanoTime());
                }
            });
        }
    ```
    
    but it won't work/compile with try with resources
    



---

Mime
View raw message