이 기사는 주로 ScheduleDexecutorService 작업 타이밍에 대한 예제 코드를 다음과 같이 공유합니다.
샘플 코드
package com.effective.common.concurrent.execute; import java.text.dateformat; import java.text.parseexception; import java.text.simpledateformat; import java.util.date; import java.util.concurrent.executors import java.util.concurecutecuterverecutecurent java.util.concurrent.timeUnit; 공개 클래스 일정 {private static dateformat dateformat = new SimpledateFormat ( "yy-mm-dd hh : mm : ss"); private static dateformat dayformat = new SimpledateFormat ( "yy-mm-dd"); 개인 정적 일정 스케줄링 excutorsvices excutor = executors.newsingleTheStreadScheduledExecutor ();/** * 지정된 주파수 기간에 따라 작업을 실행합니다. */public void fixedRate () {excutor.scheduleatfixedrate (new echoServer (), // 실행 스레드 0, // 초기화 지연 5000, // 두 실행 사이의 최소 시간 간격을 시작한 TimeUnit.milliseconds // 시간 단위);}/** * */public void elay () echoserver (), // 실행 스레드 0, // 초기화 지연 5000, //timeUnit.milliseconds); }/** * 매일 오후 8시에 한 번 실행 */public void dayofdelay (문자열 시간) {scheduledExecutorservice executor = exector.newschedudedThreadpool (1); 24 * 60 * 60 * 1000; getTimeMillis ( "20:00:00") - System.CurrentTimeMillis (); initDelay = initDelay> 0? initdelay : oneday + initdelay; executor.scheduleatfixedrate (new echoserver (), initdelay, oneday, timeUnit.milliseconds);}/** * 주어진 시간에 해당하는 milliseconds의 수를 얻으십시오 * @param 문자열 "hh : mm : ss" */private gettation long gettimemillis */privity long gettimemillis */privity long gettimemillis에 해당합니다. {date currentDate = dateformat.parse (dayformat.format (new Date ()) + "" + 시간); return currentDate.getTime ();} catch (parseException e) {e.printstackTrace ();} public static void main (String [] args) {Schedule schedule = new Schedule (); schedule.fixedRate (); schedule.fixdelay ();}}요약
위는 ScheduleDexecutorService 작업 타이밍 코드 예제에 대한이 기사의 전체 내용입니다. 모든 사람에게 도움이되기를 바랍니다. 관심있는 친구는이 사이트의 다른 관련 주제를 계속 참조 할 수 있습니다. 단점이 있으면 메시지를 남겨 두십시오. 이 사이트를 지원해 주신 친구들에게 감사드립니다!