以下代码复制了该问题。
Class TestA:
package main.java.monitor;
import javax.ejb.Schedule;
import javax.ejb.Singleton;
@Singleton
public class TestA {
@Schedule(hour="*", minute="*", second="*")
public void run() {
System.out.println("Test A started");
System.out.println("Test A finished");
}
}
Class TestB:
package main.java.monitor;
import javax.ejb.Schedule;
import javax.ejb.Singleton;
@Singleton
public class TestB {
@Schedule(hour="*", minute="*", second="*")
public void run() throws InterruptedException {
System.out.println("Test B started");
Thread.sleep(10000);
System.out.println("Test B finished");
}
}
预期输出(类似)将是测试A开始,测试A比测试B开始和测试B完成的频率高10倍,但实际输出是(添加日期/时间):
Test A started Tue Feb 03 13:09:47 GMT 2015
Test A finished Tue Feb 03 13:09:47 GMT 2015
Test B started Tue Feb 03 13:09:47 GMT 2015
Test A started Tue Feb 03 13:09:48 GMT 2015
Test A finished Tue Feb 03 13:09:48 GMT 2015
Test A started Tue Feb 03 13:09:49 GMT 2015
Test A finished Tue Feb 03 13:09:49 GMT 2015
Test B finished Tue Feb 03 13:09:57 GMT 2015
Test B started Tue Feb 03 13:09:57 GMT 2015
Test A started Tue Feb 03 13:09:58 GMT 2015
Test A finished Tue Feb 03 13:09:58 GMT 2015
Test B finished Tue Feb 03 13:10:07 GMT 2015
Test B started Tue Feb 03 13:10:07 GMT 2015
Test A started Tue Feb 03 13:10:08 GMT 2015
Test A finished Tue Feb 03 13:10:08 GMT 2015
任何人都可以对此有所了解吗?
提前致谢
答案 0 :(得分:1)
我想你会很清楚地添加你的EJB @AccessTimeout(0)
用2个字:默认情况下你的单身人士是@Lock(WRITE)而B是锁定的(每秒执行但等待10)。一旦异步池已满(默认为3个线程),则没有更多线程可用,并且调用正在等待B释放一个插槽。