How to decrease the timeout in Jakarta EE 9.1 CDI Conversation Scope (MyFaces 3.0)

90 Views Asked by At

this is Fernando,

I am using JSF 3.0 and and Conversation Scope in some Managed Beans. The problem I am facing is to configure the timeout to expire abandoned conversations. The default 30 minutes is too long to my context and I need to set this around 10 minutes. I have tried to set the timeout using the conversation.setTimeout(10000) method, but, even having the TomEE showing that the correct timeout has been settled, through the conversation.getTimeout(), it keeps expiring the conversation, and consequently destroying the managed beans, only after 30 minutes. The second approach that I have tried is to create openwebbeans.properties file inside the META-INF/openwebbeans directory and putting theese keys:

configuration.ordinal=101
org.apache.webbeans.conversation.Conversation.timeoutInterval=10000

Again the results are the same. TomEE shows the correct timeout through the conversation.getTimeout() method, but keeps expiring the conversation only after 30 minutes.

Following is the code that I have used to test the situation:


package estudosjsf;

import java.io.Serializable;
import java.text.SimpleDateFormat;
import java.util.Date;

import jakarta.annotation.PostConstruct;
import jakarta.annotation.PreDestroy;
import jakarta.enterprise.context.Conversation;
import jakarta.enterprise.context.ConversationScoped;
import jakarta.inject.Inject;
import jakarta.inject.Named;

@Named
@ConversationScoped
public class Controller implements Serializable {

    private static final long serialVersionUID = 1L;
    
    private String text = "This is a simple text";

    @Inject
    private Conversation conversation;

    @PostConstruct
    public void create() {
        System.out.println("Created at " + new SimpleDateFormat("HH:mm:ss").format(new Date()));
    }

    @PreDestroy
    public void destroy() {
        System.out.println("Destroyed at " + new SimpleDateFormat("HH:mm:ss").format(new Date()));
    }

    public void begin() {
        conversation.begin();
        conversation.setTimeout(10000);
        System.out.println(conversation.getTimeout());
    }

    public void end() {
        conversation.end();
    }

    public String getText() {
        return text;
    }

    public void setText(String text) {
        this.text = text;
    }

}

And:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xmlns:h="http://xmlns.jcp.org/jsf/html">
    <h:form>
        Message:
        <br></br>
        <br></br> 
        <h:inputText value="#{controller.text}"/>
        <br></br>
        <br></br>
        <h:commandButton value="Begin" actionListener="#{controller.begin()}" /> 
        <br></br>
        <br></br>
        <h:commandButton value="End" actionListener="#{controller.end()}" />
    </h:form>
</html>

I really appreciate any help!

Thanks!

0

There are 0 best solutions below