0

i'm new in JSF and i'm trying to create a method that schedule a simple task. I've created the task below using the annotation "Schedule" from ejb 3.2 and i've created the managed bean with the annotation "ApplicationScoped". Every time I start my server, the builder runs and print the line, but the annotated method is not working. I'm using JSF 2.0, Tomcat 8.0

package br.ifsp.eBlueCard.bean
import java.util.List;
import javax.ejb.Schedule;
import javax.faces.bean.ApplicationScoped;
import javax.faces.bean.ManagedBean;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import br.ifsp.eBlueCard.entities.ECard;
import br.ifsp.eBlueCard.repository.ECardRepository;

@ManagedBean(eager=true)
@ApplicationScoped
public class TimerEmailBean {
private List<ECard> ecards;

public TimerEmailBean(){
    System.out.println("I'm alive.");
}

@Schedule(second="*", minute="*", hour="*")
public void listaECards(){
    System.out.println("Hi, me too.");
    /*EntityManagerFactory factory = Persistence.createEntityManagerFactory("eBlueCard");

    EntityManager manager = factory.createEntityManager();

    ECardRepository ecr = new ECardRepository(manager);
    try{
    this.ecards = ecr.buscaEcardsAtivos();
    }catch(Exception e){
        System.out.println("VAZIO");
    }
    if(this.ecards.size() > 0){
        for(int i=0;i<ecards.size();i++){
            System.out.println(this.ecards.get(i).getCliente().getNome());
        }
    }else{
        System.out.println("VAZIO");
    }*/
}

public List<ECard> getEcards() {
    return ecards;
}

public void setEcards(List<ECard> ecards) {
    this.ecards = ecards;
}
}
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • Good start for a first question, but you need to explain more about how the annotated code isnt working - e.g. errors (and on which line the occur) and/or detailing the results you expect and the results that you're getting. Cheers. Welcome to Stack Overflow. – David Wilson May 13 '16 at 14:52
  • See the duplicate for the technical answer. Additionally, do note that Tomcat doesn't support EJB. Only TomEE and others does. "Just" adding a bunch of EJB JAR files merely to get the code to compile ain't gonna work. See also a.o. http://stackoverflow.com/q/7295096 – BalusC May 13 '16 at 14:53
  • @BalusC Hey, thanks for the help. I'm sorry, I did not realize that there were other questions with the same theme. I solved my problem using this http://stackoverflow.com/questions/7499534/spawning-threads-in-a-jsf-managed-bean-for-scheduled-tasks-using-a-timerquestion that you answered. Do you know if i'm using this ScheduledExecutorService and creating new instances from the class that executes the daily job, I'm taking up memory spaces on the server all the time the job is executed? The instance that was created is deleted after the job is executed? Thanks and sorry for bad english – Victor Senna May 18 '16 at 21:26

0 Answers0