MCPcopy Create free account
hub / github.com/LFYSec/MScan / runWithTimeout

Method runWithTimeout

src/main/java/pascal/taie/util/Timer.java:115–129  ·  view source on GitHub ↗

Runs a task with given time budget.

(Runnable task, long seconds)

Source from the content-addressed store, hash-verified

113 * Runs a task with given time budget.
114 */
115 public static void runWithTimeout(Runnable task, long seconds) {
116 Duration timeout = Duration.ofSeconds(seconds);
117 ExecutorService executor = Executors.newSingleThreadExecutor();
118 Future<?> handler = executor.submit(task);
119 try {
120 handler.get(timeout.getSeconds(), TimeUnit.SECONDS);
121 } catch (TimeoutException e) {
122 e.printStackTrace();
123 System.exit(1);
124 } catch (InterruptedException | ExecutionException e) {
125 e.printStackTrace();
126 } finally {
127 executor.shutdown();
128 }
129 }
130}

Callers

nothing calls this directly

Calls 2

exitMethod · 0.80
getMethod · 0.65

Tested by

no test coverage detected