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


Java Lock.lockInterruptibly方法代碼示例

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


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

示例1: interruptibleReaderView

import java.util.concurrent.locks.Lock; //導入方法依賴的package包/類
static Reader interruptibleReaderView(final StampedLock sl,
                                      final long timeout,
                                      final TimeUnit unit,
                                      final Phaser gate) {
    return new Reader("InterruptibleReaderView") { public void run() {
        if (gate != null ) toTheStartingGate(gate);
        final Lock rl = sl.asReadLock();

        try {
            if (timeout < 0)
                rl.lockInterruptibly();
            else
                rl.tryLock(timeout, unit);
            stamp(1L);  // got the lock
            check(sl.isReadLocked());
            check(!sl.isWriteLocked());
        } catch (Throwable x) { thrown(x);
        } finally { if (stamp() != 0L) rl.unlock(); } }};
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:20,代碼來源:Basic.java

示例2: interruptibleWriterView

import java.util.concurrent.locks.Lock; //導入方法依賴的package包/類
static Writer interruptibleWriterView(final StampedLock sl,
                                      final long timeout,
                                      final TimeUnit unit,
                                      final Phaser gate) {
    return new Writer("InterruptibleWriterView") { public void run() {
        if (gate != null ) toTheStartingGate(gate);
        Lock wl = sl.asWriteLock();
        try {
            if (timeout < 0)
                wl.lockInterruptibly();
            else
                wl.tryLock(timeout, unit);
            stamp(1L);  // got the lock
            check(!sl.isReadLocked());
            check(sl.isWriteLocked());
        } catch (Throwable x) { thrown(x);
        } finally { if (stamp() != 0L) wl.unlock(); } }};
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:19,代碼來源:Basic.java

示例3: testTestMethod

import java.util.concurrent.locks.Lock; //導入方法依賴的package包/類
public void testTestMethod() throws Exception {
    MyConditionService service = new MyConditionService();
    new Thread(service::testMethod).start();
    new Thread(service::testMethod).start();
    new Thread(service::testMethod).start();
    new Thread(service::testMethod).start();
    new Thread(service::testMethod).start();

    Lock lock = new ReentrantLock(true);
    lock.lockInterruptibly();
    Thread.sleep(1000 * 5);
}
 
開發者ID:byhieg,項目名稱:JavaTutorial,代碼行數:13,代碼來源:MyConditionServiceTest.java

示例4: call

import java.util.concurrent.locks.Lock; //導入方法依賴的package包/類
/**
   * Execute specified callable in lock of specified name.
   * 
   * @param name
   * 			name of the lock to be acquired
   * @param callable
   * 			callable to be execute within the named lock
   * @return
   * 			return value of the callable
   */
  public static <T> T call(String name, Callable<T> callable) {
  	Lock lock = getLock(name);
  	try {
      	lock.lockInterruptibly();
  		return callable.call();
  	} catch (Exception e) {
  		throw new RuntimeException(e);
} finally {
  		lock.unlock();
  	}
  }
 
開發者ID:jmfgdev,項目名稱:gitplex-mit,代碼行數:22,代碼來源:LockUtils.java

示例5: read

import java.util.concurrent.locks.Lock; //導入方法依賴的package包/類
/**
   * Execute specified callable in read lock of specified name.
   * 
   * @param name
   * 			name of the lock to be acquired
   * @param callable
   * 			callable to be execute within the named read lock
   * @return
   * 			return value of the callable
   */
  public static <T> T read(String name, Callable<T> callable) {
  	Lock lock = getReadWriteLock(name).readLock();
  	try {
      	lock.lockInterruptibly();
  		return callable.call();
  	} catch (Exception e) {
  		throw new RuntimeException(e);
} finally {
  		lock.unlock();
  	}
  }
 
開發者ID:jmfgdev,項目名稱:gitplex-mit,代碼行數:22,代碼來源:LockUtils.java

示例6: write

import java.util.concurrent.locks.Lock; //導入方法依賴的package包/類
/**
   * Execute specified callable in write lock of specified name.
   * 
   * @param name
   * 			name of the lock to be acquired
   * @param callable
   * 			callable to be execute within the named write lock
   * @return
   * 			return value of the callable
   */
  public static <T> T write(String name, Callable<T> callable) {
  	Lock lock = getReadWriteLock(name).writeLock();
  	try {
      	lock.lockInterruptibly();
  		return callable.call();
  	} catch (Exception e) {
  		throw new RuntimeException(e);
} finally {
  		lock.unlock();
  	}
  }
 
開發者ID:jmfgdev,項目名稱:gitplex-mit,代碼行數:22,代碼來源:LockUtils.java

示例7: lockInterruptibly

import java.util.concurrent.locks.Lock; //導入方法依賴的package包/類
public static Locker lockInterruptibly(Lock lock) throws InterruptedException {
    lock.lockInterruptibly();
    return new Locker(lock);
}
 
開發者ID:OvercastNetwork,項目名稱:ProjectAres,代碼行數:5,代碼來源:Locker.java


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