java技术--JDK、JRE、JVM、TOMCAT关系

1.JDK:
(1)是开发人员开发使用
(2)JDK中包含JRE
(3)是java运行和编译的,java没有jdk没办法编译运行,java运行必须依赖jdk的环境
(4)jdk是java语言编写的,用来给java程序调用的
2.JRE:
(1)jre是用来运行java程序,就是java程序的运行环境
3.JVM:
(1)jvm是整个java实现跨平台的最核心的部分,所有的java程序会首先被编译为.class的类文件,这种类文件可以在虚拟机上执行
(2)jvm因为与平台进行交互,是用c/c++和汇编语言编写的
4.TOMCAT:
(1)tomcat是web项目的运行容器
(2)java运行必须依赖jdk的环境,但是不一定需要tomcat,也可以放在weblogic等服务器中

 JDK、JRE、JVM关系:
 1.JDK中包含JRE,在JDK的安装目录下有一个名为jre的目录
 2.jre的目录里面有两个文件夹bin和lib,在这里bin里的就是jvm,lib中则是jvm工作所需要的类库
 3.jvm和 lib和起来就称为jre
 4.JDK(开发工具包),JRE(运行环境,运行时类库),JVM(java虚拟机)

5.什么是JVM
5.1.从操作系统的层面来理解,jvm其实就是操作系统中的一个进程
5.2.JVM(虚拟机),相当于电脑安装系统一样,可以运行应用程序

举例:我们启动运行myeclipse(myeclipse其实就是用java语言编写的一个软件)他的运行必然会启动一个jvm,我们可以把myeclipse理解成我们自己写的一个简单的java版的helloworld程序

5.3.JVM跑着tomcat,而没有JVM tomcat就废物了
6.什么是TOMCAT
6.1.Tomcat 其实是一个用java语言开发的免费开源的web服务器
6.2.Tomcat 是 Java 程序,运行在 JVM 之上
6.3.Tomcat 跑起来,就得有jdk,而jdk自带了JVM,安装完了jdk,把安装jdk的bin目录告诉tomca就可以了(运行java应用需要jvm)

  1.一个tomcat是一个进程,其中有很多线程(与有多少个app无关)
  2.一个tomcat启动一个JVM,其中可以有很多APP /WAR
  3.一个tomcat中部署的多个app,虽然同处一个JVM里,但是由于无法相互调用(因为被类加载器隔离开的),所以也可以认为是分布式的 

扩展:Tomcat和JVM的内存配置/性能优化

  1. JVM内存分配设置的参数有四个:
 (1)-Xmx Java Heap最大值,默认值为物理内存的1/4;
 (2)-Xms Java Heap初始值,Server端JVM最好将-Xms和-Xmx设为相同值,开发测试机JVM可以保留默认值;
 (3)-XX:PermSize:设定内存的永久保存区域;
 (4)-XX:MaxPermSize:设定最大内存的永久保存区域;
    -Xms512M -Xmx1024M -XX:PermSize=512m -XX:MaxPermSize=1024m

扩展:Java 的内存模型(3部分)

 1.Young:年轻代(易被 GC)
    1.1.Young 区被划分为三部分,Eden 区和两个大小严格相同的 Survivor 区
        1.1.1.Survivor 区间:
          (1)某一时刻只有其中一个是被使用的,另外一个留做垃圾收集时复制对象用
          (2)在 Young 区间变满的时候,minor GC 就会将存活的对象移到空闲的Survivor 区间中
          (3)根据 JVM 的策略,在经过几次垃圾收集后,任然存活于 Survivor 的对象将被移动到 Tenured 区间
 2.Tenured,终身代
      2.1.主要保存生命周期长的对象,一般是一些老的对象       
      2.2.当一些对象在 Young 复制转移一定的次数以后,对象就会被转移到 Tenured 区
      2.3.一般如果系统中用了 application 级别的缓存,缓存中的对象往往会被转移到这一区间
 3.Perm,永久代
      3.1.主要保存 class,method,filed 对象,这部门的空间一般不会溢出,除非一次性加载了很多的类
      3.2.在涉及到热部署的应用服务器的时候,有时候会遇到 java.lang.OutOfMemoryError : PermGen space 的错误
      3.3.造成这个错误的很大原因就有可能是每次都重新部署
      3.4.重新部署后,类的 class 没有被卸载掉,这样就造成了大量的 class 对象保存在了 perm 中
      3.5.这种情况下,一般重新启动应用服务器可以解决问题

2.TOMCAT性能优化:主要三方面,为系统优化(略),Tomcat 本身的优化,Java 虚拟机(JVM)调优
Tomcat 6/7/8 的优化参数有点不一样,最好按下面的方式看一下官网这个文档是否还保留着这个参数
启动tomcat,访问该地址,下面要讲解的一些配置信息,在该文档下都有说明的:
文档:http://127.0.0.1:8080/docs/config
Tomcat 6 文档:https://tomcat.apache.org/tomcat-6.0-doc/config
Tomcat 7 文档:https://tomcat.apache.org/tomcat-7.0-doc/config/
Tomcat 8 文档:https://tomcat.apache.org/tomcat-8.0-doc/config
2.1.Tomcat 本身优化

    2.1.1.修改一下 xml 配置文件中的参数,调整最大连接数,超时等(安装 Tomcat 时,优化就已经开始了)
        (1)工作方式选择
         Apache 和 Tomcat 的整合有三种选择(JK、http_proxy 和 ajp_proxy),建议采用 JK 的连接方式
        (2)Connector 连接器的配置(修改server.xml里的Connector节点)
         1.Tomcat 连接器的三种方式: bio、nio 和 apr
         2.apr 的性能最优, bio 的性能最差
         3.Tomcat 7 使用的 Connector  默认就启用的 Apr 协议,但需要系统安装 Apr 库,否则就会使用 bio 方式。
         4.启用 nio:是一个基于缓冲区、并能提供非阻塞I/O操作的Java API,拥有比传统I/O操作(bio)更好的并发运行性能
         修改server.xml里的Connector节点,修改protocol为org.apache.coyote.http11.Http11NioProtocol/Nio2Protocol/
         Tomcat 8 设置 nio2 更好/Tomcat 6、7 设置 nio 更好
       (3)配置文件优化
         1.需要查看 Tomcat 的运行状态可以配置tomcat管理员账户,然后登陆 Tomcat 后台进行查看
          编辑 /opt/tomcat7/bin/conf/tomcat-users.xml 文件,在里面添加下面信息:
          <role rolename="manager"/>
          <role rolename="manager-gui"/>
          <role rolename="admin"/>
          <role rolename="admin-gui"/>
          <user username="tomcat" password="tomcat" roles="admin-gui,admin,manager-gui,manager"/>
          
         2.配置文件优化其实就是对 server.xml 优化,可以提大大提高 Tomcat 的处理请求的能力
         3.默认配置下Tomcat 会为每个连接器创建一个绑定的线程池(最大200),默认创建了固定个数的(5个)空闲线程
         默认值:
               <Executor name="tomcatThreadPool" namePrefix="catalina-exec-" maxThreads="200" minSpareThreads="5"/>
        修改为:
               <Executor  name="tomcatThreadPool"  namePrefix="catalina-exec-" maxThreads="500"      minSpareThreads="100" 
                          prestartminSpareThreads = "true"  maxQueueSize = "100 />
          (1)maxThreads,最大并发数,默认设置 200,一般建议在 500 ~ 800,根据硬件设施和业务来判断
          (2)minSpareThreads,Tomcat 初始化时创建的线程数,默认设置 25
          (3)prestartminSpareThreads,在 Tomcat 初始化的时候就初始化 minSpareThreads 的参数值,
             如果不等于 true,   minSpareThreads 的值就没啥效果了
          (4)maxQueueSize,最大的等待队列数,超过则拒绝请求
          
        4.修改默认的链接参数配置
        默认值:
              <Connector 
               port="8080" 
               protocol="HTTP/1.1" 
               connectionTimeout="20000" 
               redirectPort="8443" />
        修改为:
               <Connector 
                executor="tomcatThreadPool"
                port="8080" 
                protocol="org.apache.coyote.http11.Http11Nio2Protocol" 
                connectionTimeout="20000" 
                maxConnections="10000" 
                redirectPort="8443" 
                enableLookups="false" //禁用DNS查询
                acceptCount="100" 
                maxPostSize="10485760" //以 FORM URL 参数方式的 POST 提交方式,限制提交最大的大小,单位是 字节。10485760 为 10M。如果要禁用限制,则可以设置为 -1
                compression="on" 
                disableUploadTimeout="true" 
                compressionMinSize="2048" 
                acceptorThreadCount="2" 
                compressableMimeType="text/html,text/xml,text/plain,text/css,text/javascript,application/javascript" 
                URIEncoding="utf-8"/>
                
      5.禁用 AJP(如果你服务器没有使用 Apache)
         把下面这一行注释掉,默认 Tomcat 是开启的
         <!-- <Connector port="8009" protocol="AJP/1.3" redirectPort="8443" /> -->  
  以上是一些常用的配置参数属性,当然还有好多其它的参数设置,还可以继续深入的优化

2.2.Java 虚拟机(JVM)调优

        2.2.1.Tomcat 启动命令行中的优化参数,就是 JVM 的优化
        2.2.2.Tomcat 首先跑在 JVM 之上的,因为它的启动其实也只是一个 java 命令行,首先我们需要对这个 JAVA 的启动命令行进行调优
           (1)Linux 修改 /usr/program/tomcat7/bin/catalina.sh 文件,把下面信息添加到文件第一行
           (在 Linux 下,下面的的参数值是被引号包围的,而 Windows 不需要引号包围)
               1.如果服务器只运行一个 Tomcat
                  1.1.机子内存如果是 8G,一般 PermSize 配置是主要保证系统能稳定起来就行:
                  JAVA_OPTS="-Dfile.encoding=UTF-8 -server -Xms6144m -Xmx6144m -XX:NewSize=1024m -
                  XX:MaxNewSize=2048m -XX:PermSize=512m -XX:MaxPermSize=512m -XX:MaxTenuringThreshold=10 -
                  XX:NewRatio=2 -XX:+DisableExplicitGC"
                  1.2.机子内存如果是 16G,一般 PermSize 配置是主要保证系统能稳定起来就行:
                  JAVA_OPTS="-Dfile.encoding=UTF-8 -server -Xms13312m -Xmx13312m -XX:NewSize=3072m -
                  XX:MaxNewSize=4096m -XX:PermSize=512m -XX:MaxPermSize=512m -XX:MaxTenuringThreshold=10 -
                  XX:NewRatio=2 -XX:+DisableExplicitGC"
                  1.3.机子内存如果是 32G,一般 PermSize 配置是主要保证系统能稳定起来就行:
                  JAVA_OPTS="-Dfile.encoding=UTF-8 -server -Xms29696m -Xmx29696m -XX:NewSize=6144m -
                  XX:MaxNewSize=9216m -XX:PermSize=1024m -XX:MaxPermSize=1024m -XX:MaxTenuringThreshold=10 -
                  XX:NewRatio=2 -XX:+DisableExplicitGC"
                  1.4.如果是开发机
                  Xms550m -Xmx1250m -XX:PermSize=550m -XX:MaxPermSize=1250m
           
       2.2.3.Tomcat 的启动参数位于安装目录 ${JAVA_HOME}/bin目录下
       (1)JAVA_OPTS:用于当 Java 运行时选项“start”、“stop”或“run”命令执行。
       (2)CATALINA_OPTS:用于当 Java 运行时选项“start”或“run”命令执行。
       (3)对于 Tomcat 运行过程,可能没什么区别,影响的是结束程序,而不是启动程序。
       (4)如果设置环境变量为只使用 Tomcat,建议使用 CATALINA_OPTS 变量,而如果设置环境变量使用其它的 Java 应用程序,例如 JBoss,应该把设置放在JAVA_OPTS 变量中。
       (5)TOMCAT_HOME\bin\catalina.bat 中添加这样一句话:
       set JAVA_OPTS= -Xmx1024M -Xms512M -XX:MaxPermSize=256m

扩展:直接优化JVM 和 Tomcat JVM优化区别
1.没什么区别:tomcat也是跑在jvm上的
2.建议在Tomcat中优化jvm(原因如下)
(1)tomcat启动会调用jvm,jvm中有默认参数
(2)如果只优化jvm参数启动tomcat后参数会覆盖jvm参数
(3)因此tomcat jvm优化往往是更加贴切的.更加使用的.更加有意义的

  • 3
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
================================================================================ Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. ================================================================================ Apache Tomcat Version 7.0.57 Release Notes ========= CONTENTS: ========= * Dependency Changes * API Stability * JNI Based Applications * Bundled APIs * Web application reloading and static fields in shared libraries * Tomcat on Linux * Enabling SSI and CGI Support * Security manager URLs * Symlinking static resources * Viewing the Tomcat Change Log * Cryptographic software notice * When all else fails =================== Dependency Changes: =================== Tomcat 7.0 is designed to run on Java SE 6 and later. In addition, Tomcat 7.0 uses the Eclipse JDT Java compiler for compiling JSP pages. This means you no longer need to have the complete Java Development Kit (JDK) to run Tomcat, but a Java Runtime Environment (JRE) is sufficient. The Eclipse JDT Java compiler is bundled with the binary Tomcat distributions. Tomcat can also be configured to use the compiler from the JDK to compile JSPs, or any other Java compiler supported by Apache Ant. ============== API Stability: ============== The public interfaces for the following classes are fixed and will not be changed at all during the remaining lifetime of the 7.x series: - javax/**/* The public interfaces for the following classes may be added to in order to resolve bugs and/or add new features. No existing interface will be removed or changed although it may be deprecated. - org/apache/catalina/* - org/apache/catalina/comet/* Note: As Tomcat 7 matures, the above list will be added to. The list is not considered complete at this time. The remaining classes are considered part of the Tomcat internals and may change without notice between point releases. ======================= JNI Based Applications: ======================= Applications that require native libraries must ensure that the libraries have been loaded prior to use. Typically, this is done with a call like: static { System.loadLibrary("path-to-library-file"); } in some class. However, the application must also ensure that the library is not loaded more than once. If the above code were placed in a class inside the web application (i.e. under /WEB-INF/classes or /WEB-INF/lib), and the application were reloaded, the loadLibrary() call would be attempted a second time. To avoid this problem, place classes that load native libraries outside of the web application, and ensure that the loadLibrary() call is executed only once during the lifetime of a particular JVM. ============= Bundled APIs: ============= A standard installation of Tomcat 7.0 makes all of the following APIs available for use by web applications (by placing them in "lib"): * annotations-api.jar (Annotations package) * catalina.jar (Tomcat Catalina implementation) * catalina-ant.jar (Tomcat Catalina Ant tasks) * catalina-ha.jar (High availability package) * catalina-tribes.jar (Group communication) * ecj-4.4.jar (Eclipse JDT Java compiler) * el-api.jar (EL 2.2 API) * jasper.jar (Jasper 2 Compiler and Runtime) * jasper-el.jar (Jasper 2 EL implementation) * jsp-api.jar (JSP 2.2 API) * servlet-api.jar (Servlet 3.0 API) * tomcat7-websocket.jar (WebSocket 1.1 implementation) * tomcat-api.jar (Interfaces shared by Catalina and Jasper) * tomcat-coyote.jar (Tomcat connectors and utility classes) * tomcat-dbcp.jar (package renamed database connection pool based on Commons DBCP) * tomcat-jdbc.jar (Tomcat's database connection pooling solution) * tomcat-util.jar (Various utilities) * websocket-api.jar (WebSocket 1.1 API) You can make additional APIs available to all of your web applications by putting unpacked classes into a "classes" directory (not created by default), or by placing them in JAR files in the "lib" directory. To override the XML parser implementation or interfaces, use the endorsed mechanism of the JVM. The default configuration defines JARs located in "endorsed" as endorsed. ================================================================ Web application reloading and static fields in shared libraries: ================================================================ Some shared libraries (many are part of the JDK) keep references to objects instantiated by the web application. To avoid class loading related problems (ClassCastExceptions, messages indicating that the classloader is stopped, etc.), the shared libraries state should be reinitialized. Something which might help is to avoid putting classes which would be referenced by a shared static field in the web application classloader, and putting them in the shared classloader instead (JARs should be put in the "lib" folder, and classes should be put in the "classes" folder). ================ Tomcat on Linux: ================ GLIBC 2.2 / Linux 2.4 users should define an environment variable: export LD_ASSUME_KERNEL=2.2.5 Redhat Linux 9.0 users should use the following setting to avoid stability problems: export LD_ASSUME_KERNEL=2.4.1 There are some Linux bugs reported against the NIO sendfile behavior, make sure you have a JDK that is up to date, or disable sendfile behavior in the Connector.<br/> 6427312: (fc) FileChannel.transferTo() throws IOException "system call interrupted"<br/> 5103988: (fc) FileChannel.transferTo should return -1 for EAGAIN instead throws IOException<br/> 6253145: (fc) FileChannel.transferTo on Linux fails when going beyond 2GB boundary<br/> 6470086: (fc) FileChannel.transferTo(2147483647, 1, channel) cause "Value too large" exception<br/> ============================= Enabling SSI and CGI Support: ============================= Because of the security risks associated with CGI and SSI available to web applications, these features are disabled by default. To enable and configure CGI support, please see the cgi-howto.html page. To enable and configue SSI support, please see the ssi-howto.html page. ====================== Security manager URLs: ====================== In order to grant security permissions to JARs located inside the web application repository, use URLs of of the following format in your policy file: file:${catalina.base}/webapps/examples/WEB-INF/lib/driver.jar ============================ Symlinking static resources: ============================ By default, Unix symlinks will not work when used in a web application to link resources located outside the web application root directory. This behavior is optional, and the "allowLinking" flag may be used to disable the check. ============================== Viewing the Tomcat Change Log: ============================== See changelog.html in this directory. ============================= Cryptographic software notice ============================= This distribution includes cryptographic software. The country in which you currently reside may have restrictions on the import, possession, use, and/or re-export to another country, of encryption software. BEFORE using any encryption software, please check your country's laws, regulations and policies concerning the import, possession, or use, and re-export of encryption software, to see if this is permitted. See <http://www.wassenaar.org/> for more information. The U.S. Government Department of Commerce, Bureau of Industry and Security (BIS), has classified this software as Export Commodity Control Number (ECCN) 5D002.C.1, which includes information security software using or performing cryptographic functions with asymmetric algorithms. The form and manner of this Apache Software Foundation distribution makes it eligible for export under the License Exception ENC Technology Software Unrestricted (TSU) exception (see the BIS Export Administration Regulations, Section 740.13) for both object code and source code. The following provides more details on the included cryptographic software: - Tomcat includes code designed to work with JSSE - Tomcat includes code designed to work with OpenSSL ==================== When all else fails: ==================== See the FAQ http://tomcat.apache.org/faq/

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值