本文整理汇总了Java中javax.ejb.ConcurrentAccessTimeoutException类的典型用法代码示例。如果您正苦于以下问题:Java ConcurrentAccessTimeoutException类的具体用法?Java ConcurrentAccessTimeoutException怎么用?Java ConcurrentAccessTimeoutException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ConcurrentAccessTimeoutException类属于javax.ejb包,在下文中一共展示了ConcurrentAccessTimeoutException类的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: timeout
import javax.ejb.ConcurrentAccessTimeoutException; //导入依赖的package包/类
@Timeout
public void timeout(Timer timer) {
final Cache<String, ExecutionControl> cache = GlobalCache.get().getExecutionControls();
String info = (String) timer.getInfo();
try {
int n = info.indexOf(' ');
String execCtrlName = info.substring(0, n);
int cycleNum = Integer.parseInt(info.substring(n + 1));
ExecutionControl execCtrl = cache.get(execCtrlName);
if (execCtrl != null)
execCtrl.onTimeout(cycleNum);
else
logger.log(Level.WARNING, "ExecutionControl " + execCtrlName + " not found.");
} catch (ConcurrentAccessTimeoutException ex) {
logger.warning(ex.getMessage());
}
}
示例2: testConcurrentMethodCall
import javax.ejb.ConcurrentAccessTimeoutException; //导入依赖的package包/类
public void testConcurrentMethodCall() throws Exception {
MyLocalBeanImpl.semaphore = new Semaphore(0);
final InitialContext ctx = new InitialContext();
final MyLocalBean bean = (MyLocalBean) ctx.lookup("MyLocalBeanImplLocal");
final MyLocalBean bean2 = (MyLocalBean) ctx.lookup("MyLocalBeanImplLocal");
final CallRentrantThread call = new CallRentrantThread(bean, 3000);
(new Thread(call)).start();
// ensure the call on thread came in
assertTrue(MyLocalBeanImpl.semaphore.tryAcquire(1, 30, TimeUnit.SECONDS));
try {
java.util.logging.Logger.getLogger(this.getClass().getName()).info("Expecting a SEVERE javax.ejb.ConcurrentAccessTimeoutException");
bean2.callRentrant(bean, 0);
fail("Expected exception");
} catch (final Exception e) {
if (e.getCause() instanceof ConcurrentAccessTimeoutException) {
// that's what we want
} else {
throw e;
}
}
}
示例3: aquireLock
import javax.ejb.ConcurrentAccessTimeoutException; //导入依赖的package包/类
private Lock aquireLock(final boolean read, final Duration accessTimeout, final Instance instance, final Method runMethod) {
final Lock lock;
if (read) {
lock = instance.lock.readLock();
} else {
lock = instance.lock.writeLock();
}
final boolean lockAcquired;
if (accessTimeout == null || accessTimeout.getTime() < 0) {
// wait indefinitely for a lock
//noinspection LockAcquiredButNotSafelyReleased
lock.lock();
lockAcquired = true;
} else if (accessTimeout.getTime() == 0) {
// concurrent calls are not allowed, lock only once
lockAcquired = lock.tryLock();
} else {
// try to get a lock within the specified period.
try {
lockAcquired = lock.tryLock(accessTimeout.getTime(), accessTimeout.getUnit());
} catch (final InterruptedException e) {
throw (ConcurrentAccessTimeoutException) new ConcurrentAccessTimeoutException("Unable to get " +
(read ? "read" : "write") +
" lock within specified time on '" +
runMethod.getName() +
"' method for: " +
instance.bean.getClass().getName()).initCause(e);
}
}
// Did we acquire the lock to the current execution?
if (!lockAcquired) {
throw new ConcurrentAccessTimeoutException("Unable to get " +
(read ? "read" : "write") +
" lock on '" +
runMethod.getName() +
"' method for: " +
instance.bean.getClass().getName());
}
return lock;
}
示例4: testStatelessBeanTimeout
import javax.ejb.ConcurrentAccessTimeoutException; //导入依赖的package包/类
public void testStatelessBeanTimeout() throws Exception {
final InitialContext ctx = new InitialContext();
final Object object = ctx.lookup("CounterBeanLocal");
assertTrue("instanceof counter", object instanceof Counter);
final CountDownLatch timeouts = new CountDownLatch(10);
final CountDownLatch startPistol = new CountDownLatch(1);
final CountDownLatch startingLine = new CountDownLatch(10);
final Counter counter = (Counter) object;
// Do a business method...
final Runnable r = new Runnable() {
public void run() {
try {
counter.race(startingLine, startPistol);
} catch (final ConcurrentAccessTimeoutException ex) {
comment("Leap Start");
timeouts.countDown();
}
}
};
comment("On your mark!");
for (int i = 0; i < 20; i++) {
final Thread t = new Thread(r);
t.start();
}
// Wait for the beans to reach the start line
assertTrue("expected 10 invocations", startingLine.await(3000, TimeUnit.MILLISECONDS));
comment("Get Set!");
// Wait for the other beans timeout
assertTrue("expected 10 timeouts", timeouts.await(3000, TimeUnit.MILLISECONDS));
assertEquals(10, instances.get(), 1.1);
comment("Go!");
startPistol.countDown(); // go
}