I'm using the following code to test the operation of ConversationScoped, but I don't understand how it works. I open conversation, set the value of conversationBean.i = 1, then close conversation and open a new conversation, but the value of conversationBean.i is still 1, why? it was supposed to be null, wasn't it?
@WebServlet(value = "/tes")
public class MyTag extends HttpServlet {
@Inject
ConversationBean conversationBean;
@Override
protected void doGet(HttpServletRequest req,
HttpServletResponse resp) {
conversationBean.startConversation();
conversationBean.doSomething();
conversationBean.out();
conversationBean.endConversation();
conversationBean.startConversation();
conversationBean.out();
}
}
@ConversationScoped
class ConversationBean implements Serializable {
int i = 0;
@Inject
private Conversation conversation;
public void startConversation() {
conversation.begin();
}
public void doSomething() {
i++;
}
public void out() {
System.out.println(i);
}
public void endConversation() {
conversation.end();
}
}
Tell me, maybe I got it wrong? If so, could you provide an easy example where it really shows that when closing a conversation, all the resources associated with it are cleared?