Beispiel #1
0
 /// <summary>
 /// 根据路径获取单个JAVA详细信息
 /// </summary>
 /// <param name="javaPath"></param>
 /// <returns></returns>
 public static Java GetJavaInfo(string javaPath)
 {
     try
     {
         if (!string.IsNullOrWhiteSpace(javaPath) && File.Exists(javaPath))
         {
             Process p = new Process();
             p.StartInfo.FileName              = javaPath;
             p.StartInfo.Arguments             = "-version";
             p.StartInfo.RedirectStandardError = true;
             p.StartInfo.UseShellExecute       = false;
             p.StartInfo.CreateNoWindow        = true;
             p.Start();
             string result  = p.StandardError.ReadToEnd();
             string version = result.Replace("java version \"", "");
             version = version.Remove(version.IndexOf("\""));
             bool is64 = result.Contains("64-Bit");
             Java info;
             if (is64)
             {
                 info = new Java(javaPath, version, ArchEnum.x64);
             }
             else
             {
                 info = new Java(javaPath, version, ArchEnum.x32);
             }
             p.Dispose();
             return(info);
         }
         else
         {
             return(null);
         }
     }
     catch (Exception)
     {
         return(null);
     }
 }
Beispiel #2
0
        /// <summary>
        /// 获取匹配JAVA位数的最佳内存
        /// </summary>
        /// <param name="arch">JAVA位数</param>
        /// <returns>最佳内存大小</returns>
        public static int GetBestMemory(Java java)
        {
            if (java != null)
            {
                int rm = Convert.ToInt32(Math.Floor(GetRunmemory() * 0.6));
                switch (java.Arch)
                {
                case ArchEnum.x32:
                    if (rm > 1024)
                    {
                        return(1024);
                    }
                    else
                    {
                        return(rm);
                    }

                case ArchEnum.x64:
                    if (rm > 4096)
                    {
                        return(4096);
                    }
                    else
                    {
                        return(rm);
                    }

                default:
                    return(rm);
                }
            }
            else
            {
                return(1024);
            }
        }