List of usage examples for java.util List wait
public final void wait() throws InterruptedException
From source file:org.camunda.bpm.ext.sdk.impl.workers.PollTasksRunnable.java
protected void acquire() { final List<WorkerRegistrationImpl> registrations = workerManager.getRegistrations(); final MultiPollRequestDto request = new MultiPollRequestDto(); final Map<String, Worker> workerMap = new HashMap<String, Worker>(); request.clear();//from w w w. j av a2 s. c om workerMap.clear(); synchronized (registrations) { int numOfRegistrations = registrations.size(); if (numOfRegistrations == 0) { try { registrations.wait(); } catch (InterruptedException e) { e.printStackTrace(); // TODO } } for (WorkerRegistrationImpl registration : registrations) { request.topics.add(new PollInstructionDto(registration.getTopicName(), registration.getLockTime(), registration.getVariableNames())); workerMap.put(registration.getTopicName(), registration.getWorker()); } } int tasksAcquired = 0; try { tasksAcquired = poll(request, workerMap); } catch (Exception e) { LOG.exceptionDuringPoll(e); } if (tasksAcquired == 0) { try { // back-off backoffStrategy.run(); } catch (InterruptedException e) { e.printStackTrace(); } } else { backoffStrategy.reset(); } }
From source file:com.ccc.crest.core.client.CrestClient.java
public ClientElement getFreeClient(List<ClientElement> from) { ClientElement client = null;//from w w w . jav a 2 s . c o m synchronized (from) { boolean found = false; do { for (ClientElement cliente : from) if (!cliente.inuse.get()) { cliente.inuse.set(true); client = cliente; found = true; break; } if (found) break; try { from.wait(); } catch (InterruptedException e) { log.warn("unexpected wakeup", e); } } while (true); } return client; }
From source file:org.commonreality.participant.impl.RequestableObjectManagerDelegate.java
/** * get a free identifier that is keyed on key. this may block if none are * available/* w ww .j a v a 2 s . c o m*/ * * @param key * @return */ final public IIdentifier getFreeIdentifier(Object key) { /* * first get the keyed list */ List<IIdentifier> keyedIdentifiers = getKeyedCollection(key); IIdentifier rtn = null; boolean mustRequest = false; synchronized (keyedIdentifiers) { // don't actually request from within the sync. mustRequest = keyedIdentifiers.size() == 0; } if (mustRequest) request(key); synchronized (keyedIdentifiers) { try { while (keyedIdentifiers.size() == 0) keyedIdentifiers.wait(); } catch (InterruptedException ie) { if (LOGGER.isDebugEnabled()) LOGGER.debug("Interrupted while waiting for free identifier"); } if (keyedIdentifiers.size() != 0) rtn = keyedIdentifiers.remove(0); mustRequest = keyedIdentifiers.size() <= _requestMore; } // don't request from within the synch if (mustRequest) request(key); if (LOGGER.isDebugEnabled()) LOGGER.debug("Returning new requested id " + rtn); return rtn; }