1 Eylül 2014 Pazartesi

Ejb 3.1 Schedule Job(Zamanlanmış Görev 2)


Ejb ile gelen @Schedule anotasyonu bize oldukça esnek bir yapı sunuyor. Her yılın belli bir tarihideki saat dakika saniye tanımı yapılarak, Her ayın son cuma günü, her perşembe vb. tanımladığımız business methodun çalışmasını sağlayabiliriz. Ejb'nin çalışabilmesi için uygulama sunucusunun EJB CONTAINER'ı bulunması gerekiyor. Ben uygulamayı Weblogic 12C üzerinde çalıştıracağım. Örnek kod aşağıdaki gibidir...












TimerSessionBeanLocal.java
EjbTimerEx\EjbTimerEx\EjbTimerEx-ejb\src\main\java\com\blogtest\ex\TimerSessionBeanLocal.java
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package com.blogtest.ex;

import javax.ejb.Local;
import javax.ejb.Timer;

/**
 *
 * @author BeytullahC
 */
@Local
public interface TimerSessionBeanLocal {

    public void timerMethod(Timer t);
    
}

EjbTimerEx\EjbTimerEx\EjbTimerEx-ejb\src\main\java\com\blogtest\ex\TimerSessionBean.java
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package com.blogtest.ex; import java.io.Serializable; import java.util.Date; import javax.ejb.Schedule; import javax.ejb.Stateless; import javax.ejb.Timer; /** * * @author BeytullahC */ @Stateless public class TimerSessionBean implements TimerSessionBeanLocal,Serializable { /** * 00 Saniyesinde çalış ve Her dakika tekrarla * @Schedule anotasyonu ile saniye dakika saat gün ay ve yıl tanımlanarak istenilen * zamanda methodun çalıştırılması sağlanabilir * Örn: * Ayın son cuma günü saat 23 te çalış gibi * @Schedule(dayOfMonth="Last"), * @Schedule(dayOfWeek="Fri", hour="23") * * @param t */ @Schedule(second = "00", minute = "*", hour = "*", info = "Automatic Timer(Every Minute)") @Override public void timerMethod(Timer t) { System.out.println("Timer Method called : ===>" + new Date()); } }

Kaynak Kod : https://drive.google.com/file/d/0BxhjtDmkuDJtaG03NmdxSkRIcTg/edit?usp=sharing
-->

Hiç yorum yok:

Yorum Gönder