상세 컨텐츠

본문 제목

[Spring] Scheduler 예제

소프트웨어/spring

by 야솔아빠 2012. 1. 13. 14:58

본문

반응형
1. spring 설정 xml에 다음과 같이 등록한다.

<?xml version="1.0" encoding="UTF-8"?>

<beans:beans xmlns="http://www.springframework.org/schema/mvc"

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

xmlns:beans="http://www.springframework.org/schema/beans"

xmlns:context="http://www.springframework.org/schema/context"

xmlns:task="http://www.springframework.org/schema/task"

xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd

http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd

http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd

http://www.springframework.org/schema/task

http://www.springframework.org/schema/task/spring-task-3.0.xsd">


<!-- DispatcherServlet Context: defines this servlet's request-processing infrastructure -->

<!-- Enables the Spring MVC @Controller programming model -->

<annotation-driven />


<!-- Handles HTTP GET requests for /resources/** by efficiently serving up static resources in the ${webappRoot}/resources directory -->

<resources mapping="/resources/**" location="/resources/" />


<!-- Resolves views selected for rendering by @Controllers to .jsp resources in the /WEB-INF/views directory -->

<beans:bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">

<beans:property name="prefix" value="/WEB-INF/views/" />

<beans:property name="suffix" value=".jsp" />


</beans:bean>

<context:component-scan base-package="com.inho.scheduler" />

<beans:bean class="com.inho.scheduler.scheduled.DBPolling" />

<task:annotation-driven scheduler="scheduler"/>

<task:scheduler id="scheduler" pool-size="10"/>

</beans:beans>


 

2. DBPolling.java 생성 

package com.inho.scheduler.scheduled;


import org.springframework.scheduling.annotation.Scheduled;


public class DBPolling {

@Scheduled(fixedRate=1000)

public void dbPolling() {

System.out.println("DB polling...");

}

}



1초마다 scheduling 됩니다.

아래는 서버 실행화면입니다.

2012. 1. 13 오후 2:55:46 org.apache.coyote.http11.Http11Protocol start

정보: Starting Coyote HTTP/1.1 on http-8080

DB polling...

2012. 1. 13 오후 2:55:46 org.apache.jk.common.ChannelSocket init

정보: JK: ajp13 listening on /0.0.0.0:8009

2012. 1. 13 오후 2:55:46 org.apache.jk.server.JkMain start

정보: Jk running ID=0 time=0/103  config=null

2012. 1. 13 오후 2:55:46 org.apache.catalina.startup.Catalina start

정보: Server startup in 2852 ms

DB polling...

DB polling...

DB polling...

DB polling...




반응형

관련글 더보기

댓글 영역