Seam de Zamanlı İşler – Scheduling
Seam içerisinde belirli aralıklarla çalışan operasyonların olmasını istiyorsanız zamanlı işleri (Scheduling) kullanabilirsiniz. Bunun için iki alternatifiniz var. Birincisi EJB Timer olabilir ancak bu durumda EJB Container üzerinde çalışmanız gerekiyor. Alternatif olarakta Java dünyasında en çok kullanılan scheduling faramework ü olan Quartz ı kullanabilirsiniz.
Öncelikle zamanlı işlemler için quartz ı kullanacağımızdan bunu components.xml altında aşağıdaki gibi tanımlamamız gerekiyor.
<async:quartz-dispatcher />
Daha sonra WEB-INF/lib altında quartz.jar ın var olduğunu kontrol edelim. Eğer yoksa bunu seam-runtime/lib altından alıp ekleyelim.
Şimdi quartz içerisinde genel tanımlar için kullanacağımız seam.qartz.properties dosyasını src/main/ altında aşağıdaki gibi oluşturalım.
#============================================================================
# Configure Main Scheduler Properties
#============================================================================
org.quartz.scheduler.instanceName Sched1
org.quartz.scheduler.instanceId AUTO
org.quartz.scheduler.rmi.export false
org.quartz.scheduler.rmi.proxy false
#============================================================================
# Configure ThreadPool
#============================================================================
org.quartz.threadPool.class org.quartz.simpl.SimpleThreadPool
org.quartz.threadPool.threadCount 3
#============================================================================
# Configure JobStore
#============================================================================
org.quartz.jobStore.misfireThreshold 60000
org.quartz.jobStore.class org.quartz.simpl.RAMJobStore
Şimdi asenkron çalışacak bir bean tanımı yapalım.
package com.mergecons.seam.session;
import java.util.Date;
import org.jboss.seam.annotations.AutoCreate;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.annotations.async.Asynchronous;
import org.jboss.seam.annotations.async.Expiration;
import org.jboss.seam.annotations.async.FinalExpiration;
import org.jboss.seam.annotations.async.IntervalDuration;
import org.jboss.seam.async.QuartzTriggerHandle;
@Name("zamanliBean")
@AutoCreate
public class ZamanliBean {
@Asynchronous
public QuartzTriggerHandle zamanliMetod(@Expiration Date when,
@IntervalDuration Long interval, @FinalExpiration Date stoptime,
String mesaj) {
System.out.println(+ mesaj);
return null;
}
}
Bu bean in kontrolü içinde aşağıdaki gibi mekanizma oluşturulabilir.
package com.mergecons.seam.session;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import org.hibernate.validator.Length;
import org.jboss.seam.ScopeType;
import org.jboss.seam.annotations.AutoCreate;
import org.jboss.seam.annotations.In;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.annotations.Out;
import org.jboss.seam.annotations.Scope;
import org.jboss.seam.annotations.Transactional;
import org.jboss.seam.annotations.async.Asynchronous;
import org.jboss.seam.annotations.async.Expiration;
import org.jboss.seam.annotations.async.FinalExpiration;
import org.jboss.seam.annotations.async.IntervalDuration;
import org.jboss.seam.async.QuartzTriggerHandle;
import org.jboss.seam.international.StatusMessages;
import org.quartz.SchedulerException;
@Name("demoService")
public class DemoService
{
@In StatusMessages statusMessages;
private String value;
@In ZamanliBean zamanliBean;
@In(required=false,scope=ScopeType.SESSION) @Out(required=false,scope=ScopeType.SESSION) QuartzTriggerHandle handle;
public void kaydet()
{
try {
handle = zamanliBean.zamanliMetod(new Date(), 2000L, new SimpleDateFormat("dd.MM.yyyy").parse("16.09.2012"), value);
System.out.println("handle : " + handle);
} catch (ParseException e) {
e.printStackTrace();
}
statusMessages.add("kaydet #{deneme.value}");
}
public void durdur() {
try {
handle.cancel();
} catch (SchedulerException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
@Length(max = 10)
public String getValue()
{
return value;
}
public void setValue(String value)
{
this.value = value;
}
}

Faydalı oldu, teşekkürler ;)
Emeğinize sağlık hocam, baya işime yaradı :)
stackoverflow da adamlar tam anlatmamış, sitenizi referan olarak gösterdim
http://stackoverflow.com/questions/7819446/asynchronous-method-in-seam-always-return-null-quartztriggerhandle/9787682#9787682