EJB @Lock doesn't work as expected
I have a scheduled EJB that calls a Singleton EJB. For some reason, the scheduled method is executed twice in each schedule (something to do with the WAR file reference as well as the EAR). To counter this, I put an annotation @Lock
on the method in the @Singleton
bean, but it still gets executed twice at the same time:
@Stateless
public class PaymoTimer {
@EJB
private IPaymoManagerRemote manager;
@Schedule(hour = "10,12,14,16", minute = "41", second = "0", info = "PaymoTimer")
public void timer() throws Exception {
manager.generateEmailReport();
}
}
@LocalBean
@Singleton
public class PaymoManager implements IPaymoManagerRemote {
@Override
@Lock(LockType.WRITE)
public void generateEmailReport() {
System.out.println("generateEmailReport");
String text = getDailySummaryForUser();
System.out.println("done");
}
}
My console prints the following data:
12:42:00,008 INFO [stdout] (EJB default - 10) generateEmailReport
12:42:00,009 INFO [stdout] (EJB default - 9) generateEmailReport
12:42:24,027 INFO [stdout] (EJB default - 10) done
12:42:24,323 INFO [stdout] (EJB default - 9) done
Looking at the time and process ID, it becomes clear that the method is called while the previous instance is still running.
I don't understand what annotation means @Lock
?
+3
source to share