# How Do I: Control the Lifetime of a Web Service?

If several messages between your web service and a client are related to each other, the messages can be associated with one another by using conversations. Methods that start a conversation will create a unique identifier that is returned to the client. Continue methods and callbacks will use this identifier to associate their message with the information that was saved from the start method, while finish methods will end the conversation and remove the unique identifier from the server's conversation persistence cache. For more information, see How Do I: Design a Web Service that Involves Long-Running Operations?

A conversation can also expire after a specified period, as set in the max-age attribute of the conversation-lifetime property. The default duration for a conversation is one day.

To Change the Default Conversation Lifetime

1. In Design View, select your web service.
2. In the Properties pane, expand the conversation-lifetime property.
3. For the max-age attribute, enter the duration you would like to preserve a conversation.

You can also give a conversation a max-idle time, which specifies how much time may pass between subsequent calls before the conversation will expire.

To Change the max-idle-time Property

1. In the Properties pane, expand the conversation-lifetime property.
2. For the max-idle-time attribute, enter the longest allowed duration between messages. Use the default of 0 if you do not want to set a max-idle time.

If a conversation exists for a duration of more than the max-age, or if there are no messages for longer than the max-idle-time, the conversation will be removed from the server's cache.

To Change the Conversation Lifetime at Runtime

A conversation can also be finished at runtime by a call to the JwsContext interface's finishConversation() method. To end a conversation from the server, add this line in the source view where you would like to end the conversation, like shown in the following example:

    import com.bea.control.JwsContext;
    ...
    public class MyWebService implements com.bea.jws.WebService
    {
        /** @common:context */
        JwsContext context;

        public void finish_up()
        {
            ...
            context.finishConversation();
        }
    }

Note. Conversation termination never occurs during the execution of a web service method or callback. Whether the conversation is finished due to the method being marked as a "finish" method, because JwsContext.finishConversation is called, or whether the conversation lifetime expires, the conversation does not actually finish until immediately after execution of any current method invocation.

Related Topics

Managing Conversation Lifetime

@jws:conversation-lifetime Annotation

JwsContext Interface