Re: [jgroups-dev] anyway to do unlock in another thread
hyliu <[email protected]> Sat, 27 Apr 2013 21:57:27 -0700 (PDT)
| Newsgroups | gmane.comp.java.javagroups.devel |
|---|---|
| Message-ID | <[email protected]> |
I find a way, I know it's ugly, but it seems no better choice.
customize CENTRAL_LOCK, add a hack to let the new thread pretend the
original thread. code is below. I tested it works.
public class OptimizedCENTRAL_LOCK extends CENTRAL_LOCK {
public static ThreadLocal<Long> threadId = new ThreadLocal<Long>();
@Override
protected Owner getOwner() {
Long hackId = threadId.get();
if (hackId != null){
return new Owner(local_addr, hackId);
}
return super.getOwner();
}
public static void pretendThread(long originalThreadId){
threadId.set(originalThreadId);
}
public static void unpretendThread(){
threadId.remove();
}
}
the jmx bean to cleanup lock is below:
public boolean unLock(String lockName, long originalLockThreadId) {
try {
OptimizedCENTRAL_LOCK.pretendThread(originalLockThreadId);
lockService_.getLock(lockName).unlock();
} finally {
OptimizedCENTRAL_LOCK.unpretendThread();
}
return true;
}
original lock thread id is can be get from LockService.printLocks()
...any side effect in this way?
--
View this message in context: http://jgroups.1086181.n5.nabble.com/anyway-to-do-unlock-in-another-thread-tp9574p9576.html
Sent from the JGroups - Dev mailing list archive at Nabble.com.
------------------------------------------------------------------------------
Try New Relic Now & We'll Send You this Cool Shirt
New Relic is the only SaaS-based application performance monitoring service
that delivers powerful full stack analytics. Optimize and monitor your
browser, app, & servers with just a few lines of code. Try New Relic
and get this awesome Nerd Life shirt! http://p.sf.net/sfu/newrelic_d2d_apr
_______________________________________________
Javagroups-development mailing list