You can try anjlab-tapestry-quartz from here:

https://github.com/anjlab/anjlab-tapestry-commons/tree/master/anjlab-tapestry-quartz


On Thu, Feb 6, 2014 at 2:46 PM, Matthias <[email protected]>wrote:

> Hi, I need to write a service where jobs can be added and should executed
> after a given delay. After execution they are finished, so periodical
> execution is not required. I prefer to user the ScheduledExecutorService
> for this task.
>
> The question is now, how do I use my @Inject objects in the thread? Just
> passing them is not working (hibernate session is invalid). I read some
> stuff like http://wiki.apache.org/tapestry/Tapestry5HowToRunTaskInThreadbut 
> it does'nt help me because I don't invoke the thread myself, the
> scheduler is doing it. Also the other tapestry classes like the
> ParallelExecutor or PeriodicExecutor doesn't seem to fit.
>
> Any suggestions?
>
> @Scope(ScopeConstants.DEFAULT)
> public class MyServiceImpl implements MyService {
>
>     @Inject
>     MyDAO myDAO;
>
>     private ScheduledExecutorService scheduler = Executors.
> newScheduledThreadPool(4);
>
>     public void addJob(Job job, long executeDelay) {
>          scheduler.schedule(new JobTask(job, myDAO), executeDelay);
>     }
>
>     public static class JobTask implements Runnable {
>         // some class members
>         public JobTask(MyDAO myDAO, Job job) {
>             this.myDAO = myDAO;
>             this.job = job;
>         }
>
>         @Override
>         public void run() {
>           // ...
>           Object result = myDAO.getSomethingFromJob(job);
>           // ...
>         }
>      }
> }
>
> Thanks,
> Matthias
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
>
>


-- 
Dmitry Gusev

AnjLab Team
http://anjlab.com

Reply via email to