Examples of Semaphore


Examples of java.util.concurrent.Semaphore

        this.bestMove = new ConcurrentHashMap<SpecificRole, Integer>();
        this.instances = new AtomicInteger(0);
        this.timeoutForSnapshot = timeoutForSnapshot;
        this.startTime = System.currentTimeMillis();
        this.fullfilled = false;
        this.termination = new Semaphore(0);
        this.feedAssetCache = feedAssetCache;
        this.useAssetCache = useAssetCache;
    }
View Full Code Here

Examples of java.util.concurrent.Semaphore

  private void decreaseUsed(Host host) {
    getSemaphore(host).release();
  }
 
  private Semaphore getSemaphore(Host host) {
    Semaphore semaphore = used.get(host);
    if (semaphore == null) {
      semaphore = new Semaphore(maxConnectionsPerHost);
      Semaphore exist = used.putIfAbsent(host, semaphore);
      semaphore = exist == null ? semaphore : exist;
    }
    return semaphore;
  }
View Full Code Here

Examples of java.util.concurrent.Semaphore

  private final Collection<V>          unmodifiableresources;
  private OResourcePoolListener<K, V>  listener;

  public OResourcePool(final int iMaxResources, final OResourcePoolListener<K, V> iListener) {
    listener = iListener;
    sem = new Semaphore(iMaxResources + 1, true);
    unmodifiableresources = Collections.unmodifiableCollection(resources);
  }
View Full Code Here

Examples of java.util.concurrent.Semaphore

  public void init(FilterConfig config)
    throws ServletException
  {
    if (_maxTotalRequests > 0)
      _requestSemaphore = new Semaphore(_maxTotalRequests);
  }
View Full Code Here

Examples of java.util.concurrent.Semaphore

      concurrentTimeout = Long.MAX_VALUE / 2;
   
    _concurrentTimeout = concurrentTimeout;
   
    if (concurrentMax > 0)
      _concurrentSemaphore = new Semaphore(concurrentMax);
    else
      _concurrentSemaphore = null;
  }
View Full Code Here

Examples of java.util.concurrent.Semaphore

      _concurrentSemaphore = null;
  }
 
  public Item<X> allocate()
  {
    Semaphore semaphore = _concurrentSemaphore;
   
    if (semaphore != null) {
      try {
        Thread.interrupted();
        if (! semaphore.tryAcquire(_concurrentTimeout, TimeUnit.MILLISECONDS))
          throw new RuntimeException(L.l("{0} concurrent max exceeded", this));
      } catch (Exception e) {
        throw new RuntimeException(e);
      }
    }
   
    boolean isValid = false;
   
    try {
      Item<X> beanItem = _freeList.allocate();
   
      if (beanItem == null) {
        CreationalContextImpl<X> env = new OwnerCreationalContext<X>(_manager.getBean());
        Object []bindings;

        X instance = _context.newInstance(env);
       
        bindings = _manager.getInterceptorBindings(_interceptorBeans, env);
              
        if (instance instanceof SessionBean) {
          try {
            ((SessionBean) instance).setSessionContext(_context);
          } catch (Exception e) {
            log.log(Level.WARNING, e.toString(), e);
          }
        }
       
        beanItem = new Item<X>(instance, bindings);
       
        Item<X> oldInstance = _lifecycleInstanceLocal.get();
        try {
          _lifecycleInstanceLocal.set(beanItem);
         
          _proxy.__caucho_postConstruct();
        } catch (RuntimeException e) {
          throw e;
        } catch (Exception e) {
          throw new RuntimeException(e);
        } finally {
          _lifecycleInstanceLocal.set(oldInstance);
        }
        // _ejbProducer.newInstance();
      }
     
      isValid = true;
     
      _manager.setLocalStatelessPool(this);
   
      return beanItem;
    } finally {
      if (! isValid && semaphore != null)
        semaphore.release();
    }
  }
View Full Code Here

Examples of java.util.concurrent.Semaphore

    return _lifecycleInstanceLocal.get();
  }

  public void free(Item<X> beanItem)
  {
    Semaphore semaphore = _concurrentSemaphore;
    if (semaphore != null)
      semaphore.release();
   
    _manager.setLocalStatelessPool(null);
   
    if (! _freeList.free(beanItem)) {
      destroyImpl(beanItem);
View Full Code Here

Examples of java.util.concurrent.Semaphore

  public void destroy(Item<X> beanItem)
  {
    if (beanItem == null)
      return;
   
    Semaphore semaphore = _concurrentSemaphore;
    if (semaphore != null)
      semaphore.release();
   
    _manager.setLocalStatelessPool(null);
   
    destroyImpl(beanItem);
  }
View Full Code Here

Examples of java.util.concurrent.Semaphore

  public void discard(Item<X> beanItem)
  {
    if (beanItem == null)
      return;
   
    Semaphore semaphore = _concurrentSemaphore;
    if (semaphore != null)
      semaphore.release();
  }
View Full Code Here

Examples of java.util.concurrent.Semaphore

              EncryptionConfiguration.CIPHER_PROVIDER + " is present while " +
          "key provider name is not.");
    }

    if(queueRemaining == null) {
      queueRemaining = new Semaphore(capacity, true);
    }
    if(log != null) {
      log.setCheckpointInterval(checkpointInterval);
      log.setMaxFileSize(maxFileSize);
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.