How to make Requestcontext thread-safe?

Asked

Viewed 84 times

0

In one project I am using the component "Demoiselle-Scheduler-Quartz". 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 task execution, and disables 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 with the class org.jboss.weld.context.AbstractManagedContext:

public abstract class AbstractManagedContext extends AbstractContext implements ManagedContext {

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

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

1 answer

0

It was not clear to me what the issue of competition is. So I will not go into this merit.

From what I understand you want to create an alternative implementation of Requestcontext that would not present this problem. Thus, to inject its alternative implementation, in addition to using the tag @Alternative 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>
  • I had already declared my implementation in Beans.xml as you suggested, but it still doesn’t work. I believe that the way Demoiselle-core was implemented prevents the injection of context "alternatives". See: br.gov.frameworkdemoiselle.internal.context.CustomContextProducer and br.gov.frameworkdemoiselle.internal.bootstrap.CustomContextBootstrap

Browser other questions tagged

You are not signed in. Login or sign up in order to post.