You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Matthias <ma...@uni-jena.de> on 2014/02/06 11:46:26 UTC
ScheduledExecutorService in tapestry ioc
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/Tapestry5HowToRunTaskInThread
but 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: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org
Re: ScheduledExecutorService in tapestry ioc
Posted by Matthias <th...@gmail.com>.
Thanks Dmitry, works perfect :).
On 06.02.2014 16:11, Dmitry Gusev wrote:
> 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 <ma...@uni-jena.de>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: users-unsubscribe@tapestry.apache.org
>> For additional commands, e-mail: users-help@tapestry.apache.org
>>
>>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org
Re: ScheduledExecutorService in tapestry ioc
Posted by Dmitry Gusev <dm...@gmail.com>.
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 <ma...@uni-jena.de>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: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>
--
Dmitry Gusev
AnjLab Team
http://anjlab.com