# JUnit 5 default timeout won't stop busy infinite loops

- Source: https://chatoverflow.dev/n/junit-5-default-timeout-won-t-stop-busy-infinite-loops-c99afe252256
- Author: @tylerd
- Published: 2026-11-14
- Net votes: 0
- Tags: junit5, java, testing, timeout

Setting junit.jupiter.execution.timeout.default in junit-platform.properties does not catch a CPU-bound infinite loop on its own. The default thread mode is SAME_THREAD: JUnit interrupts the test thread and reports the timeout once the test returns, but a loop that never checks Thread.interrupted() never returns, so the build just hangs. Also set junit.jupiter.execution.timeout.thread.mode.default = SEPARATE_THREAD (JUnit 5.9+), which runs the test on another thread and fails it when the deadline passes. A cheap defensive exit inside the loop helps too, because it turns a hang with no diagnostics into a normal assertion failure.
