當前位置: 首頁>>代碼示例>>Java>>正文


Java Semaphore.acquireUninterruptibly方法代碼示例

本文整理匯總了Java中java.util.concurrent.Semaphore.acquireUninterruptibly方法的典型用法代碼示例。如果您正苦於以下問題:Java Semaphore.acquireUninterruptibly方法的具體用法?Java Semaphore.acquireUninterruptibly怎麽用?Java Semaphore.acquireUninterruptibly使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.util.concurrent.Semaphore的用法示例。


在下文中一共展示了Semaphore.acquireUninterruptibly方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: loop

import java.util.concurrent.Semaphore; //導入方法依賴的package包/類
final int loop(int n) {
    final Semaphore sem = this.sem;
    int sum = 0;
    int x = 0;
    while (n-- > 0) {
        sem.acquireUninterruptibly();
        try {
            x = setValue(LoopHelpers.compute1(getValue()));
        }
        finally {
            sem.release();
        }
        sum += LoopHelpers.compute2(x);
    }
    return sum;
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:17,代碼來源:CheckedLockLoops.java

示例2: lock

import java.util.concurrent.Semaphore; //導入方法依賴的package包/類
/**
 * 鎖定key,其他等待此key的線程將進入等待,直到調用{@link #unlock(K)}
 * 使用hashcode和equals來判斷key是否相同,因此key必須實現{@link #hashCode()}和
 * {@link #equals(Object)}方法
 *
 * @param key
 */
public void lock(K key) {
    if (key == null)
        return;
    LockInfo info = local.get().get(key);
    if (info == null) {
        Semaphore current = new Semaphore(1);
        current.acquireUninterruptibly();
        Semaphore previous = map.put(key, current);
        if (previous != null)
            previous.acquireUninterruptibly();
        local.get().put(key, new LockInfo(current));
    } else {
        info.lockCount++;
    }
}
 
開發者ID:gzxishan,項目名稱:OftenPorter,代碼行數:23,代碼來源:ConcurrentKeyLock.java

示例3: getResult

import java.util.concurrent.Semaphore; //導入方法依賴的package包/類
public R getResult() {
  final List<R> results = new ArrayList<>(1);
  final Semaphore semaphore = new Semaphore(0);
  run(new Subscriber<R>() {
    @Override public void onSuccess(R result) {
      results.add(0, result);
      semaphore.release();
    }

    @Override public void onError(Exception exception) {
      semaphore.release();
    }
  });
  semaphore.acquireUninterruptibly();
  return !results.isEmpty() ? results.get(0) : null;
}
 
開發者ID:softonic,項目名稱:instamaterial,代碼行數:17,代碼來源:ObservableTask.java

示例4: save

import java.util.concurrent.Semaphore; //導入方法依賴的package包/類
public Publisher<Integer> save(Publisher<Customer> customers) throws IOException {
  AsynchronousFileChannel fileChannel = AsynchronousFileChannel.open(path, StandardOpenOption.WRITE);
  AtomicLong offset = new AtomicLong(0);
  AtomicInteger resultCount = new AtomicInteger(0);
  SingleItemPublisher<Integer> resultPublisher = new SingleItemPublisher<>();
  Semaphore writeSemaphore = new Semaphore(1);
  writeSemaphore.acquireUninterruptibly();
  fileChannel.write(ByteBuffer.wrap("[".getBytes()), 0, resultPublisher,
      andThen((count, s) -> {
        writeSemaphore.release();
        customers.subscribe(pullEach((Customer customer, Subscription subscription) -> {
            String json = String.format("%s{\"firstName\": \"%s\", \"lastName\": \"%s\"}", offset.longValue() == 0 ? "" : ",",
                customer.getFirstName(), customer.getLastName());
            offset.addAndGet(count);
            writeSemaphore.acquireUninterruptibly();
            fileChannel.write(ByteBuffer.wrap(json.getBytes()), offset.get(), resultPublisher,
                andThen((size, c) -> {
                  writeSemaphore.release();
                  offset.addAndGet(size);
                  resultCount.incrementAndGet();
                  subscription.request(1);
                }));
          }).andThen(() -> {
            writeSemaphore.acquireUninterruptibly();
              fileChannel.write(ByteBuffer.wrap("]".getBytes()), offset.longValue(), resultPublisher,
                  andThen((d, e) -> {
                    writeSemaphore.release();
                    try {
                      fileChannel.close();
                      resultPublisher.publish(resultCount.intValue());
                    } catch (IOException error) {
                      resultPublisher.publish(error);
                    }
                  }));
          }).exceptionally(error -> resultPublisher.publish(error)));
      }));
  return resultPublisher;
}
 
開發者ID:openknowledge,項目名稱:reactive-jax-rs,代碼行數:39,代碼來源:CustomerRepository.java

示例5: startTest

import java.util.concurrent.Semaphore; //導入方法依賴的package包/類
private void startTest() {
    stopped.set(false);
    RateLimiter limiter = RateLimiter.create(rate);
    Semaphore s = new Semaphore(100);
    while (!stopped.get()) {
        limiter.acquire();
        s.acquireUninterruptibly();
        counters.get(RandomUtils.nextInt(TOTAL_COUNTERS)).incrementAndGet().whenComplete((r, e) -> {
            s.release();
            if (e == null) {
                increments.incrementAndGet();
            }
        });
    }
}
 
開發者ID:shlee89,項目名稱:athena,代碼行數:16,代碼來源:DistributedConsensusLoadTest.java

示例6: SyncCallback

import java.util.concurrent.Semaphore; //導入方法依賴的package包/類
public SyncCallback() {
    m_response = null;
    m_lock = new Semaphore(1);
    m_lock.acquireUninterruptibly();
}
 
開發者ID:s-store,項目名稱:sstore-soft,代碼行數:6,代碼來源:SyncCallback.java

示例7: acquire

import java.util.concurrent.Semaphore; //導入方法依賴的package包/類
void acquire(Semaphore s) {
    s.acquireUninterruptibly();
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:4,代碼來源:SemaphoreTest.java


注:本文中的java.util.concurrent.Semaphore.acquireUninterruptibly方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。