How to make RequestContext thread-safe?

0

In a project I'm using the demoiselle-scheduler-quartz component. In this project several threads are fired and executed concurrently. The demoiselle-scheduler-quartz component injects the Demoiselle contexts (RequestContext, SessionContext, ViewContext, ConversationContext), activates them, invokes the execution of the task, and deactivates them. But sporadically occurs ContextNotActiveException.

Looking at the Demoiselle source code I noticed the class br.gov.frameworkdemoiselle.internal.context.AbstractCustomContext :

public abstract class AbstractCustomContext implements CustomContext {

    private boolean active;
    ...
}

and compared to class org.jboss.weld.context.AbstractManagedContext :

public abstract class AbstractManagedContext extends AbstractContext implements ManagedContext {

    private final ThreadLocal<Boolean> active;
    ...
}

I do not know if the implementation was intentional or a bug, but is there any way to make RequestContext thread-safe? I tried to implement a @Alternative RequestContext , but it is always injected to br.gov.frameworkdemoiselle.internal.context.TemporaryRequestContextImpl . I also tried setting a @Produces RequestContext method, but it did not work either.

    
asked by anonymous 11.10.2016 / 22:05

1 answer

0

It has not been clear to me what the competition is. So I will not go into that merit.

So I understand you want to create an alternative implementation of RequestContext that would not have this problem. So to inject your alternate implementation, in addition to using the @Alternative tag in the class you have to put in your beans.xml that you want to use that implementation.

<beans ... >
...
    <alternatives>
        <class>meu.pacote.MeuContextoAlternativo</class>
    </alternatives>
...
</beans>
    
12.10.2016 / 18:14