This content has been marked as final.
Show 2 replies
-
1. Re: ReentrantLock: How to know which code succesfully locked something?
luxspes Nov 9, 2009 9:31 PM (in response to luxspes)Solved it like this:
@Interceptor(type=InterceptorType.CLIENT) public class ConfigurableSynchronizationInterceptor extends AbstractInterceptor { org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger(ConfigurableSynchronizationInterceptor.class); public ConfigurableSynchronizationInterceptor() { log.debug("Constructor"); } private String getStackTrace(Throwable t) { StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw, true); t.printStackTrace(pw); pw.flush(); sw.flush(); return sw.toString(); } /** * */ private static final long serialVersionUID = 6644552930765616337L; private ReentrantLock lock = new ReentrantLock(true); private String lockedStacktrace; @AroundInvoke public Object aroundInvoke(InvocationContext invocation) throws Exception { log.debug("Will try to get lock for: "+getComponent().getName()); SynchronizationConfiguration cfg=(SynchronizationConfiguration) Component.getInstance("synchronizationConfiguration"); if ( lock.tryLock( cfg.getSynchronizationTimeOut()/*getComponent().getTimeout()*/, TimeUnit.MILLISECONDS ) ) { try { lockedStacktrace = this.getStackTrace(new RuntimeException("Succesfully locked stacktrace")); return invocation.proceed(); } finally { lockedStacktrace = null; lock.unlock(); } } else { throw new LockTimeoutException("could not acquire lock on @Synchronized component: " + getComponent().getName()+" because someone else got it at: "+lockedStacktrace); } } public boolean isInterceptorEnabled() { return getComponent().isSynchronize(); } }
Basically when I succesfully get the lock I store a string representation of the stacktrace, and, if a component fails to get the lock, I take that stored stacktrace representation and append it to the message of the LockTimeoutException.
IMO (unless it is wrong), this should be part for Seam core behavior...
-
2. Re: ReentrantLock: How to know which code succesfully locked something?
luxspes Nov 9, 2009 10:30 PM (in response to luxspes)And so I create JBSEAM-4472