windows服务启动tomcat内存溢出问题解决方案

利用程序修改注册表,代码如下

 void UpdateMemmory() 
        {
            try
            {
                RegistryKey root = Registry.LocalMachine;
                RegistryKey software = root.OpenSubKey("SOFTWARE", true);
                RegistryKey asf = software.OpenSubKey("Apache Software Foundation", true);
                RegistryKey pru = asf.OpenSubKey("Procrun 2.0", true);
                //RegistryKey tl = pru.OpenSubKey("tomcatloan", true);
                RegistryKey tl = pru.OpenSubKey(CommonMethod.GetTomcatName(), true);
                RegistryKey Parameters = tl.OpenSubKey("Parameters", true);
                RegistryKey java = Parameters.OpenSubKey("Java", true);
                string[] strarray = java.GetValue("Options") as string[];
                if (strarray != null)
                {
                    bool flag = true;
                    ArrayList al = new ArrayList();
                    for (int i = 0; i < strarray.Length; i++)
                    {
                        //if (strarray[i] == "-Xrs –Xms512m –Xmx1024m")
                        if(strarray[i].StartsWith("-Xrs –Xms512m –Xmx1024m"))
                        {
                            flag = false;
                        }
                        al.Add(strarray[i]);
                    }
                    if (flag)
                    {
                        al.Add("-Xrs –Xms512m –Xmx1024m");
                        al.Add("-XX:PermSize=256M");
                        al.Add("-XX:MaxPermSize=256M");
                        java.SetValue("Options", (string[])al.ToArray(typeof(string)), RegistryValueKind.MultiString);
                    }
                }
            }
            catch 
            {
                
            }
        }

  al.Add("-XX:PermSize=256M");
   al.Add("-XX:MaxPermSize=256M");

上边这两句很重要,是设置tomcat的非堆内存大小,什么事非堆内存,自己可以百度。同时写进注册表的参数一定是分行的,写成一行不行。

注册表截图如下:windows服务启动tomcat内存溢出问题解决方案_第1张图片

转载于:https://www.cnblogs.com/zjBoy/archive/2013/01/04/2844091.html

你可能感兴趣的:(windows服务启动tomcat内存溢出问题解决方案)