This is the first time I work with threads ... The method below runs every 15 seconds by EJB. I would like if in case there is an SMS list in the database it would add to a new SMS trigger thread
But you are returning the following error:
Caused by: java.util.concurrent.RejectedExecutionException: Task com.core.framework.timerservice.TimerSessionBeanSmsLote$1@1e13b49e rejected from java.util.concurrent.ThreadPoolExecutor@1945ea4f[Terminated, pool size = 0, active threads = 0, queued tasks = 0, completed tasks = 1]
10:29:17,342 ERROR [org.jboss.as.ejb3] (EJB default - 1) JBAS014122: Error during retrying timeout for timer: [id=f3aba899-a38f-4111-bbc6-2465b9dfcbf0 timedObjectId=PortalEAR.PortalEJB.TimerSessionBeanSmsLote auto-timer?:true persistent?:true timerService=org.jboss.as.ejb3.timerservice.TimerServiceImpl@2a060c86 initialExpiration=Thu Oct 09 00:00:00 BRT 2014 intervalDuration(in milli sec)=0 nextExpiration=Wed Oct 15 05:07:45 BRT 2014 timerState=IN_TIMEOUT: javax.ejb.EJBException: java.util.concurrent.RejectedExecutionException: Task com.core.framework.timerservice.TimerSessionBeanSmsLote$1@1ad48394 rejected from java.util.concurrent.ThreadPoolExecutor@1945ea4f[Terminated, pool size = 0, active threads = 0, queued tasks = 0, completed tasks = 1]
Follow the code:
@Singleton
@TransactionManagement(TransactionManagementType.BEAN)
public class TimerSessionBeanSmsLote {
private ExecutorService service = Executors.newFixedThreadPool(10);
private List smsLoteList;
// Esse método é executado de 15 em 15 segundos.........
@Schedule(hour="*", minute="*", second="*/15")
@AccessTimeout(value = 20, unit = TimeUnit.DAYS)
public void automaticTimeout() {
// pega a lista de sms no banco.............
smsLoteList = buscaOsSMSnoBANCO();
if(!smsLoteList.isEmpty()){
service.execute(new Runnable() {
@Override
public void run() {
//Envia SMS.............
}
});
service.shutdown();
}
}
}