@Component
public class DemoExpirationEvent implements Runnable {
@Resource(name = "demoPhotoService")
private DemoExpirationService demoExpirationService;
@Resource(name = "demoExpirationTaskScheduler")
private TaskScheduler taskScheduler;
private Long id;
@Override
public void run() {
demoExpirationService.expiration(id);
}
public void schedule(Long id, Date dateToExpire){
this.id = id;
taskScheduler.schedule(this, dateToExpire);
}
}
@Service("demoPhotoService")
public class DemoPhotoServiceImpl implements DemoExpirationService, DemoPhotoService {
@Override
public void expiration(Long id) {
DemoPhoto photo = getPhoto(id);
photo.setExpirationDate(null);
savePhoto(photo);
notifyAuthorOfPhoto(id);
}
@Override
public void getPhoto(long id){
//some implementation
}
@Override
public void savePhoto(DemoPhoto photo){
//some implementation
}
@Override
public void notifyAuthorOfPhoto(long id){
//some implementation
}
}
public class DemoAddedPhotoActivity {
@Resource(name = "demoExpirationEvent")
private DemoExpirationEvent demoExpirationEvent;
@Resource(name = "demoPhotoService")
private DemoPhotoService demoPhotoService;
public void execute(long id) throws Exception {
DemoPhoto photo = demoPhotoService.getPhoto(id);
Date expirationDate = new Date(System.currentTimeMillis() + 30000000000L);
photo.setExpirationDate(expirationDate);
demoPhotoService.savePhoto(photo);
demoExpirationEvent.schedule(id, expirationDate);
}
}
- あなたのapplicationContext.xmlを内のレジスタのタスクスケジューラすぎ
<beans xmlns:task="http://www.springframework.org/schema/task"
xsi:schemaLocation="http://www.springframework.org/schema/task
http://www.springframework.org/schema/task/spring-task-4.1.xsd">
<task:scheduler id="demoExpirationTaskScheduler" pool-size="3"/>
- と豆の残りと(それは、コントローラ方法することができ、写真を追加することでアクティビティを呼び出します同じように実行する
あなたの答えにリンクされたコンテンツの関連部分を含めてください。 –
上記のコメントを参考に私の答えを更新しました。 –