# How Do I: Associate Code With the End of a Conversation?

When a conversation ends, the onFinish callback of the JwsContext interface is invoked. You can write code to be executed at the end of a conversation by adding a handler for this callback to your web service, 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 context_onFinish(boolean expired)
        {
            /* If the conversation has ended because it expired, tell the client
               that results will not be coming. */
            if(expired){
                callback.onError("Results unavailable at this time. Please try again.");
    		}
        }
    }

The argument to onFinish is a boolean value that indicates whether the conversation ended because it timed out (true) or because a finish method was invoked (false).

Related Topics

Managing Conversation Lifetime