Hi all,
I need to create a background service in EJB 3.1 that pulls a list of tasks to run from the DB and creates the distributed threads to run them.
I need the service to have global state, so it keeps a reference to the tasks (static ArrayList) that are currently running so it doesn't run them more than once
Initially I though I could use
@Singleton
public class MyService {
static ArrayList<Task> tasksList;
@Lock(LockType.WRITE) // write cause I am modifing static fields
@Schedule(second="0,15,30,45", minute="*", hour="*")
public void execute(Timer timer) {
.......
Task newTask = new Task();
newtask.start();
taskList.add(newTask);
public class Task extends Thread {
.....
But with this approach the thread won't be distributed, and also singleton is getting concurrent calls that eventually timeout when the cycle takes longer than 15 seconds.
So, how can I:
1) make use of a TimerService across the cluster that won't be re-entrant, or make it exit it another cycle is still running ?
2) how can I distribute the threads across the cluster ?
Thanks
I need to create a background service in EJB 3.1 that pulls a list of tasks to run from the DB and creates the distributed threads to run them.
I need the service to have global state, so it keeps a reference to the tasks (static ArrayList) that are currently running so it doesn't run them more than once
Initially I though I could use
@Singleton
public class MyService {
static ArrayList<Task> tasksList;
@Lock(LockType.WRITE) // write cause I am modifing static fields
@Schedule(second="0,15,30,45", minute="*", hour="*")
public void execute(Timer timer) {
.......
Task newTask = new Task();
newtask.start();
taskList.add(newTask);
public class Task extends Thread {
.....
But with this approach the thread won't be distributed, and also singleton is getting concurrent calls that eventually timeout when the cycle takes longer than 15 seconds.
So, how can I:
1) make use of a TimerService across the cluster that won't be re-entrant, or make it exit it another cycle is still running ?
2) how can I distribute the threads across the cluster ?
Thanks