3-8 Managing Server Startup and Shutdown for Oracle WebLogic Server
This value is read from the registry during the startup of the Windows operating system and it affects all services that are installed.
6.
Save your changes to the WebLogic Server master script.
3.1.4.1 Java Class that Shuts Down a Server Instance
The following Java class uses Java Management Extensions JMX to shut down a server instance. Each server uses JMX Managed Beans MBeans to expose its
management attributes and operations. One such MBean, ServerRuntime, exposes a shutdown
method that gracefully shuts down a server. The class in
Example 3–2 uses the Administration MBeanHome interface, which can
retrieve and call ServerRuntime MBean operations for all server instances in a domain.
For more information about JMX programming, refer to Developing Custom Management Utilities With JMX for Oracle WebLogic Server. For more information about
the ServerRuntime MBean, refer to the WebLogic Server Javadoc.
Example 3–2 Java Class that Shuts Down a Server Instance
import java.util.Set; import java.util.Iterator;
import java.rmi.RemoteException; import javax.naming.Context;
import javax.management.ObjectName;
import weblogic.jndi.Environment; import weblogic.management.MBeanHome;
import weblogic.management.WebLogicMBean; import weblogic.management.configuration.ServerMBean;
import weblogic.management.runtime.ServerRuntimeMBean; import weblogic.management.runtime.ServerStates;
import weblogic.management.WebLogicObjectName;
public class ServerStopper { public static void stop throws Exception {
MBeanHome home = null;
url of the Admin server String url = t3:qa113:7001;
String username = system; String password = gumby1234;
ServerRuntimeMBean serverRuntime = null; Set mbeanSet = null;
Iterator mbeanIterator = null;
try { Set ContextClassloader to prevent assertions
URL[] urls = { new File.toURL }; Thread.currentThread.setContextClassLoadernew
URLClassLoaderurls;
Environment env = new Environment; env.setProviderUrlurl;
env.setSecurityPrincipalusername; env.setSecurityCredentialspassword;
Context ctx = env.getInitialContext; home = MBeanHome
ctx.lookupweblogic.management.adminhome;
Setting Up a WebLogic Server Instance as a Windows Service 3-9
mbeanSet = home.getMBeansByTypeServerRuntime; mbeanIterator = mbeanSet.iterator;
whilembeanIterator.hasNext { serverRuntime = ServerRuntimeMBeanmbeanIterator.next;
ifserverRuntime.getState.equalsServerStates.RUNNING{ serverRuntime.shutdown;
} }
} catch Exception e { e.printStackTrace;
} }
}
3.1.5 Redirecting Standard Out and Standard Error to a File