이 기사의 내용은 예약된 작업의 SpringBoot 동적 관리 구현 코드에 대한 것입니다. 필요한 친구가 참고할 수 있기를 바랍니다.
SpringBoot는 예약된 작업을 동적으로 관리합니다.
먼저 @EnableScheduling을 사용하여 예약된 작업을 설정합니다.
package com.fighting; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.scheduling.annotation.EnableScheduling; @SpringBootApplication @EnableScheduling public class ScheduledApplication { public static void main(String[] args) { SpringApplication.run(ScheduledApplication.class, args); } }
로그 수준 구성
logging.level.com= debug logging.file=springboot-scheduled.log#🎜🎜 #주기적인 예약 작업 수정
package com.fighting;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
/**
* Spring静态周期定时任务
*
* @author fighting
* @date 2018-09-11
*/
@Component
public class SpringStaticCronTask {
public static final Logger logger = LoggerFactory.getLogger(SpringStaticCronTask.class);
@Scheduled(cron = "0/5 * * * * ?")
public void staticCornTask() {
logger.debug("staticCronTask is running...");
}
}
타이밍 기간을 동적으로 수정SchedulingConfigurer 인터페이스 구현 및configureTasks 메서드 다시 작성package com.fighting; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.scheduling.annotation.SchedulingConfigurer; import org.springframework.scheduling.config.ScheduledTaskRegistrar; import org.springframework.scheduling.support.CronTrigger; import org.springframework.stereotype.Component; /** * 动态定时任务 * * @author fighting * @date 2018-09-11 */ @Component public class SpringDynamicCronTask implements SchedulingConfigurer { private static final Logger logger = LoggerFactory.getLogger(SpringDynamicCronTask.class); private static String cron = "0/5 * * * * ?"; @Override public void configureTasks(ScheduledTaskRegistrar scheduledTaskRegistrar) { scheduledTaskRegistrar.addTriggerTask(() -> { // 任务逻辑 logger.error("dynamicCronTask is running..."); }, triggerContext -> { // 任务触发,在这里可修改任务的执行周期,因为每次调度都会执行这里 CronTrigger cronTrigger = new CronTrigger(cron); return cronTrigger.nextExecutionTime(triggerContext); }); } public SpringDynamicCronTask() { //模拟业务修改周期,可以在具体业务中修改参数cron new Thread(() -> { try { Thread.sleep(15000); } catch (InterruptedException e) { e.printStackTrace(); } cron = "0/2 * * * * ?"; }).start(); } }인쇄 결과 관찰, 기간이 변경되었지만 프로젝트가 다시 시작되지 않습니다.
2018-09-11 13:36:50.009 DEBUG 16708 --- [pool-1-thread-1] com.fighting.SpringStaticCronTask : staticCronTask is running... 2018-09-11 13:36:50.010 ERROR 16708 --- [pool-1-thread-1] com.fighting.SpringDynamicCronTask : dynamicCronTask is running... 2018-09-11 13:36:55.001 DEBUG 16708 --- [pool-1-thread-1] com.fighting.SpringStaticCronTask : staticCronTask is running... 2018-09-11 13:36:55.002 ERROR 16708 --- [pool-1-thread-1] com.fighting.SpringDynamicCronTask : dynamicCronTask is running... 2018-09-11 13:37:00.009 DEBUG 16708 --- [pool-1-thread-1] com.fighting.SpringStaticCronTask : staticCronTask is running... 2018-09-11 13:37:00.016 ERROR 16708 --- [pool-1-thread-1] com.fighting.SpringDynamicCronTask : dynamicCronTask is running... 2018-09-11 13:37:05.016 DEBUG 16708 --- [pool-1-thread-1] com.fighting.SpringStaticCronTask : staticCronTask is running... 2018-09-11 13:37:05.016 ERROR 16708 --- [pool-1-thread-1] com.fighting.SpringDynamicCronTask : dynamicCronTask is running... 2018-09-11 13:37:06.013 ERROR 16708 --- [pool-1-thread-1] com.fighting.SpringDynamicCronTask : dynamicCronTask is running... 2018-09-11 13:37:08.008 ERROR 16708 --- [pool-1-thread-1] com.fighting.SpringDynamicCronTask : dynamicCronTask is running... 2018-09-11 13:37:10.002 ERROR 16708 --- [pool-1-thread-1] com.fighting.SpringDynamicCronTask : dynamicCronTask is running... 2018-09-11 13:37:10.003 DEBUG 16708 --- [pool-1-thread-1] com.fighting.SpringStaticCronTask : staticCronTask is running... 2018-09-11 13:37:12.002 ERROR 16708 --- [pool-1-thread-1] com.fighting.SpringDynamicCronTask : dynamicCronTask is running... 2018-09-11 13:37:14.006 ERROR 16708 --- [pool-1-thread-1] com.fighting.SpringDynamicCronTask : dynamicCronTask is running... 2018-09-11 13:37:15.015 DEBUG 16708 --- [pool-1-thread-1] com.fighting.SpringStaticCronTask : staticCronTask is running... 2018-09-11 13:37:16.012 ERROR 16708 --- [pool-1-thread-1] com.fighting.SpringDynamicCronTask : dynamicCronTask is running... 2018-09-11 13:37:18.002 ERROR 16708 --- [pool-1-thread-1] com.fighting.SpringDynamicCronTask : dynamicCronTask is running...관련 권장 사항: #🎜 🎜 #reidis를 통해 예약된 작업을 관리하세요
위 내용은 예약된 작업의 SpringBoot 동적 관리를 위한 구현 코드의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!

Java는 JVM (Java Virtual Machines) 및 바이트 코드에 의존하는 "Write Once, Everywhere 어디에서나 Run Everywhere"디자인 철학으로 인해 플랫폼 독립적입니다. 1) Java Code는 JVM에 의해 해석되거나 로컬로 계산 된 바이트 코드로 컴파일됩니다. 2) 라이브러리 의존성, 성능 차이 및 환경 구성에주의하십시오. 3) 표준 라이브러리를 사용하여 크로스 플랫폼 테스트 및 버전 관리가 플랫폼 독립성을 보장하기위한 모범 사례입니다.

java'splatformincceldenceisisnotsimple; itinvolvescomplex

Java'SplatformIndenceBenefitsWebApplicationScodetorUnonySystemwithajvm, simplifyingDeploymentandScaling.Itenables : 1) EasyDeploymentAcrossDifferentservers, 2) SeamlessScalingAcrossCloudPlatforms, 3))

thejvmistheruntimeenvironmenmentforexecutingjavabytecode, Crucialforjava의 "WriteOnce, runanywhere"capability.itmanagesmemory, executesThreads, andensuressecurity, makingestement ofjavadeveloperStandStandStandStandStandStandStandStandStandStandStandStandStandStandStandStandStandStandStandStandStandStandStandStandStandStandStandStandStandStandStandStandSmetsmentsMemory

javaremainsatopchoicefordevelopersdueToitsplatformindence, 객체 지향 데 디자인, 강력한, 자동 메모리 관리 및 compehensiveStandardlibrary

Java'splatforminceldenceMeansdeveloperscanwriteCodeOnceAndrunitonAnyDevicewithoutRecompiling.thisiSocievedTheRoughthejavirtualMachine (JVM), thisTecodeIntomachine-specificinstructions, hallyslatslatsplatforms.howev

JVM을 설정하려면 다음 단계를 따라야합니다. 1) JDK 다운로드 및 설치, 2) 환경 변수 설정, 3) 설치 확인, 4) IDE 설정, 5) 러너 프로그램 테스트. JVM을 설정하는 것은 단순히 작동하는 것이 아니라 메모리 할당, 쓰레기 수집, 성능 튜닝 및 오류 처리를 최적화하여 최적의 작동을 보장하는 것도 포함됩니다.

ToensureJavaplatform Independence, followthesesteps : 1) CompileIndrunyourApplicationOnMultiplePlatformsUsingDifferentOnsandjvMversions.2) Utilizeci/CDPIPELINES LICKINSORTIBACTIONSFORAUTOMATES-PLATFORMTESTING


핫 AI 도구

Undresser.AI Undress
사실적인 누드 사진을 만들기 위한 AI 기반 앱

AI Clothes Remover
사진에서 옷을 제거하는 온라인 AI 도구입니다.

Undress AI Tool
무료로 이미지를 벗다

Clothoff.io
AI 옷 제거제

Video Face Swap
완전히 무료인 AI 얼굴 교환 도구를 사용하여 모든 비디오의 얼굴을 쉽게 바꾸세요!

인기 기사

뜨거운 도구

Atom Editor Mac 버전 다운로드
가장 인기 있는 오픈 소스 편집기

SublimeText3 영어 버전
권장 사항: Win 버전, 코드 프롬프트 지원!

Eclipse용 SAP NetWeaver 서버 어댑터
Eclipse를 SAP NetWeaver 애플리케이션 서버와 통합합니다.

PhpStorm 맥 버전
최신(2018.2.1) 전문 PHP 통합 개발 도구

MinGW - Windows용 미니멀리스트 GNU
이 프로젝트는 osdn.net/projects/mingw로 마이그레이션되는 중입니다. 계속해서 그곳에서 우리를 팔로우할 수 있습니다. MinGW: GCC(GNU Compiler Collection)의 기본 Windows 포트로, 기본 Windows 애플리케이션을 구축하기 위한 무료 배포 가능 가져오기 라이브러리 및 헤더 파일로 C99 기능을 지원하는 MSVC 런타임에 대한 확장이 포함되어 있습니다. 모든 MinGW 소프트웨어는 64비트 Windows 플랫폼에서 실행될 수 있습니다.