Re: [jgroups-dev] anyway to do unlock in another thread
Bela Ban <[email protected]> Sun, 28 Apr 2013 18:09:33 +0200
| Newsgroups | gmane.comp.java.javagroups.devel |
|---|---|
| Message-ID | <[email protected]> |
This is a hack. I'd rather fix the original code which doesn't release
the lock, to release it in a finally clause. I consider not releasing a
lock a bug.
On 4/28/13 6:57 AM, hyliu wrote:
> 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?
--
Bela Ban, JGroups lead (http://www.jgroups.org)
------------------------------------------------------------------------------
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