The setScriptTimeout method of the Server class establishes the amount of time that can pass before scripts will become invalid.
public void setScriptTimeout(int timeout);