本文整理了Java中sun.misc.Unsafe.monitorExit()
方法的一些代码示例,展示了Unsafe.monitorExit()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Unsafe.monitorExit()
方法的具体详情如下:
包路径:sun.misc.Unsafe
类名称:Unsafe
方法名:monitorExit
[英]Unlock the object. It must have been locked via #monitorEnter.
[中]解锁对象。它一定是通过#监控中心锁定的。
代码示例来源:origin: org.apache.cassandra/cassandra-all
public static void monitorExitUnsafe(Object object)
{
if (unsafe != null)
unsafe.monitorExit(object);
}
}
代码示例来源:origin: jsevellec/cassandra-unit
public static void monitorExitUnsafe(Object object)
{
if (unsafe != null)
unsafe.monitorExit(object);
}
}
代码示例来源:origin: com.netflix.sstableadaptor/sstable-adaptor-cassandra
public static void monitorExitUnsafe(Object object)
{
if (unsafe != null)
unsafe.monitorExit(object);
}
}
代码示例来源:origin: lihengming/java-codes
public void unlock(Object obj) {
unsafe.monitorExit(obj);
}
代码示例来源:origin: com.facebook.presto.cassandra/cassandra-server
public static void monitorExitUnsafe(Object object)
{
if (unsafe != null)
unsafe.monitorExit(object);
}
}
代码示例来源:origin: com.strapdata.cassandra/cassandra-all
public static void monitorExitUnsafe(Object object)
{
if (unsafe != null)
unsafe.monitorExit(object);
}
}
代码示例来源:origin: kabutz/javaspecialists
public static void unsynchronize(Object monitor) {
unsafe.monitorExit(monitor);
}
}
代码示例来源:origin: org.terracotta/terracotta-l1-ee
public static void monitorExit(Object object) {
unsafe.monitorExit(object);
}
代码示例来源:origin: org.terracotta/terracotta-ee
public static void monitorExit(Object object) {
unsafe.monitorExit(object);
}
代码示例来源:origin: com.tomitribe.tribestream/tribestream-metrics-bytecode
public static void monitorExit(final Object o) {
UNSAFE.monitorExit(o);
}
代码示例来源:origin: GeeQuery/ef-orm
/**
* 释放因为lock/tryLock方法得到的锁
*
* @param obj
*/
@SuppressWarnings("restriction")
public static void unlock(Object obj) {
sun.misc.Unsafe unsafe = UnsafeUtils.getUnsafe();
unsafe.monitorExit(obj);
}
代码示例来源:origin: org.terracotta/terracotta-ee
/**
* Completely release the monitor on the given object (calling thread needs to own the monitor obviously)
*
* @return the number of monitorExit calls performed
*/
public static int releaseMonitor(Object object) {
if (object == null) { throw new NullPointerException("object is null"); }
if (!Thread.holdsLock(object)) { throw new IllegalMonitorStateException("not monitor owner"); }
// This has the side effect of inflating the monitor (see VM source). It may not be necessary on all platforms (and
// can be optimized as such if necessary).
unsafe.monitorEnter(object);
unsafe.monitorExit(object);
int count = 0;
while (Thread.holdsLock(object)) {
unsafe.monitorExit(object);
count++;
}
return count++;
}
}
代码示例来源:origin: org.terracotta/terracotta-l1-ee
/**
* Completely release the monitor on the given object (calling thread needs to own the monitor obviously)
*
* @return the number of monitorExit calls performed
*/
public static int releaseMonitor(Object object) {
if (object == null) { throw new NullPointerException("object is null"); }
if (!Thread.holdsLock(object)) { throw new IllegalMonitorStateException("not monitor owner"); }
// This has the side effect of inflating the monitor (see VM source). It may not be necessary on all platforms (and
// can be optimized as such if necessary).
unsafe.monitorEnter(object);
unsafe.monitorExit(object);
int count = 0;
while (Thread.holdsLock(object)) {
unsafe.monitorExit(object);
count++;
}
return count++;
}
}
代码示例来源:origin: lihengming/java-codes
@Test
public void test6() throws Exception {
Object lock = new Object();
//注掉下面这行代码则抛出java.lang.IllegalMonitorStateException
unsafe.monitorEnter(lock);
lock.wait(1000);
System.out.println("Hello World");
unsafe.monitorExit(lock);
}
}
代码示例来源:origin: stackoverflow.com
private static sun.misc.Unsafe getUnsafe() {
try {
Field field = sun.misc.Unsafe.class.getDeclaredField("theUnsafe");
field.setAccessible(true);
return (Unsafe) field.get(null);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
public void doSomething() {
Object record = new Object();
sun.misc.Unsafe unsafe = getUnsafe();
if (unsafe.tryMonitorEnter(record)) {
try {
// record is locked - perform operations on it
} finally {
unsafe.monitorExit(record);
}
} else {
// could not lock record
}
}
代码示例来源:origin: org.gridgain/gridgain-core
UNSAFE.monitorExit(locked.get(j));
代码示例来源:origin: GeeQuery/ef-orm
/**
* 判断当前该对象是否已锁。<br> 注意在并发场景下,这一操作只能反映瞬时的状态,仅用于检测,并不能认为本次检测该锁空闲,紧接着的代码就能得到锁。
*
* @param obj
* @return
*/
@SuppressWarnings("restriction")
public static boolean isLocked(Object obj) {
sun.misc.Unsafe unsafe = UnsafeUtils.getUnsafe();
if (unsafe.tryMonitorEnter(obj)) {
unsafe.monitorExit(obj);
return false;
}
return true;
}
代码示例来源:origin: org.gridgain/gridgain-core
UNSAFE.monitorExit(entry);
else
return Collections.singletonList(entry);
UNSAFE.monitorExit(locked.get(j));
代码示例来源:origin: org.gridgain/gridgain-core
/**
* Releases java-level locks on cache entries.
*
* @param locked Locked entries.
*/
private void unlockEntries(Iterable<GridCacheEntryEx<K, V>> locked) {
for (GridCacheEntryEx<K, V> entry : locked)
UNSAFE.monitorExit(entry);
long topVer = ctx.affinity().affinityTopologyVersion();
for (GridCacheEntryEx<K, V> entry : locked)
ctx.evicts().touch(entry, topVer);
}
代码示例来源:origin: org.gridgain/gridgain-core
UNSAFE.monitorExit(entry);
内容来源于网络,如有侵权,请联系作者删除!