当前位置: 首页>>代码示例>>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;未经允许,请勿转载。