2012-10-24 2 views
1

jave에서 자동화 된 상태 변경으로 마이그레이션해야하는 상태 시스템이 있습니다. 즉, certan 간격 후 상태 변경이 필요합니다. 예를 들어 5 초 후 상태 1, 10 초 상태 2 이후.시간 제한 상태 시스템이 작동합니까?

나는 사용을 생각하고 있었다;

ScheduledExecutorService executor = new ScheduledThreadPoolExecutor(1); 

기본적으로 상태를 변경하고 다음 상태로 변경하는 다른 작업을 예약하는 방법을 호출하는 작업을 예약합니다.

아이디어가 있으십니까? 이와 유사한

+0

작동하는 것처럼 보입니다. 너 해봤 어? – KJP

+0

예, 그랬습니다. 그다지 옳지 않다고 느끼는 것 같습니다. – user1555190

답변

0

필요 코드 :

ScheduledThreadPoolExecutor exec = new ScheduledThreadPoolExecutor(1); 
exec.scheduleWithFixedDelay(new Runnable() { 
     public void run() { 
      // TODO: do something 
     } 
    }, 
    0, // no wait and start the 1st one 
    5, // delay 5 seconds and do the next one 
    TimeUnit.SECONDS); 

또한 (scheduleAtFixedRate에 볼 수 있었다).