Simple timeout in java

Can anyone guide me on how I can use a simple timeout in java? Basically in my project I’m executing a statement br.readLine(), which is reading a response from a modem. But sometimes the modem isn’t responding. For that purpose I want to add a timeout. I’m looking for a code like: