そうです、タイマーを使用すると、その値を変更できます。
Timer timer = new Timer();
timer.schedule( new TimerTask(){
public void run() {
synchronized( lock ) {
isOpen = false;
}
}
}, 10000 );
以上です。内部のメソッドrun
は、呼び出してから10秒後に実行されますschedule
編集
サンプル:
import java.util.Timer;
import java.util.TimerTask;
import java.util.Date;
import static java.lang.System.out;
public class Test {
public static void main( String [] args ) {
Timer timer = new Timer();
timer.schedule( new TimerTask(){
public void run() {
out.println(new Date()+" No more bets, thank you!");
}
}, 10000 );
out.println(new Date() + " Place your bets, place your bets!!");
}
}