Code example for SimpleTimeLimiter

Methods: callWithTimeout

1
            String command) {
        log.info("=== about to call ===\n{}", command);
        final List<String> commands =
                Lists.newArrayList(Splitter.on(" ").split(command));
 
        SimpleTimeLimiter timeLimiter = new SimpleTimeLimiter();
        Callable<List<String>> work = new Callable<List<String>>() {
            @Override 
            public List<String> call() throws Exception {
                Process process = 
                        ClientWorkFlow.invokeClient(workingDirectory,
                                commands);
                process.waitFor(); 
                List<String> output = ClientWorkFlow.getOutput(process);
                logOutputLines(output);
                return output;
            } 
        }; 
        try { 
            return timeLimiter
                    .callWithTimeout(work, timeoutDuration, TimeUnit.SECONDS, true);
        } catch (Exception e) {
            throw new RuntimeException(e);
        } 
    } 
 
Experience pair programming with AI  Get Codota for Java