Search in sources :

Example 51 with ReentrantReadWriteLock

use of java.util.concurrent.locks.ReentrantReadWriteLock in project jena by apache.

the class TestTDBInternal method exclusive_2.

@Test
public void exclusive_2() {
    DatasetGraph dsg = TDBFactory.createDatasetGraph();
    TransactionManager txnmgr = TDBInternal.getTransactionManager(dsg);
    checkTxnMgr(txnmgr, 0, 0);
    ReentrantReadWriteLock rwx = (ReentrantReadWriteLock) txnmgr.getExclusivityLock$();
    checkLock(rwx, 0, 0);
    dsg.begin(ReadWrite.READ);
    checkLock(rwx, 1, 0);
    checkTxnMgr(txnmgr, 1, 0);
    dsg.end();
    checkLock(rwx, 0, 0);
    checkTxnMgr(txnmgr, 0, 0);
}
Also used : ReentrantReadWriteLock(java.util.concurrent.locks.ReentrantReadWriteLock) DatasetGraph(org.apache.jena.sparql.core.DatasetGraph) Test(org.junit.Test)

Example 52 with ReentrantReadWriteLock

use of java.util.concurrent.locks.ReentrantReadWriteLock in project tomee by apache.

the class SingletonInstanceManager method createInstance.

private Instance createInstance(final ThreadContext callContext, final BeanContext beanContext) throws ApplicationException {
    try {
        initializeDependencies(beanContext);
        final InstanceContext context = beanContext.newInstance();
        if (context.getBean() instanceof SessionBean) {
            final Operation originalOperation = callContext.getCurrentOperation();
            try {
                callContext.setCurrentOperation(Operation.CREATE);
                final Method create = beanContext.getCreateMethod();
                final InterceptorStack ejbCreate = new InterceptorStack(context.getBean(), create, Operation.CREATE, new ArrayList<InterceptorData>(), new HashMap());
                ejbCreate.invoke();
            } finally {
                callContext.setCurrentOperation(originalOperation);
            }
        }
        final ReadWriteLock lock;
        if (beanContext.isBeanManagedConcurrency()) {
            // Bean-Managed Concurrency
            lock = new BeanManagedLock();
        } else {
            // Container-Managed Concurrency
            lock = new ReentrantReadWriteLock();
        }
        return new Instance(context.getBean(), context.getInterceptors(), context.getCreationalContext(), lock);
    } catch (Throwable e) {
        if (e instanceof InvocationTargetException) {
            e = ((InvocationTargetException) e).getTargetException();
        }
        final String t = "The bean instance " + beanContext.getDeploymentID() + " threw a system exception:" + e;
        logger.error(t, e);
        throw new ApplicationException(new NoSuchEJBException("Singleton failed to initialize").initCause(e));
    }
}
Also used : NoSuchEJBException(javax.ejb.NoSuchEJBException) HashMap(java.util.HashMap) SystemInstance(org.apache.openejb.loader.SystemInstance) Operation(org.apache.openejb.core.Operation) Method(java.lang.reflect.Method) SessionBean(javax.ejb.SessionBean) ReentrantReadWriteLock(java.util.concurrent.locks.ReentrantReadWriteLock) InvocationTargetException(java.lang.reflect.InvocationTargetException) ApplicationException(org.apache.openejb.ApplicationException) ReentrantReadWriteLock(java.util.concurrent.locks.ReentrantReadWriteLock) ReadWriteLock(java.util.concurrent.locks.ReadWriteLock) InstanceContext(org.apache.openejb.core.InstanceContext) InterceptorStack(org.apache.openejb.core.interceptor.InterceptorStack) InterceptorData(org.apache.openejb.core.interceptor.InterceptorData)

Aggregations

ReentrantReadWriteLock (java.util.concurrent.locks.ReentrantReadWriteLock)52 ReadWriteLock (java.util.concurrent.locks.ReadWriteLock)17 Test (org.junit.Test)15 ArrayList (java.util.ArrayList)6 Lock (java.util.concurrent.locks.Lock)5 DatasetGraph (org.apache.jena.sparql.core.DatasetGraph)5 HashMap (java.util.HashMap)4 IgniteInternalFuture (org.apache.ignite.internal.IgniteInternalFuture)4 Nullable (org.jetbrains.annotations.Nullable)4 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)3 InternalErrorException (cz.metacentrum.perun.core.api.exceptions.InternalErrorException)2 IOException (java.io.IOException)2 List (java.util.List)2 TreeSet (java.util.TreeSet)2 ExecutorService (java.util.concurrent.ExecutorService)2 AtomicLong (java.util.concurrent.atomic.AtomicLong)2 ReentrantLock (java.util.concurrent.locks.ReentrantLock)2 PostLoad (javax.persistence.PostLoad)2 Configuration (org.apache.hadoop.conf.Configuration)2 Path (org.apache.hadoop.fs.Path)2