Quello che devi fare è sostanzialmente un "polling", senza bloccare alcunché. Devi solo determinare se non si è ancora arrivati ad un certo istante nel tempo e in tal caso sapere quanti secondi rimangono.
Con uno scenario come questo non serve nemmeno usare un "timer"! Basta solo ragionare appunto in termini di "istante" del tempo.
Prova questo, così vediamo se ho capito bene cosa ti serve:
codice:
import java.util.*;
public class Prova
{
public static void main (String[] args)
{
Scanner sc = new Scanner (System.in);
Waiter waiter = new Waiter (10); // 10 secondi
do {
System.out.print ("comando: ");
String line = sc.nextLine ();
if (waiter.isWaiting ())
{
int seconds = waiter.getSecondsToWait ();
System.out.println ("Devi aspettare ancora " + seconds + (seconds == 1 ? " secondo" : " secondi"));
}
else
{
waiter.start ();
System.out.println ("....lavoro....");
}
} while (true);
}
}
class Waiter
{
private int seconds;
private long targetTime;
public Waiter (int seconds)
{
this.seconds = seconds;
}
public void start ()
{
if (System.currentTimeMillis () > targetTime)
targetTime = System.currentTimeMillis () + seconds * 1000;
}
public boolean isWaiting ()
{
return System.currentTimeMillis () < targetTime;
}
public int getSecondsToWait ()
{
return (int) ((targetTime - System.currentTimeMillis () + 1000) / 1000);
}
}