diff --git a/.idea/artifacts/jvm_war_exploded.xml b/.idea/artifacts/jvm_war_exploded.xml new file mode 100644 index 0000000..d328531 --- /dev/null +++ b/.idea/artifacts/jvm_war_exploded.xml @@ -0,0 +1,13 @@ + + + $PROJECT_DIR$/out/artifacts/jvm_war_exploded + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Maven__commons_codec_commons_codec_1_13.xml b/.idea/libraries/Maven__commons_codec_commons_codec_1_13.xml new file mode 100644 index 0000000..f8b0a28 --- /dev/null +++ b/.idea/libraries/Maven__commons_codec_commons_codec_1_13.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Maven__org_apache_httpcomponents_httpclient_4_5_10.xml b/.idea/libraries/Maven__org_apache_httpcomponents_httpclient_4_5_10.xml new file mode 100644 index 0000000..f91763b --- /dev/null +++ b/.idea/libraries/Maven__org_apache_httpcomponents_httpclient_4_5_10.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Maven__org_apache_httpcomponents_httpcore_4_4_12.xml b/.idea/libraries/Maven__org_apache_httpcomponents_httpcore_4_4_12.xml new file mode 100644 index 0000000..64343e8 --- /dev/null +++ b/.idea/libraries/Maven__org_apache_httpcomponents_httpcore_4_4_12.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Maven__org_hamcrest_hamcrest_core_2_1.xml b/.idea/libraries/Maven__org_hamcrest_hamcrest_core_2_1.xml new file mode 100644 index 0000000..d51962f --- /dev/null +++ b/.idea/libraries/Maven__org_hamcrest_hamcrest_core_2_1.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/uiDesigner.xml b/.idea/uiDesigner.xml new file mode 100644 index 0000000..e96534f --- /dev/null +++ b/.idea/uiDesigner.xml @@ -0,0 +1,124 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/basic/mvnw b/basic/mvnw deleted file mode 100644 index 8b9da3b..0000000 --- a/basic/mvnw +++ /dev/null @@ -1,286 +0,0 @@ -#!/bin/sh -# ---------------------------------------------------------------------------- -# 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 -# -# https://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. -# ---------------------------------------------------------------------------- - -# ---------------------------------------------------------------------------- -# Maven2 Start Up Batch script -# -# Required ENV vars: -# ------------------ -# JAVA_HOME - location of a JDK home dir -# -# Optional ENV vars -# ----------------- -# M2_HOME - location of maven2's installed home dir -# MAVEN_OPTS - parameters passed to the Java VM when running Maven -# e.g. to debug Maven itself, use -# set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 -# MAVEN_SKIP_RC - flag to disable loading of mavenrc files -# ---------------------------------------------------------------------------- - -if [ -z "$MAVEN_SKIP_RC" ] ; then - - if [ -f /etc/mavenrc ] ; then - . /etc/mavenrc - fi - - if [ -f "$HOME/.mavenrc" ] ; then - . "$HOME/.mavenrc" - fi - -fi - -# OS specific support. $var _must_ be set to either true or false. -cygwin=false; -darwin=false; -mingw=false -case "`uname`" in - CYGWIN*) cygwin=true ;; - MINGW*) mingw=true;; - Darwin*) darwin=true - # Use /usr/libexec/java_home if available, otherwise fall back to /Library/Java/Home - # See https://developer.apple.com/library/mac/qa/qa1170/_index.html - if [ -z "$JAVA_HOME" ]; then - if [ -x "/usr/libexec/java_home" ]; then - export JAVA_HOME="`/usr/libexec/java_home`" - else - export JAVA_HOME="/Library/Java/Home" - fi - fi - ;; -esac - -if [ -z "$JAVA_HOME" ] ; then - if [ -r /etc/gentoo-release ] ; then - JAVA_HOME=`java-config --jre-home` - fi -fi - -if [ -z "$M2_HOME" ] ; then - ## resolve links - $0 may be a link to maven's home - PRG="$0" - - # need this for relative symlinks - while [ -h "$PRG" ] ; do - ls=`ls -ld "$PRG"` - link=`expr "$ls" : '.*-> \(.*\)$'` - if expr "$link" : '/.*' > /dev/null; then - PRG="$link" - else - PRG="`dirname "$PRG"`/$link" - fi - done - - saveddir=`pwd` - - M2_HOME=`dirname "$PRG"`/.. - - # make it fully qualified - M2_HOME=`cd "$M2_HOME" && pwd` - - cd "$saveddir" - # echo Using m2 at $M2_HOME -fi - -# For Cygwin, ensure paths are in UNIX format before anything is touched -if $cygwin ; then - [ -n "$M2_HOME" ] && - M2_HOME=`cygpath --unix "$M2_HOME"` - [ -n "$JAVA_HOME" ] && - JAVA_HOME=`cygpath --unix "$JAVA_HOME"` - [ -n "$CLASSPATH" ] && - CLASSPATH=`cygpath --path --unix "$CLASSPATH"` -fi - -# For Mingw, ensure paths are in UNIX format before anything is touched -if $mingw ; then - [ -n "$M2_HOME" ] && - M2_HOME="`(cd "$M2_HOME"; pwd)`" - [ -n "$JAVA_HOME" ] && - JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`" - # TODO classpath? -fi - -if [ -z "$JAVA_HOME" ]; then - javaExecutable="`which javac`" - if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then - # readlink(1) is not available as standard on Solaris 10. - readLink=`which readlink` - if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then - if $darwin ; then - javaHome="`dirname \"$javaExecutable\"`" - javaExecutable="`cd \"$javaHome\" && pwd -P`/javac" - else - javaExecutable="`readlink -f \"$javaExecutable\"`" - fi - javaHome="`dirname \"$javaExecutable\"`" - javaHome=`expr "$javaHome" : '\(.*\)/bin'` - JAVA_HOME="$javaHome" - export JAVA_HOME - fi - fi -fi - -if [ -z "$JAVACMD" ] ; then - if [ -n "$JAVA_HOME" ] ; then - if [ -x "$JAVA_HOME/jre/sh/java" ] ; then - # IBM's JDK on AIX uses strange locations for the executables - JAVACMD="$JAVA_HOME/jre/sh/java" - else - JAVACMD="$JAVA_HOME/bin/java" - fi - else - JAVACMD="`which java`" - fi -fi - -if [ ! -x "$JAVACMD" ] ; then - echo "Error: JAVA_HOME is not defined correctly." >&2 - echo " We cannot execute $JAVACMD" >&2 - exit 1 -fi - -if [ -z "$JAVA_HOME" ] ; then - echo "Warning: JAVA_HOME environment variable is not set." -fi - -CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher - -# traverses directory structure from process work directory to filesystem root -# first directory with .mvn subdirectory is considered project base directory -find_maven_basedir() { - - if [ -z "$1" ] - then - echo "Path not specified to find_maven_basedir" - return 1 - fi - - basedir="$1" - wdir="$1" - while [ "$wdir" != '/' ] ; do - if [ -d "$wdir"/.mvn ] ; then - basedir=$wdir - break - fi - # workaround for JBEAP-8937 (on Solaris 10/Sparc) - if [ -d "${wdir}" ]; then - wdir=`cd "$wdir/.."; pwd` - fi - # end of workaround - done - echo "${basedir}" -} - -# concatenates all lines of a file -concat_lines() { - if [ -f "$1" ]; then - echo "$(tr -s '\n' ' ' < "$1")" - fi -} - -BASE_DIR=`find_maven_basedir "$(pwd)"` -if [ -z "$BASE_DIR" ]; then - exit 1; -fi - -########################################################################################## -# Extension to allow automatically downloading the maven-wrapper.jar from Maven-central -# This allows using the maven wrapper in projects that prohibit checking in binary data. -########################################################################################## -if [ -r "$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" ]; then - if [ "$MVNW_VERBOSE" = true ]; then - echo "Found .mvn/wrapper/maven-wrapper.jar" - fi -else - if [ "$MVNW_VERBOSE" = true ]; then - echo "Couldn't find .mvn/wrapper/maven-wrapper.jar, downloading it ..." - fi - jarUrl="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.4.2/maven-wrapper-0.4.2.jar" - while IFS="=" read key value; do - case "$key" in (wrapperUrl) jarUrl="$value"; break ;; - esac - done < "$BASE_DIR/.mvn/wrapper/maven-wrapper.properties" - if [ "$MVNW_VERBOSE" = true ]; then - echo "Downloading from: $jarUrl" - fi - wrapperJarPath="$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" - - if command -v wget > /dev/null; then - if [ "$MVNW_VERBOSE" = true ]; then - echo "Found wget ... using wget" - fi - wget "$jarUrl" -O "$wrapperJarPath" - elif command -v curl > /dev/null; then - if [ "$MVNW_VERBOSE" = true ]; then - echo "Found curl ... using curl" - fi - curl -o "$wrapperJarPath" "$jarUrl" - else - if [ "$MVNW_VERBOSE" = true ]; then - echo "Falling back to using Java to download" - fi - javaClass="$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.java" - if [ -e "$javaClass" ]; then - if [ ! -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then - if [ "$MVNW_VERBOSE" = true ]; then - echo " - Compiling MavenWrapperDownloader.java ..." - fi - # Compiling the Java class - ("$JAVA_HOME/bin/javac" "$javaClass") - fi - if [ -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then - # Running the downloader - if [ "$MVNW_VERBOSE" = true ]; then - echo " - Running MavenWrapperDownloader.java ..." - fi - ("$JAVA_HOME/bin/java" -cp .mvn/wrapper MavenWrapperDownloader "$MAVEN_PROJECTBASEDIR") - fi - fi - fi -fi -########################################################################################## -# End of extension -########################################################################################## - -export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"} -if [ "$MVNW_VERBOSE" = true ]; then - echo $MAVEN_PROJECTBASEDIR -fi -MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS" - -# For Cygwin, switch paths to Windows format before running java -if $cygwin; then - [ -n "$M2_HOME" ] && - M2_HOME=`cygpath --path --windows "$M2_HOME"` - [ -n "$JAVA_HOME" ] && - JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"` - [ -n "$CLASSPATH" ] && - CLASSPATH=`cygpath --path --windows "$CLASSPATH"` - [ -n "$MAVEN_PROJECTBASEDIR" ] && - MAVEN_PROJECTBASEDIR=`cygpath --path --windows "$MAVEN_PROJECTBASEDIR"` -fi - -WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain - -exec "$JAVACMD" \ - $MAVEN_OPTS \ - -classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \ - "-Dmaven.home=${M2_HOME}" "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \ - ${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@" diff --git a/basic/mvnw.cmd b/basic/mvnw.cmd deleted file mode 100644 index fef5a8f..0000000 --- a/basic/mvnw.cmd +++ /dev/null @@ -1,161 +0,0 @@ -@REM ---------------------------------------------------------------------------- -@REM Licensed to the Apache Software Foundation (ASF) under one -@REM or more contributor license agreements. See the NOTICE file -@REM distributed with this work for additional information -@REM regarding copyright ownership. The ASF licenses this file -@REM to you under the Apache License, Version 2.0 (the -@REM "License"); you may not use this file except in compliance -@REM with the License. You may obtain a copy of the License at -@REM -@REM https://www.apache.org/licenses/LICENSE-2.0 -@REM -@REM Unless required by applicable law or agreed to in writing, -@REM software distributed under the License is distributed on an -@REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -@REM KIND, either express or implied. See the License for the -@REM specific language governing permissions and limitations -@REM under the License. -@REM ---------------------------------------------------------------------------- - -@REM ---------------------------------------------------------------------------- -@REM Maven2 Start Up Batch script -@REM -@REM Required ENV vars: -@REM JAVA_HOME - location of a JDK home dir -@REM -@REM Optional ENV vars -@REM M2_HOME - location of maven2's installed home dir -@REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands -@REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a key stroke before ending -@REM MAVEN_OPTS - parameters passed to the Java VM when running Maven -@REM e.g. to debug Maven itself, use -@REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 -@REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files -@REM ---------------------------------------------------------------------------- - -@REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on' -@echo off -@REM set title of command window -title %0 -@REM enable echoing my setting MAVEN_BATCH_ECHO to 'on' -@if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO% - -@REM set %HOME% to equivalent of $HOME -if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%") - -@REM Execute a user defined script before this one -if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre -@REM check for pre script, once with legacy .bat ending and once with .cmd ending -if exist "%HOME%\mavenrc_pre.bat" call "%HOME%\mavenrc_pre.bat" -if exist "%HOME%\mavenrc_pre.cmd" call "%HOME%\mavenrc_pre.cmd" -:skipRcPre - -@setlocal - -set ERROR_CODE=0 - -@REM To isolate internal variables from possible post scripts, we use another setlocal -@setlocal - -@REM ==== START VALIDATION ==== -if not "%JAVA_HOME%" == "" goto OkJHome - -echo. -echo Error: JAVA_HOME not found in your environment. >&2 -echo Please set the JAVA_HOME variable in your environment to match the >&2 -echo location of your Java installation. >&2 -echo. -goto error - -:OkJHome -if exist "%JAVA_HOME%\bin\java.exe" goto init - -echo. -echo Error: JAVA_HOME is set to an invalid directory. >&2 -echo JAVA_HOME = "%JAVA_HOME%" >&2 -echo Please set the JAVA_HOME variable in your environment to match the >&2 -echo location of your Java installation. >&2 -echo. -goto error - -@REM ==== END VALIDATION ==== - -:init - -@REM Find the project base dir, i.e. the directory that contains the folder ".mvn". -@REM Fallback to current working directory if not found. - -set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR% -IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir - -set EXEC_DIR=%CD% -set WDIR=%EXEC_DIR% -:findBaseDir -IF EXIST "%WDIR%"\.mvn goto baseDirFound -cd .. -IF "%WDIR%"=="%CD%" goto baseDirNotFound -set WDIR=%CD% -goto findBaseDir - -:baseDirFound -set MAVEN_PROJECTBASEDIR=%WDIR% -cd "%EXEC_DIR%" -goto endDetectBaseDir - -:baseDirNotFound -set MAVEN_PROJECTBASEDIR=%EXEC_DIR% -cd "%EXEC_DIR%" - -:endDetectBaseDir - -IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig - -@setlocal EnableExtensions EnableDelayedExpansion -for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a -@endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS% - -:endReadAdditionalConfig - -SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe" -set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar" -set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain - -set DOWNLOAD_URL="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.4.2/maven-wrapper-0.4.2.jar" -FOR /F "tokens=1,2 delims==" %%A IN (%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties) DO ( - IF "%%A"=="wrapperUrl" SET DOWNLOAD_URL=%%B -) - -@REM Extension to allow automatically downloading the maven-wrapper.jar from Maven-central -@REM This allows using the maven wrapper in projects that prohibit checking in binary data. -if exist %WRAPPER_JAR% ( - echo Found %WRAPPER_JAR% -) else ( - echo Couldn't find %WRAPPER_JAR%, downloading it ... - echo Downloading from: %DOWNLOAD_URL% - powershell -Command "(New-Object Net.WebClient).DownloadFile('%DOWNLOAD_URL%', '%WRAPPER_JAR%')" - echo Finished downloading %WRAPPER_JAR% -) -@REM End of extension - -%MAVEN_JAVA_EXE% %JVM_CONFIG_MAVEN_PROPS% %MAVEN_OPTS% %MAVEN_DEBUG_OPTS% -classpath %WRAPPER_JAR% "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %* -if ERRORLEVEL 1 goto error -goto end - -:error -set ERROR_CODE=1 - -:end -@endlocal & set ERROR_CODE=%ERROR_CODE% - -if not "%MAVEN_SKIP_RC%" == "" goto skipRcPost -@REM check for post script, once with legacy .bat ending and once with .cmd ending -if exist "%HOME%\mavenrc_post.bat" call "%HOME%\mavenrc_post.bat" -if exist "%HOME%\mavenrc_post.cmd" call "%HOME%\mavenrc_post.cmd" -:skipRcPost - -@REM pause the script if MAVEN_BATCH_PAUSE is set to 'on' -if "%MAVEN_BATCH_PAUSE%" == "on" pause - -if "%MAVEN_TERMINATE_CMD%" == "on" exit %ERROR_CODE% - -exit /B %ERROR_CODE% diff --git a/basic/pom.xml b/basic/pom.xml index caf0c79..16c59a0 100644 --- a/basic/pom.xml +++ b/basic/pom.xml @@ -24,6 +24,12 @@ spring-boot-starter-web + + org.apache.httpcomponents + httpclient + 4.5.10 + + org.springframework.boot spring-boot-starter-test @@ -36,6 +42,12 @@ + + junit + junit + 4.12 + test + org.projectlombok @@ -52,6 +64,7 @@ + basic org.springframework.boot diff --git a/basic/src/main/java/com/tison/basic/BasicApplication.java b/basic/src/main/java/com/tison/basic/BasicApplication.java index c270d8d..9e71b83 100644 --- a/basic/src/main/java/com/tison/basic/BasicApplication.java +++ b/basic/src/main/java/com/tison/basic/BasicApplication.java @@ -2,7 +2,9 @@ import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.scheduling.annotation.EnableScheduling; +@EnableScheduling @SpringBootApplication public class BasicApplication { diff --git a/basic/src/main/java/com/tison/basic/config/excutor/ExcutorConfiguration.java b/basic/src/main/java/com/tison/basic/config/excutor/ExcutorConfiguration.java deleted file mode 100644 index f4e3095..0000000 --- a/basic/src/main/java/com/tison/basic/config/excutor/ExcutorConfiguration.java +++ /dev/null @@ -1,19 +0,0 @@ -package com.tison.basic.config.excutor; - -import org.springframework.boot.context.properties.EnableConfigurationProperties; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; - -/** - * @author tison - * @date 2019/10/22 - * @description 配置类注入容器 - */ -@Configuration -public class ExcutorConfiguration { - - @Bean - public ExcutorProperties excutorProperties() { - return new ExcutorProperties(); - } -} diff --git a/basic/src/main/java/com/tison/basic/config/excutor/ExcutorProperties.java b/basic/src/main/java/com/tison/basic/config/excutor/ExcutorProperties.java index c4f03a9..b4bf03a 100644 --- a/basic/src/main/java/com/tison/basic/config/excutor/ExcutorProperties.java +++ b/basic/src/main/java/com/tison/basic/config/excutor/ExcutorProperties.java @@ -10,6 +10,7 @@ * @description 线程池配置实体 */ @Data +@Component @ConfigurationProperties(prefix="excutor") public class ExcutorProperties { diff --git a/basic/src/main/java/com/tison/basic/task/SchedulerService.java b/basic/src/main/java/com/tison/basic/task/SchedulerService.java new file mode 100644 index 0000000..3c2f656 --- /dev/null +++ b/basic/src/main/java/com/tison/basic/task/SchedulerService.java @@ -0,0 +1,26 @@ +package com.tison.basic.task; + +import com.tison.basic.config.excutor.ExcutorProperties; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.scheduling.annotation.Scheduled; +import org.springframework.stereotype.Component; + +/** + * @author tison + * @date 2019/11/6 + * @description + */ +@Slf4j +@Component +public class SchedulerService { + + @Autowired + private ExcutorProperties excutorProperties; + + @Scheduled(cron = "0/5 * * * * *") + public void scheduled(){ + log.info("corePoolSize={}", excutorProperties.getCorePoolSize()); + } + +} diff --git a/basic/src/main/java/com/tison/basic/web/OOMTestController.java b/basic/src/main/java/com/tison/basic/web/OOMTestController.java new file mode 100644 index 0000000..4359db2 --- /dev/null +++ b/basic/src/main/java/com/tison/basic/web/OOMTestController.java @@ -0,0 +1,57 @@ +package com.tison.basic.web; + +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import javax.servlet.http.HttpServletRequest; +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.LinkedBlockingQueue; +import java.util.concurrent.ThreadPoolExecutor; +import java.util.concurrent.TimeUnit; + +/** + * @author tison + * @date 2020/03/25 + * @description OOM触发类 + */ +@RestController +@RequestMapping("/oom") +public class OOMTestController { + + /** + * 创建线程池,通过线程池,保证创建的线程存活 + */ + final static ThreadPoolExecutor poolExecutor = new ThreadPoolExecutor( + 100, 100, 1, TimeUnit.MINUTES, + new LinkedBlockingQueue<>()); + + /** + * 声明本地变量,循环请求引发OOM + */ + final static ThreadLocal localVariable = new ThreadLocal(); + + @GetMapping(value = "/test0") + public String test0() { + poolExecutor.execute(()->{ + Byte[] c = new Byte[4096*1024]; + localVariable.set(c);// 为线程添加变量 + }); + return "success"; + } + + /** + * 循环请求引发FullGC + * @param request + * @return + */ + @GetMapping(value = "/test1") + public String test1(HttpServletRequest request) { + List temp1 = new ArrayList(); + Byte[] b = new Byte[1024*20]; + //添加局部变量 + temp1.add(b); + return "success"; + } +} diff --git a/basic/src/main/resources/application-stg.yaml b/basic/src/main/resources/application-stg.yaml new file mode 100644 index 0000000..452c6b6 --- /dev/null +++ b/basic/src/main/resources/application-stg.yaml @@ -0,0 +1,2 @@ +excutor: + core-pool-size: 20 diff --git a/basic/src/test/java/com/tison/basic/MockOOMTestController.java b/basic/src/test/java/com/tison/basic/MockOOMTestController.java new file mode 100644 index 0000000..44d7fc7 --- /dev/null +++ b/basic/src/test/java/com/tison/basic/MockOOMTestController.java @@ -0,0 +1,56 @@ +package com.tison.basic; + +import org.apache.http.HttpEntity; +import org.apache.http.client.config.RequestConfig; +import org.apache.http.client.methods.CloseableHttpResponse; +import org.apache.http.client.methods.HttpGet; +import org.apache.http.impl.client.CloseableHttpClient; +import org.apache.http.impl.client.HttpClients; +import org.apache.http.util.EntityUtils; +import org.junit.Test; + +public class MockOOMTestController { + + @Test + public void test(){ + + for(int i = 0 ; i<10000; i++){ + System.out.println("send the get count=" + i); + sendGet("http://localhost:8080/oom/test0"); + } + } + + /** + * 模拟请求 + * @param url + * @return + */ + public static String sendGet(String url) { + String result = ""; + try( + CloseableHttpClient httpClient=HttpClients.createDefault(); + ) { + // 通过址默认配置创建一个httpClient实例 + // 创建httpGet远程连接实例 + // 设置配置请求参数 + RequestConfig requestConfig = RequestConfig.custom().setConnectTimeout(35000)// 连接主机服务超时时间 + .setConnectionRequestTimeout(35000)// 请求超时时间 + .setSocketTimeout(60000)// 数据读取超时时间 + .build(); + // 为httpGet实例设置配置 + HttpGet httpGet = new HttpGet(url); + + httpGet.setConfig(requestConfig); + // 执行get请求得到返回对象 + CloseableHttpResponse response=httpClient.execute(httpGet); + // 通过返回对象获取返回数据 + HttpEntity entity = response.getEntity(); + // 通过EntityUtils中的toString方法将结果转换为字符串 + result = EntityUtils.toString(entity); + }catch (Exception e){ + e.printStackTrace(); + } + return result; + } + +} diff --git a/heapTest.log b/heapTest.log new file mode 100644 index 0000000..81bc9f9 --- /dev/null +++ b/heapTest.log @@ -0,0 +1,95 @@ +Java HotSpot(TM) 64-Bit Server VM (25.202-b08) for windows-amd64 JRE (1.8.0_202-b08), built on Dec 15 2018 19:54:30 by "java_re" with MS VC++ 10.0 (VS2010) +Memory: 4k page, physical 8230644k(2562660k free), swap 14397192k(2125236k free) +CommandLine flags: -XX:-BytecodeVerificationLocal -XX:-BytecodeVerificationRemote -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=d:/dump/ -XX:InitialHeapSize=1073741824 -XX:+ManagementServer -XX:MaxHeapSize=1073741824 -XX:+PrintGC -XX:+PrintGCDetails -XX:+PrintGCTimeStamps -XX:TieredStopAtLevel=1 -XX:+UseCompressedClassPointers -XX:+UseCompressedOops -XX:-UseLargePagesIndividualAllocation -XX:+UseParallelGC +3.018: [GC (Metadata GC Threshold) [PSYoungGen: 157346K->14275K(305664K)] 157346K->14291K(1005056K), 0.0225683 secs] [Times: user=0.09 sys=0.00, real=0.02 secs] +3.041: [Full GC (Metadata GC Threshold) [PSYoungGen: 14275K->0K(305664K)] [ParOldGen: 16K->13635K(699392K)] 14291K->13635K(1005056K), [Metaspace: 20598K->20597K(1067008K)], 0.0456608 secs] [Times: user=0.13 sys=0.00, real=0.05 secs] +26.360: [GC (Allocation Failure) [PSYoungGen: 262144K->16127K(305664K)] 275779K->29779K(1005056K), 0.0482744 secs] [Times: user=0.06 sys=0.05, real=0.05 secs] +38.240: [GC (Allocation Failure) [PSYoungGen: 278271K->6404K(305664K)] 291923K->20063K(1005056K), 0.0195139 secs] [Times: user=0.13 sys=0.00, real=0.02 secs] +48.306: [GC (Allocation Failure) [PSYoungGen: 268548K->6308K(305664K)] 282207K->19975K(1005056K), 0.0081196 secs] [Times: user=0.09 sys=0.00, real=0.01 secs] +59.982: [GC (Allocation Failure) [PSYoungGen: 268452K->6340K(305664K)] 282119K->20007K(1005056K), 0.0089518 secs] [Times: user=0.00 sys=0.00, real=0.01 secs] +80.841: [GC (Allocation Failure) [PSYoungGen: 254239K->6416K(330752K)] 267906K->167548K(1030144K), 0.0837031 secs] [Times: user=0.38 sys=0.08, real=0.08 secs] +81.055: [GC (Allocation Failure) [PSYoungGen: 312972K->6436K(330240K)] 474104K->462488K(1029632K), 0.1509864 secs] [Times: user=0.69 sys=0.22, real=0.15 secs] +81.334: [GC (Allocation Failure) --[PSYoungGen: 309967K->309967K(330240K)] 766019K->995396K(1029632K), 0.2426983 secs] [Times: user=0.53 sys=0.31, real=0.24 secs] +81.577: [Full GC (Ergonomics) [PSYoungGen: 309967K->55037K(330240K)] [ParOldGen: 685428K->692948K(699392K)] 995396K->747986K(1029632K), [Metaspace: 32379K->32379K(1079296K)], 0.4762912 secs] [Times: user=1.48 sys=0.03, real=0.48 secs] +82.155: [Full GC (Ergonomics) [PSYoungGen: 307034K->300802K(330240K)] [ParOldGen: 692948K->692868K(699392K)] 999983K->993671K(1029632K), [Metaspace: 32383K->32383K(1079296K)], 0.4995472 secs] [Times: user=2.06 sys=0.00, real=0.50 secs] +82.655: [Full GC (Allocation Failure) [PSYoungGen: 300802K->299369K(330240K)] [ParOldGen: 692868K->692264K(699392K)] 993671K->991633K(1029632K), [Metaspace: 32383K->32194K(1079296K)], 0.4657258 secs] [Times: user=1.97 sys=0.00, real=0.47 secs] +86.367: [Full GC (Ergonomics) [PSYoungGen: 300620K->299431K(330240K)] [ParOldGen: 692264K->692260K(699392K)] 992884K->991691K(1029632K), [Metaspace: 32195K->32195K(1079296K)], 0.5087923 secs] [Times: user=1.75 sys=0.00, real=0.51 secs] +86.876: [Full GC (Allocation Failure) [PSYoungGen: 299431K->299368K(330240K)] [ParOldGen: 692260K->692260K(699392K)] 991691K->991629K(1029632K), [Metaspace: 32195K->32195K(1079296K)], 0.2121518 secs] [Times: user=1.00 sys=0.00, real=0.21 secs] +87.095: [Full GC (Ergonomics) [PSYoungGen: 300203K->299395K(330240K)] [ParOldGen: 692260K->692260K(699392K)] 992463K->991655K(1029632K), [Metaspace: 32197K->32197K(1079296K)], 0.3650056 secs] [Times: user=1.36 sys=0.01, real=0.37 secs] +87.460: [Full GC (Allocation Failure) [PSYoungGen: 299395K->299370K(330240K)] [ParOldGen: 692260K->692260K(699392K)] 991655K->991631K(1029632K), [Metaspace: 32197K->32197K(1079296K)], 0.2872651 secs] [Times: user=1.59 sys=0.00, real=0.29 secs] +87.757: [Full GC (Ergonomics) [PSYoungGen: 300949K->299436K(330240K)] [ParOldGen: 692260K->692260K(699392K)] 993209K->991696K(1029632K), [Metaspace: 32197K->32197K(1079296K)], 0.2240331 secs] [Times: user=1.27 sys=0.00, real=0.22 secs] +87.982: [Full GC (Allocation Failure) [PSYoungGen: 299436K->299373K(330240K)] [ParOldGen: 692260K->692260K(699392K)] 991696K->991633K(1029632K), [Metaspace: 32197K->32197K(1079296K)], 0.1983266 secs] [Times: user=0.80 sys=0.00, real=0.20 secs] +88.190: [Full GC (Ergonomics) [PSYoungGen: 300577K->299396K(330240K)] [ParOldGen: 692260K->692259K(699392K)] 992837K->991655K(1029632K), [Metaspace: 32197K->32197K(1079296K)], 0.3428311 secs] [Times: user=1.31 sys=0.02, real=0.34 secs] +88.533: [Full GC (Allocation Failure) [PSYoungGen: 299396K->299374K(330240K)] [ParOldGen: 692259K->692259K(699392K)] 991655K->991633K(1029632K), [Metaspace: 32197K->32197K(1079296K)], 0.2227973 secs] [Times: user=1.11 sys=0.00, real=0.22 secs] +88.759: [Full GC (Ergonomics) [PSYoungGen: 299990K->299416K(330240K)] [ParOldGen: 692259K->692259K(699392K)] 992250K->991676K(1029632K), [Metaspace: 32197K->32197K(1079296K)], 0.1732279 secs] [Times: user=0.81 sys=0.00, real=0.17 secs] +88.933: [Full GC (Allocation Failure) [PSYoungGen: 299416K->299387K(330240K)] [ParOldGen: 692259K->692259K(699392K)] 991676K->991647K(1029632K), [Metaspace: 32197K->32197K(1079296K)], 0.2115431 secs] [Times: user=0.98 sys=0.02, real=0.21 secs] +89.160: [Full GC (Ergonomics) [PSYoungGen: 300702K->299430K(330240K)] [ParOldGen: 692259K->692259K(699392K)] 992962K->991690K(1029632K), [Metaspace: 32197K->32197K(1079296K)], 0.2311977 secs] [Times: user=1.13 sys=0.00, real=0.23 secs] +89.392: [Full GC (Allocation Failure) [PSYoungGen: 299430K->299374K(330240K)] [ParOldGen: 692259K->692259K(699392K)] 991690K->991634K(1029632K), [Metaspace: 32197K->32197K(1079296K)], 0.1891086 secs] [Times: user=0.88 sys=0.00, real=0.19 secs] +89.581: [Full GC (Ergonomics) [PSYoungGen: 299378K->299375K(330240K)] [ParOldGen: 692259K->692259K(699392K)] 991637K->991634K(1029632K), [Metaspace: 32197K->32197K(1079296K)], 0.2034002 secs] [Times: user=0.91 sys=0.00, real=0.20 secs] +89.785: [Full GC (Allocation Failure) [PSYoungGen: 299375K->299375K(330240K)] [ParOldGen: 692259K->692259K(699392K)] 991634K->991634K(1029632K), [Metaspace: 32197K->32197K(1079296K)], 0.1976397 secs] [Times: user=0.89 sys=0.00, real=0.20 secs] +89.991: [Full GC (Ergonomics) [PSYoungGen: 302291K->299438K(330240K)] [ParOldGen: 692259K->692259K(699392K)] 994550K->991697K(1029632K), [Metaspace: 32197K->32197K(1079296K)], 0.4109166 secs] [Times: user=1.58 sys=0.00, real=0.41 secs] +90.402: [Full GC (Allocation Failure) [PSYoungGen: 299438K->299375K(330240K)] [ParOldGen: 692259K->692259K(699392K)] 991697K->991634K(1029632K), [Metaspace: 32197K->32197K(1079296K)], 0.1881184 secs] [Times: user=0.91 sys=0.02, real=0.19 secs] +90.598: [Full GC (Ergonomics) [PSYoungGen: 300026K->299399K(330240K)] [ParOldGen: 692259K->692259K(699392K)] 992285K->991658K(1029632K), [Metaspace: 32197K->32197K(1079296K)], 0.1960797 secs] [Times: user=0.81 sys=0.00, real=0.20 secs] +90.794: [Full GC (Allocation Failure) [PSYoungGen: 299399K->299377K(330240K)] [ParOldGen: 692259K->692259K(699392K)] 991658K->991636K(1029632K), [Metaspace: 32197K->32197K(1079296K)], 0.2369216 secs] [Times: user=0.91 sys=0.00, real=0.24 secs] +91.048: [Full GC (Ergonomics) [PSYoungGen: 302002K->299440K(330240K)] [ParOldGen: 692259K->692259K(699392K)] 994261K->991699K(1029632K), [Metaspace: 32197K->32197K(1079296K)], 0.2534037 secs] [Times: user=1.19 sys=0.00, real=0.25 secs] +91.301: [Full GC (Allocation Failure) [PSYoungGen: 299440K->299377K(330240K)] [ParOldGen: 692259K->692259K(699392K)] 991699K->991636K(1029632K), [Metaspace: 32197K->32197K(1079296K)], 0.2611797 secs] [Times: user=1.31 sys=0.02, real=0.26 secs] +91.569: [Full GC (Ergonomics) [PSYoungGen: 300414K->299404K(330240K)] [ParOldGen: 692259K->692259K(699392K)] 992673K->991663K(1029632K), [Metaspace: 32197K->32197K(1079296K)], 0.1889955 secs] [Times: user=0.97 sys=0.00, real=0.19 secs] +91.759: [Full GC (Allocation Failure) [PSYoungGen: 299404K->299382K(330240K)] [ParOldGen: 692259K->692259K(699392K)] 991663K->991641K(1029632K), [Metaspace: 32197K->32197K(1079296K)], 0.2318707 secs] [Times: user=1.14 sys=0.00, real=0.23 secs] +92.002: [Full GC (Ergonomics) [PSYoungGen: 302616K->299406K(330240K)] [ParOldGen: 692259K->692259K(699392K)] 994876K->991665K(1029632K), [Metaspace: 32197K->32197K(1079296K)], 0.2514467 secs] [Times: user=1.23 sys=0.00, real=0.25 secs] +92.254: [Full GC (Allocation Failure) [PSYoungGen: 299406K->299381K(330240K)] [ParOldGen: 692259K->692259K(699392K)] 991665K->991640K(1029632K), [Metaspace: 32197K->32197K(1079296K)], 0.2066469 secs] [Times: user=1.03 sys=0.02, real=0.21 secs] +92.464: [Full GC (Ergonomics) [PSYoungGen: 300410K->299445K(330240K)] [ParOldGen: 692259K->692259K(699392K)] 992669K->991704K(1029632K), [Metaspace: 32197K->32197K(1079296K)], 0.2130106 secs] [Times: user=1.02 sys=0.00, real=0.21 secs] +92.678: [Full GC (Allocation Failure) [PSYoungGen: 299445K->299382K(330240K)] [ParOldGen: 692259K->692259K(699392K)] 991704K->991641K(1029632K), [Metaspace: 32197K->32197K(1079296K)], 0.2163255 secs] [Times: user=1.03 sys=0.00, real=0.22 secs] +92.901: [Full GC (Ergonomics) [PSYoungGen: 301067K->299409K(330240K)] [ParOldGen: 692259K->692258K(699392K)] 993326K->991668K(1029632K), [Metaspace: 32197K->32197K(1079296K)], 0.3972665 secs] [Times: user=1.39 sys=0.00, real=0.40 secs] +93.298: [Full GC (Allocation Failure) [PSYoungGen: 299409K->299387K(330240K)] [ParOldGen: 692258K->692258K(699392K)] 991668K->991646K(1029632K), [Metaspace: 32197K->32197K(1079296K)], 0.2574192 secs] [Times: user=1.25 sys=0.00, real=0.26 secs] +93.566: [Full GC (Ergonomics) [PSYoungGen: 302615K->299447K(330240K)] [ParOldGen: 692258K->692258K(699392K)] 994874K->991706K(1029632K), [Metaspace: 32197K->32197K(1079296K)], 0.2590185 secs] [Times: user=1.25 sys=0.00, real=0.26 secs] +93.825: [Full GC (Allocation Failure) [PSYoungGen: 299447K->299384K(330240K)] [ParOldGen: 692258K->692258K(699392K)] 991706K->991643K(1029632K), [Metaspace: 32197K->32197K(1079296K)], 0.2208867 secs] [Times: user=1.08 sys=0.00, real=0.22 secs] +94.049: [Full GC (Ergonomics) [PSYoungGen: 300236K->299407K(330240K)] [ParOldGen: 692258K->692258K(699392K)] 992495K->991666K(1029632K), [Metaspace: 32197K->32197K(1079296K)], 0.2166517 secs] [Times: user=1.06 sys=0.00, real=0.22 secs] +94.266: [Full GC (Allocation Failure) [PSYoungGen: 299407K->299385K(330240K)] [ParOldGen: 692258K->692258K(699392K)] 991666K->991644K(1029632K), [Metaspace: 32197K->32197K(1079296K)], 0.2190165 secs] [Times: user=0.99 sys=0.00, real=0.22 secs] +94.494: [Full GC (Ergonomics) [PSYoungGen: 300286K->299409K(330240K)] [ParOldGen: 692258K->692258K(699392K)] 992545K->991668K(1029632K), [Metaspace: 32197K->32197K(1079296K)], 0.2877215 secs] [Times: user=0.97 sys=0.02, real=0.29 secs] +94.782: [Full GC (Allocation Failure) [PSYoungGen: 299409K->299387K(330240K)] [ParOldGen: 692258K->692258K(699392K)] 991668K->991646K(1029632K), [Metaspace: 32197K->32197K(1079296K)], 0.2284331 secs] [Times: user=1.09 sys=0.01, real=0.23 secs] +95.011: [Full GC (Ergonomics) [PSYoungGen: 300736K->299388K(330240K)] [ParOldGen: 692258K->692258K(699392K)] 992994K->991647K(1029632K), [Metaspace: 32197K->32197K(1079296K)], 0.2016891 secs] [Times: user=0.89 sys=0.00, real=0.20 secs] +95.213: [Full GC (Allocation Failure) [PSYoungGen: 299388K->299388K(330240K)] [ParOldGen: 692258K->692258K(699392K)] 991647K->991647K(1029632K), [Metaspace: 32197K->32197K(1079296K)], 0.2138394 secs] [Times: user=0.95 sys=0.00, real=0.21 secs] +95.438: [Full GC (Ergonomics) [PSYoungGen: 302741K->299453K(330240K)] [ParOldGen: 692258K->692258K(699392K)] 994999K->991712K(1029632K), [Metaspace: 32197K->32197K(1079296K)], 0.1914459 secs] [Times: user=0.94 sys=0.00, real=0.19 secs] +95.630: [Full GC (Allocation Failure) [PSYoungGen: 299453K->299390K(330240K)] [ParOldGen: 692258K->692258K(699392K)] 991712K->991649K(1029632K), [Metaspace: 32197K->32197K(1079296K)], 0.2327758 secs] [Times: user=1.16 sys=0.00, real=0.23 secs] +95.863: [Full GC (Ergonomics) [PSYoungGen: 299392K->299390K(330240K)] [ParOldGen: 692258K->692258K(699392K)] 991651K->991649K(1029632K), [Metaspace: 32197K->32197K(1079296K)], 0.2061028 secs] [Times: user=0.95 sys=0.00, real=0.21 secs] +96.069: [Full GC (Allocation Failure) [PSYoungGen: 299390K->299390K(330240K)] [ParOldGen: 692258K->692258K(699392K)] 991649K->991649K(1029632K), [Metaspace: 32197K->32197K(1079296K)], 0.2099929 secs] [Times: user=1.08 sys=0.00, real=0.21 secs] +96.286: [Full GC (Ergonomics) [PSYoungGen: 301139K->299415K(330240K)] [ParOldGen: 692258K->692258K(699392K)] 993398K->991673K(1029632K), [Metaspace: 32197K->32197K(1079296K)], 0.2135339 secs] [Times: user=1.13 sys=0.00, real=0.21 secs] +96.500: [Full GC (Allocation Failure) [PSYoungGen: 299415K->299392K(330240K)] [ParOldGen: 692258K->692258K(699392K)] 991673K->991651K(1029632K), [Metaspace: 32197K->32197K(1079296K)], 0.2037234 secs] [Times: user=0.91 sys=0.00, real=0.20 secs] +96.712: [Full GC (Ergonomics) [PSYoungGen: 300591K->299461K(330240K)] [ParOldGen: 692258K->692258K(699392K)] 992849K->991720K(1029632K), [Metaspace: 32197K->32197K(1079296K)], 0.2477421 secs] [Times: user=1.34 sys=0.00, real=0.25 secs] +96.960: [Full GC (Allocation Failure) [PSYoungGen: 299461K->299395K(330240K)] [ParOldGen: 692258K->692258K(699392K)] 991720K->991654K(1029632K), [Metaspace: 32197K->32197K(1079296K)], 0.2135037 secs] [Times: user=1.00 sys=0.00, real=0.21 secs] +97.174: [Full GC (Ergonomics) [PSYoungGen: 299403K->299396K(330240K)] [ParOldGen: 692258K->692258K(699392K)] 991662K->991654K(1029632K), [Metaspace: 32197K->32197K(1079296K)], 0.2316349 secs] [Times: user=1.14 sys=0.00, real=0.23 secs] +97.406: [Full GC (Allocation Failure) [PSYoungGen: 299396K->299396K(330240K)] [ParOldGen: 692258K->692258K(699392K)] 991654K->991654K(1029632K), [Metaspace: 32197K->32197K(1079296K)], 0.2278539 secs] [Times: user=0.98 sys=0.00, real=0.23 secs] +97.642: [Full GC (Ergonomics) [PSYoungGen: 302266K->299419K(330240K)] [ParOldGen: 692258K->692258K(699392K)] 994525K->991678K(1029632K), [Metaspace: 32197K->32197K(1079296K)], 0.1826099 secs] [Times: user=0.94 sys=0.00, real=0.18 secs] +97.825: [Full GC (Allocation Failure) [PSYoungGen: 299419K->299397K(330240K)] [ParOldGen: 692258K->692258K(699392K)] 991678K->991656K(1029632K), [Metaspace: 32197K->32197K(1079296K)], 0.2146380 secs] [Times: user=0.97 sys=0.02, real=0.21 secs] +98.047: [Full GC (Ergonomics) [PSYoungGen: 300506K->299464K(330240K)] [ParOldGen: 692258K->692258K(699392K)] 992765K->991723K(1029632K), [Metaspace: 32197K->32197K(1079296K)], 0.1901511 secs] [Times: user=0.89 sys=0.00, real=0.19 secs] +98.237: [Full GC (Allocation Failure) [PSYoungGen: 299464K->299402K(330240K)] [ParOldGen: 692258K->692258K(699392K)] 991723K->991660K(1029632K), [Metaspace: 32197K->32197K(1079296K)], 0.2287836 secs] [Times: user=1.02 sys=0.00, real=0.23 secs] +98.466: [Full GC (Ergonomics) [PSYoungGen: 300305K->299402K(330240K)] [ParOldGen: 692258K->692258K(699392K)] 992563K->991661K(1029632K), [Metaspace: 32197K->32197K(1079296K)], 0.2232204 secs] [Times: user=1.14 sys=0.02, real=0.22 secs] +98.690: [Full GC (Allocation Failure) [PSYoungGen: 299402K->299402K(330240K)] [ParOldGen: 692258K->692258K(699392K)] 991661K->991661K(1029632K), [Metaspace: 32197K->32197K(1079296K)], 0.1975750 secs] [Times: user=0.95 sys=0.00, real=0.20 secs] +98.894: [Full GC (Ergonomics) [PSYoungGen: 300787K->299423K(330240K)] [ParOldGen: 692258K->692258K(699392K)] 993046K->991681K(1029632K), [Metaspace: 32197K->32197K(1079296K)], 0.2162200 secs] [Times: user=1.17 sys=0.00, real=0.22 secs] +99.110: [Full GC (Allocation Failure) [PSYoungGen: 299423K->299400K(330240K)] [ParOldGen: 692258K->692258K(699392K)] 991681K->991659K(1029632K), [Metaspace: 32197K->32197K(1079296K)], 0.2363169 secs] [Times: user=1.27 sys=0.00, real=0.24 secs] +99.359: [Full GC (Ergonomics) [PSYoungGen: 300556K->299464K(330240K)] [ParOldGen: 692258K->692258K(699392K)] 992814K->991723K(1029632K), [Metaspace: 32197K->32197K(1079296K)], 0.2158705 secs] [Times: user=1.05 sys=0.00, real=0.22 secs] +99.575: [Full GC (Allocation Failure) [PSYoungGen: 299464K->299401K(330240K)] [ParOldGen: 692258K->692258K(699392K)] 991723K->991660K(1029632K), [Metaspace: 32197K->32197K(1079296K)], 0.2273654 secs] [Times: user=0.89 sys=0.00, real=0.23 secs] +99.804: [Full GC (Ergonomics) [PSYoungGen: 299407K->299402K(330240K)] [ParOldGen: 692258K->692258K(699392K)] 991666K->991660K(1029632K), [Metaspace: 32197K->32197K(1079296K)], 0.3584789 secs] [Times: user=2.05 sys=0.03, real=0.36 secs] +100.162: [Full GC (Allocation Failure) [PSYoungGen: 299402K->299402K(330240K)] [ParOldGen: 692258K->692258K(699392K)] 991660K->991660K(1029632K), [Metaspace: 32197K->32197K(1079296K)], 0.2177550 secs] [Times: user=1.13 sys=0.00, real=0.22 secs] +100.390: [Full GC (Ergonomics) [PSYoungGen: 302312K->299466K(330240K)] [ParOldGen: 692258K->692258K(699392K)] 994570K->991725K(1029632K), [Metaspace: 32197K->32197K(1079296K)], 0.2225672 secs] [Times: user=1.03 sys=0.00, real=0.22 secs] +100.613: [Full GC (Allocation Failure) [PSYoungGen: 299466K->299403K(330240K)] [ParOldGen: 692258K->692258K(699392K)] 991725K->991662K(1029632K), [Metaspace: 32197K->32197K(1079296K)], 0.2406893 secs] [Times: user=1.14 sys=0.02, real=0.24 secs] +100.854: [Full GC (Ergonomics) [PSYoungGen: 299405K->299404K(330240K)] [ParOldGen: 692258K->692258K(699392K)] 991664K->991663K(1029632K), [Metaspace: 32197K->32197K(1079296K)], 0.2546441 secs] [Times: user=1.20 sys=0.00, real=0.25 secs] +101.109: [Full GC (Allocation Failure) [PSYoungGen: 299404K->299404K(330240K)] [ParOldGen: 692258K->692258K(699392K)] 991663K->991663K(1029632K), [Metaspace: 32197K->32197K(1079296K)], 0.2416729 secs] [Times: user=1.09 sys=0.01, real=0.24 secs] +101.360: [Full GC (Ergonomics) [PSYoungGen: 302680K->299428K(330240K)] [ParOldGen: 692258K->692258K(699392K)] 994939K->991687K(1029632K), [Metaspace: 32197K->32197K(1079296K)], 0.2478133 secs] [Times: user=1.33 sys=0.02, real=0.25 secs] +101.608: [Full GC (Allocation Failure) [PSYoungGen: 299428K->299406K(330240K)] [ParOldGen: 692258K->692258K(699392K)] 991687K->991664K(1029632K), [Metaspace: 32197K->32197K(1079296K)], 0.2172785 secs] [Times: user=0.98 sys=0.00, real=0.22 secs] +101.832: [Full GC (Ergonomics) [PSYoungGen: 302063K->299448K(330240K)] [ParOldGen: 692258K->692258K(699392K)] 994322K->991707K(1029632K), [Metaspace: 32205K->32205K(1079296K)], 0.2144298 secs] [Times: user=1.08 sys=0.00, real=0.21 secs] +102.047: [Full GC (Allocation Failure) [PSYoungGen: 299448K->299425K(330240K)] [ParOldGen: 692258K->692258K(699392K)] 991707K->991684K(1029632K), [Metaspace: 32205K->32205K(1079296K)], 0.1937286 secs] [Times: user=0.94 sys=0.00, real=0.20 secs] +102.248: [Full GC (Ergonomics) [PSYoungGen: 300419K->299457K(330240K)] [ParOldGen: 692258K->692258K(699392K)] 992677K->991716K(1029632K), [Metaspace: 32205K->32205K(1079296K)], 0.2157237 secs] [Times: user=1.11 sys=0.00, real=0.22 secs] +102.464: [Full GC (Allocation Failure) [PSYoungGen: 299457K->299416K(330240K)] [ParOldGen: 692258K->692258K(699392K)] 991716K->991675K(1029632K), [Metaspace: 32205K->32205K(1079296K)], 0.2227619 secs] [Times: user=1.00 sys=0.00, real=0.22 secs] +102.692: [Full GC (Ergonomics) [PSYoungGen: 299771K->283063K(330240K)] [ParOldGen: 692258K->692258K(699392K)] 992029K->975321K(1029632K), [Metaspace: 32205K->32205K(1079296K)], 0.3966756 secs] [Times: user=1.34 sys=0.00, real=0.40 secs] +103.090: [Full GC (Ergonomics) [PSYoungGen: 299468K->299438K(330240K)] [ParOldGen: 692258K->692258K(699392K)] 991726K->991697K(1029632K), [Metaspace: 32205K->32205K(1079296K)], 0.2294288 secs] [Times: user=1.17 sys=0.02, real=0.23 secs] +103.319: [Full GC (Allocation Failure) [PSYoungGen: 299438K->299416K(330240K)] [ParOldGen: 692258K->692258K(699392K)] 991697K->991674K(1029632K), [Metaspace: 32205K->32205K(1079296K)], 0.2181420 secs] [Times: user=1.03 sys=0.03, real=0.22 secs] +103.544: [Full GC (Ergonomics) [PSYoungGen: 300847K->262595K(330240K)] [ParOldGen: 692258K->696354K(699392K)] 993106K->958950K(1029632K), [Metaspace: 32205K->32205K(1079296K)], 0.4733754 secs] [Times: user=1.55 sys=0.01, real=0.47 secs] +104.031: [Full GC (Ergonomics) [PSYoungGen: 296830K->262278K(330240K)] [ParOldGen: 696354K->696692K(699392K)] 993184K->958970K(1029632K), [Metaspace: 32205K->32205K(1079296K)], 0.4813451 secs] [Times: user=1.91 sys=0.00, real=0.48 secs] +104.524: [Full GC (Ergonomics) [PSYoungGen: 296425K->262272K(330240K)] [ParOldGen: 696692K->696696K(699392K)] 993117K->958969K(1029632K), [Metaspace: 32205K->32205K(1079296K)], 0.4322844 secs] [Times: user=1.36 sys=0.00, real=0.43 secs] +104.964: [Full GC (Ergonomics) [PSYoungGen: 296403K->278650K(330240K)] [ParOldGen: 696696K->696698K(699392K)] 993100K->975349K(1029632K), [Metaspace: 32205K->32205K(1079296K)], 0.6573269 secs] [Times: user=2.72 sys=0.01, real=0.66 secs] +105.625: [Full GC (Ergonomics) [PSYoungGen: 311808K->295036K(330240K)] [ParOldGen: 696698K->696700K(699392K)] 1008506K->991737K(1029632K), [Metaspace: 32205K->32205K(1079296K)], 0.4478491 secs] [Times: user=1.59 sys=0.00, real=0.45 secs] +106.078: [Full GC (Ergonomics) [PSYoungGen: 296566K->278653K(330240K)] [ParOldGen: 696700K->696700K(699392K)] 993267K->975353K(1029632K), [Metaspace: 32205K->32205K(1079296K)], 0.4475804 secs] [Times: user=1.63 sys=0.00, real=0.45 secs] +106.532: [Full GC (Ergonomics) [PSYoungGen: 296494K->278652K(330240K)] [ParOldGen: 696700K->696700K(699392K)] 993194K->975353K(1029632K), [Metaspace: 32205K->32205K(1079296K)], 0.4860856 secs] [Times: user=1.49 sys=0.02, real=0.49 secs] +107.024: [Full GC (Ergonomics) [PSYoungGen: 296310K->278661K(330240K)] [ParOldGen: 696700K->696700K(699392K)] 993010K->975362K(1029632K), [Metaspace: 32205K->32205K(1079296K)], 0.4304760 secs] [Times: user=1.44 sys=0.02, real=0.43 secs] +107.470: [Full GC (Ergonomics) \ No newline at end of file diff --git a/jvm/jvm.iml b/jvm/jvm.iml new file mode 100644 index 0000000..62eef8f --- /dev/null +++ b/jvm/jvm.iml @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/jvm/pom.xml b/jvm/pom.xml new file mode 100644 index 0000000..157534d --- /dev/null +++ b/jvm/pom.xml @@ -0,0 +1,46 @@ + + + 4.0.0 + + org.springframework.boot + spring-boot-starter-parent + 2.2.0.RELEASE + + + com.tison + jvm + 0.0.1-SNAPSHOT + basic + JVM project for Spring Boot + + + 1.8 + + + + + org.projectlombok + lombok + 1.18.8 + provided + + + cglib + cglib + 3.1 + compile + + + + + jvm + + + org.springframework.boot + spring-boot-maven-plugin + + + + + diff --git a/jvm/src/main/java/HelloWorld.java b/jvm/src/main/java/HelloWorld.java new file mode 100644 index 0000000..8d260f0 --- /dev/null +++ b/jvm/src/main/java/HelloWorld.java @@ -0,0 +1,14 @@ +/** + * @author tison + * @date 2020/3/18 + * @description + */ +public class HelloWorld { + public static void main(String[] args) { + print(); + } + public static void print() { + String content = new String("Hello World"); + System.out.println(content); + } +} diff --git a/jvm/src/main/java/classloader/ClassLoaderMain.java b/jvm/src/main/java/classloader/ClassLoaderMain.java new file mode 100644 index 0000000..35ca286 --- /dev/null +++ b/jvm/src/main/java/classloader/ClassLoaderMain.java @@ -0,0 +1,27 @@ +package classloader; + +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; + +/** + * 类加载器主函数 + */ +public class ClassLoaderMain { + public static void main(String[] args) throws ClassNotFoundException, InstantiationException, IllegalAccessException, NoSuchMethodException, SecurityException, IllegalArgumentException, InvocationTargetException { + //这个类class的路径 + String classPath = "d/Hello.class"; + MyClassLoader myClassLoader = new MyClassLoader(classPath); + + //类的全称 + String packageNamePath = "classloader.Hello"; + + //加载Log这个class文件 + Class Hello = myClassLoader.loadClass(packageNamePath); + + //利用反射获取main方法 + Method method = Hello.getDeclaredMethod("main", String[].class); + Object object = Hello.newInstance(); + String[] arg = {"ad"}; + method.invoke(object, (Object) arg); + } +} diff --git a/jvm/src/main/java/classloader/Hello.java b/jvm/src/main/java/classloader/Hello.java new file mode 100644 index 0000000..cb7b722 --- /dev/null +++ b/jvm/src/main/java/classloader/Hello.java @@ -0,0 +1,12 @@ +package classloader; + +/** + * 需要编译的class + */ +public class Hello { + + public static void main(String[] args) { + System.out.println("load Log class successfully"); + } + +} diff --git a/jvm/src/main/java/classloader/MyClassLoader.java b/jvm/src/main/java/classloader/MyClassLoader.java new file mode 100644 index 0000000..fbe1ef9 --- /dev/null +++ b/jvm/src/main/java/classloader/MyClassLoader.java @@ -0,0 +1,67 @@ +package classloader; + +import java.io.ByteArrayOutputStream; +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; + +/** + * @author admin + * 自定义类加载器 + */ +public class MyClassLoader extends ClassLoader { + + /** + * 指定路径 + */ + private String path ; + + public MyClassLoader(String classPath){ + path=classPath; + } + + /** + * 重写findClass方法 + * @param name 是我们这个类的全路径 + * @return + * @throws ClassNotFoundException + */ + @Override + protected Class findClass(String name) throws ClassNotFoundException { + Class log = null; + // 获取该class文件字节码数组 + byte[] classData = getData(); + if (classData != null) { + // 将class的字节码数组转换成Class类的实例 + log = defineClass(name, classData, 0, classData.length); + } + return log; + } + + /** + * 将class文件转化为字节码数组 + * @return + */ + private byte[] getData() { + File file = new File(path); + if (file.exists()){ + try(FileInputStream in = new FileInputStream(file); + ByteArrayOutputStream out = new ByteArrayOutputStream()){ + byte[] buffer = new byte[1024]; + int size = 0; + while ((size = in.read(buffer)) != -1) { + out.write(buffer, 0, size); + } + return out.toByteArray(); + } catch (IOException e) { + e.printStackTrace(); + return null; + } + }else{ + return null; + } + + + } + +} diff --git a/jvm/src/main/java/gc/FullGCOptimize.txt b/jvm/src/main/java/gc/FullGCOptimize.txt new file mode 100644 index 0000000..2bdde8f --- /dev/null +++ b/jvm/src/main/java/gc/FullGCOptimize.txt @@ -0,0 +1,27 @@ +1、优化前JVM参数设置如下: +------------------------------------------------------------ +-Xms200M +-Xmx200M +-XX:NewSize=100m +-XX:MaxNewSize=100m +-XX:SurvivorRatio=8 +-XX:PretenureSizeThreshold=20m +-XX:+UseConcMarkSweepGC +-Xloggc:gc.log +-XX:+PrintGCDetails +-XX:+PrintGCDateStamps +-XX:+PrintGCTimeStamps + +3、优化后JVM参数 +------------------------------------------------------------ +-Xms300M +-Xmx300M +-XX:NewSize=200m +-XX:MaxNewSize=200m +-XX:SurvivorRatio=2 +-XX:PretenureSizeThreshold=20m +-XX:+UseConcMarkSweepGC +-Xloggc:gc.log +-XX:+PrintGCDetails +-XX:+PrintGCDateStamps +-XX:+PrintGCTimeStamps \ No newline at end of file diff --git a/jvm/src/main/java/gc/FullGCOptmize.java b/jvm/src/main/java/gc/FullGCOptmize.java new file mode 100644 index 0000000..fe80fe4 --- /dev/null +++ b/jvm/src/main/java/gc/FullGCOptmize.java @@ -0,0 +1,32 @@ +package gc; + +/** + * FullGC调优实例 + * BEFORE_JVM_SETTING:-Xms200M -Xmx200M -XX:NewSize=100m -XX:MaxNewSize=100m -XX:SurvivorRatio=8 -XX:PretenureSizeThreshold=20m -XX:+UseConcMarkSweepGC -Xloggc:gc.log -XX:+PrintGCDetails -XX:+PrintGCDateStamps -XX:+PrintGCTimeStamps + * AFTER_JVM_SETTING: -Xms300M -Xmx300M -XX:NewSize=200m -XX:MaxNewSize=200m -XX:SurvivorRatio=2 -XX:PretenureSizeThreshold=20m -XX:+UseConcMarkSweepGC -Xloggc:gc.log -XX:+PrintGCDetails -XX:+PrintGCDateStamps -XX:+PrintGCTimeStamps + */ +public class FullGCOptmize { + + public static void main(String[] args) throws Exception{ + Thread.sleep(1000); + while (true) { + loadData(); + } + } + + public static void loadData() throws Exception{ + byte[] data = null; + for (int i = 0; i < 4; i++) { + data = new byte[10 * 1024 * 1024]; + } + data = null; + + byte[] data1 = new byte[10 * 1024 * 1024]; + byte[] data2 = new byte[10 * 1024 * 1024]; + + byte[] data3 = new byte[10 * 1024 * 1024]; + data3 = new byte[10 * 1024 * 1024]; + + Thread.sleep(1000); + } +} diff --git a/jvm/src/main/java/gc/OldGCTest.java b/jvm/src/main/java/gc/OldGCTest.java new file mode 100644 index 0000000..8a73077 --- /dev/null +++ b/jvm/src/main/java/gc/OldGCTest.java @@ -0,0 +1,25 @@ +package gc; + +/** + * 模拟OldGC测试 + * JVM_SETTINGS:-Xms10M -Xmx10M -XX:NewSize=5m -XX:MaxNewSize=5m -XX:SurvivorRatio=8 -XX:PretenureSizeThreshold=10m -XX:+UseConcMarkSweepGC -Xloggc:gc.log -XX:+PrintGCDetails -XX:+PrintGCDateStamps -XX:+PrintGCTimeStamps + */ +public class OldGCTest { + + public static void main(String[] args) { + byte[] arr1 = new byte[2*1024*1024]; + arr1 = new byte[2*1024*1024]; + arr1 = new byte[2*1024*1024]; + arr1 = null; + + byte[] arr2 = new byte[128*1024]; + byte[] arr3 = new byte[2*1024*1024]; + arr3 = new byte[2*1024*1024]; + arr3 = new byte[2*1024*1024]; + arr3 = new byte[128*1024]; + arr3 = null; + + byte[] arr4 = new byte[2*1024*1024]; + } + +} diff --git a/jvm/src/main/java/gc/OldGCTest.txt b/jvm/src/main/java/gc/OldGCTest.txt new file mode 100644 index 0000000..b7d0a0f --- /dev/null +++ b/jvm/src/main/java/gc/OldGCTest.txt @@ -0,0 +1,46 @@ +1、JVM参数设置如下: +------------------------------------------------------------ +-Xms10M +-Xmx10M +-XX:NewSize=5m +-XX:MaxNewSize=5m +-XX:SurvivorRatio=8 +-XX:PretenureSizeThreshold=10m +-XX:+UseConcMarkSweepGC +-Xloggc:gc.log +-XX:+PrintGCDetails +-XX:+PrintGCDateStamps +-XX:+PrintGCTimeStamps + +2、JVM参数合并一行: +------------------------------------------------------------ +-Xms10M -Xmx10M -XX:NewSize=5m -XX:MaxNewSize=5m -XX:SurvivorRatio=8 -XX:PretenureSizeThreshold=10m -XX:+UseConcMarkSweepGC -Xloggc:gc.log -XX:+PrintGCDetails -XX:+PrintGCDateStamps -XX:+PrintGCTimeStamps + +3、执行Test方法生成的gc日志如下: +------------------------------------------------------------ +Java HotSpot(TM) 64-Bit Server VM (25.202-b08) for windows-amd64 JRE (1.8.0_202-b08), built on Dec 15 2018 19:54:30 by "java_re" with MS VC++ 10.0 (VS2010) +Memory: 4k page, physical 8230644k(1943744k free), swap 12031732k(2166116k free) +CommandLine flags: -XX:InitialHeapSize=10485760 -XX:MaxHeapSize=10485760 -XX:MaxNewSize=5242880 -XX:NewSize=5242880 -XX:OldPLABSize=16 -XX:PretenureSizeThreshold=10485760 -XX:+PrintGC -XX:+PrintGCDateStamps -XX:+PrintGCDetails -XX:+PrintGCTimeStamps -XX:SurvivorRatio=8 -XX:+UseCompressedClassPointers -XX:+UseCompressedOops -XX:+UseConcMarkSweepGC -XX:-UseLargePagesIndividualAllocation -XX:+UseParNewGC +2020-03-22T10:01:32.194+0800: 0.159: [GC (Allocation Failure) 2020-03-22T10:01:32.195+0800: 0.159: [ParNew: 4096K->512K(4608K), 0.0017725 secs] 4096K->2740K(9728K), 0.0019813 secs] [Times: user=0.00 sys=0.00, real=0.00 secs] +2020-03-22T10:01:32.197+0800: 0.162: [GC (Allocation Failure) 2020-03-22T10:01:32.197+0800: 0.162: [ParNew (promotion failed): 2560K->2048K(4608K), 0.0013742 secs]2020-03-22T10:01:32.198+0800: 0.163: [CMS: 4644K->2682K(5120K), 0.0019116 secs] 4788K->2682K(9728K), [Metaspace: 3044K->3044K(1056768K)], 0.0033608 secs] [Times: user=0.00 sys=0.00, real=0.00 secs] +2020-03-22T10:01:32.200+0800: 0.165: [GC (CMS Initial Mark) [1 CMS-initial-mark: 2682K(5120K)] 4730K(9728K), 0.0001262 secs] [Times: user=0.00 sys=0.00, real=0.00 secs] +2020-03-22T10:01:32.200+0800: 0.165: [CMS-concurrent-mark-start] +2020-03-22T10:01:32.200+0800: 0.165: [GC (Allocation Failure) 2020-03-22T10:01:32.200+0800: 0.165: [ParNew: 2255K->128K(4608K), 0.0002048 secs] 4938K->2810K(9728K), 0.0002345 secs] [Times: user=0.00 sys=0.00, real=0.00 secs] +2020-03-22T10:01:32.201+0800: 0.166: [GC (Allocation Failure) 2020-03-22T10:01:32.201+0800: 0.166: [ParNew: 2257K->128K(4608K), 0.0004231 secs] 4940K->4861K(9728K), 0.0004502 secs] [Times: user=0.00 sys=0.00, real=0.00 secs] +2020-03-22T10:01:32.201+0800: 0.166: [GC (Allocation Failure) 2020-03-22T10:01:32.201+0800: 0.166: [ParNew: 2176K->2176K(4608K), 0.0000118 secs]2020-03-22T10:01:32.201+0800: 0.166: [CMS2020-03-22T10:01:32.202+0800: 0.167: [CMS-concurrent-mark: 0.000/0.002 secs] [Times: user=0.00 sys=0.00, real=0.00 secs] + (concurrent mode failure): 4733K->2775K(5120K), 0.0022860 secs] 6909K->2775K(9728K), [Metaspace: 3048K->3048K(1056768K)], 0.0023470 secs] [Times: user=0.00 sys=0.00, real=0.00 secs] +2020-03-22T10:01:32.204+0800: 0.169: [GC (Allocation Failure) 2020-03-22T10:01:32.204+0800: 0.169: [ParNew: 2294K->0K(4608K), 0.0002142 secs] 5070K->2775K(9728K), 0.0002384 secs] [Times: user=0.00 sys=0.00, real=0.00 secs] +2020-03-22T10:01:32.204+0800: 0.169: [GC (CMS Initial Mark) [1 CMS-initial-mark: 2775K(5120K)] 4823K(9728K), 0.0000591 secs] [Times: user=0.00 sys=0.00, real=0.00 secs] +2020-03-22T10:01:32.204+0800: 0.169: [CMS-concurrent-mark-start] +2020-03-22T10:01:32.205+0800: Heap +0.170: par new generation [CMS-concurrent-mark: 0.001/0.001 secs] total 4608K, used 2089K [0x00000000ff600000, 0x00000000ffb00000, 0x00000000ffb00000) + eden space 4096K, 51% used [0x00000000ff600000, 0x00000000ff80a558, 0x00000000ffa00000) + from space 512K, 0% used [Times: user=0.06 sys=0.00, real=0.00 secs] + [0x00000000ffa80000, 0x00000000ffa80000, 0x00000000ffb00000) + to space 512K, 0% used [0x00000000ffa00000, 0x00000000ffa00000, 0x00000000ffa80000) +2020-03-22T10:01:32.205+0800: concurrent mark-sweep generation0.170: [CMS-concurrent-preclean-start] + total 5120K, used 2775K [0x00000000ffb00000, 0x0000000100000000, 0x0000000100000000) + Metaspace used 3054K, capacity 4556K, committed 4864K, reserved 1056768K + class space used 323K, capacity 392K, committed 512K, reserved 1048576K +2020-03-22T10:01:32.205+0800: 0.170: [CMS-concurrent-preclean: 0.000/0.000 secs] [Times: user=0.00 sys=0.00, real=0.00 secs] +2020-03-22T10:01:32.205+0800: 0.170: [CMS-concurrent-abortable-preclean-start] diff --git a/jvm/src/main/java/gc/YoungGCTest.java b/jvm/src/main/java/gc/YoungGCTest.java new file mode 100644 index 0000000..2f70b66 --- /dev/null +++ b/jvm/src/main/java/gc/YoungGCTest.java @@ -0,0 +1,17 @@ +package gc; + +/** + * 模拟YoungGC测试 + */ +public class YoungGCTest { + + public static void main(String[] args) { + byte[] arr1 = new byte[1024*1024]; + arr1 = new byte[1024*1024]; + arr1 = new byte[1024*1024]; + arr1 = null; + + byte[] arr2 = new byte[2*1024*1024]; + } + +} diff --git a/jvm/src/main/java/gc/YoungGCTest.txt b/jvm/src/main/java/gc/YoungGCTest.txt new file mode 100644 index 0000000..b9b505d --- /dev/null +++ b/jvm/src/main/java/gc/YoungGCTest.txt @@ -0,0 +1,32 @@ +1、JVM参数设置如下: +------------------------------------------------------------ +-Xms10M +-Xmx10M +-XX:NewSize=5m +-XX:MaxNewSize=5m +-XX:SurvivorRatio=8 +-XX:PretenureSizeThreshold=10m +-XX:+UseConcMarkSweepGC +-Xloggc:gc.log +-XX:+PrintGCDetails +-XX:+PrintGCDateStamps +-XX:+PrintGCTimeStamps + +2、JVM参数合并一行: +------------------------------------------------------------ +-Xms10M -Xmx10M -XX:NewSize=5m -XX:MaxNewSize=5m -XX:SurvivorRatio=8 -XX:PretenureSizeThreshold=10m -XX:+UseConcMarkSweepGC -Xloggc:gc.log -XX:+PrintGCDetails -XX:+PrintGCDateStamps -XX:+PrintGCTimeStamps + +3、执行Test方法生成的gc日志如下: +------------------------------------------------------------ +Java HotSpot(TM) 64-Bit Server VM (25.202-b08) for windows-amd64 JRE (1.8.0_202-b08), built on Dec 15 2018 19:54:30 by "java_re" with MS VC++ 10.0 (VS2010) +Memory: 4k page, physical 8230644k(1738784k free), swap 12031732k(2868568k free) +CommandLine flags: -XX:InitialHeapSize=10485760 -XX:MaxHeapSize=10485760 -XX:MaxNewSize=5242880 -XX:NewSize=5242880 -XX:OldPLABSize=16 -XX:PretenureSizeThreshold=10485760 -XX:+PrintGC -XX:+PrintGCDateStamps -XX:+PrintGCDetails -XX:+PrintGCTimeStamps -XX:SurvivorRatio=8 -XX:+UseCompressedClassPointers -XX:+UseCompressedOops -XX:+UseConcMarkSweepGC -XX:-UseLargePagesIndividualAllocation -XX:+UseParNewGC +2020-03-21T23:29:14.826+0800: 0.216: [GC (Allocation Failure) 2020-03-21T23:29:14.827+0800: 0.217: [ParNew: 3098K->512K(4608K), 0.0019817 secs] 3098K->1712K(9728K), 0.0030021 secs] [Times: user=0.00 sys=0.05, real=0.00 secs] +2020-03-21T23:29:14.830+0800: 0.219: [GC (Allocation Failure) 2020-03-21T23:29:14.830+0800: 0.219: [ParNew: 2638K->0K(4608K), 0.0018264 secs] 3839K->1715K(9728K), 0.0019584 secs] [Times: user=0.00 sys=0.00, real=0.00 secs] +Heap + par new generation total 4608K, used 2089K [0x00000000ff600000, 0x00000000ffb00000, 0x00000000ffb00000) + eden space 4096K, 51% used [0x00000000ff600000, 0x00000000ff80a558, 0x00000000ffa00000) + from space 512K, 0% used [0x00000000ffa00000, 0x00000000ffa00000, 0x00000000ffa80000) + to space 512K, 0% used [0x00000000ffa80000, 0x00000000ffa80000, 0x00000000ffb00000) + concurrent mark-sweep generation total 5120K, used 1715K [0x00000000ffb00000, 0x0000000100000000, 0x0000000100000000) + Metaspace used 3053K, capacity 4556K, committed 4864K, reserved 1056768K \ No newline at end of file diff --git a/jvm/src/main/java/oom/DirectByteBufferOOM.java b/jvm/src/main/java/oom/DirectByteBufferOOM.java new file mode 100644 index 0000000..35ee874 --- /dev/null +++ b/jvm/src/main/java/oom/DirectByteBufferOOM.java @@ -0,0 +1,18 @@ +package oom; + +import java.nio.ByteBuffer; +import java.util.concurrent.TimeUnit; + +/** + * 堆外内存空间不足引发OOM + * -Xmx256m -XX:MaxDirectMemorySize=100M + */ +public class DirectByteBufferOOM { + + public static void main(String[] args) throws InterruptedException{ + //分配128MB直接内存 + ByteBuffer bb = ByteBuffer.allocateDirect(1024*1024*128); + TimeUnit.SECONDS.sleep(10); + System.out.println("ok"); + } +} diff --git a/jvm/src/main/java/oom/HeapOOM.java b/jvm/src/main/java/oom/HeapOOM.java new file mode 100644 index 0000000..c6b76ac --- /dev/null +++ b/jvm/src/main/java/oom/HeapOOM.java @@ -0,0 +1,31 @@ +package oom; + +import java.util.ArrayList; +import java.util.List; + +/** + * JVM配置参数 + * -Xms20m JVM初始分配的内存20m + * -Xmx20m JVM最大可用内存为20m + * -XX:+HeapDumpOnOutOfMemoryError 当JVM发生OOM时,自动生成DUMP文件 + * -XX:HeapDumpPath=d: 生成DUMP文件的路径 + * JVM_SETTINGS:-Xms20m -Xmx20m -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=d:/dump/ + */ +public class HeapOOM { + + static class OOMObject { + } + + public static void main(String[] args) { + int i = 0; + List list = new ArrayList(); + cycle(list, i); + } + public static void cycle(List list, int i) { + //在堆中无限创建对象 + while (true) { + System.out.println("already create objects=" + i++); + list.add(new OOMObject()); + } + } +} diff --git a/jvm/src/main/java/oom/MetaSpaceOOM.java b/jvm/src/main/java/oom/MetaSpaceOOM.java new file mode 100644 index 0000000..dd6b6ab --- /dev/null +++ b/jvm/src/main/java/oom/MetaSpaceOOM.java @@ -0,0 +1,35 @@ +package oom; + +import net.sf.cglib.proxy.Enhancer; +import net.sf.cglib.proxy.MethodInterceptor; +import net.sf.cglib.proxy.MethodProxy; + +import java.lang.reflect.Method; + +/** + * @author admin + * @description 虚拟机栈OOM + * JVM_SETTINGS:-XX:MetaspaceSize=10M -XX:MaxMetaspaceSize=10M + */ +public class MetaSpaceOOM { + + public static void main(String[] args) { + + while (true) { + Enhancer enhancer = new Enhancer(); + enhancer.setSuperclass(OOMObject.class); + enhancer.setUseCache(false); + + enhancer.setCallback(new MethodInterceptor() { + @Override + public Object intercept(Object obj, Method method, + Object[] args, MethodProxy proxy) throws Throwable { + return proxy.invokeSuper(obj, args); + } + }); + enhancer.create(); + } + } + static class OOMObject { + } +} diff --git a/jvm/src/main/java/oom/ThreadOOM.java b/jvm/src/main/java/oom/ThreadOOM.java new file mode 100644 index 0000000..d0a3437 --- /dev/null +++ b/jvm/src/main/java/oom/ThreadOOM.java @@ -0,0 +1,25 @@ +package oom; + +/** + * 模拟虚拟机栈溢出 + * 假如虚拟机栈可以动态扩展,当扩展时无法申请到足够的内存时会抛出 OutOfMemoryError 异常 + */ +public class ThreadOOM { + + private void cycle(){ + while(true){ + } + } + + public void stackLeakByThread(){ + while(true){ + new Thread(()->{ cycle(); }).start(); + } + } + + public static void main(String[] args) { + ThreadOOM oom = new ThreadOOM(); + oom.stackLeakByThread(); + + } +} diff --git a/netty/src/main/java/com/tison/kong/basic/nio/LinkChatHandler.java b/netty/src/main/java/com/tison/kong/basic/nio/LinkChatHandler.java new file mode 100644 index 0000000..ab8e9b3 --- /dev/null +++ b/netty/src/main/java/com/tison/kong/basic/nio/LinkChatHandler.java @@ -0,0 +1,38 @@ +package com.tison.kong.basic.nio; + +import io.netty.buffer.ByteBuf; +import io.netty.channel.ChannelHandlerContext; +import io.netty.channel.ChannelInboundHandlerAdapter; + +public class LinkChatHandler extends ChannelInboundHandlerAdapter { + + @Override + public void channelActive(ChannelHandlerContext ctx) throws Exception { + String context = "hello"; + byte[] contxtByts = context.getBytes(); + int length = contxtByts.length; + ByteBuf byteBuf = ctx.alloc().buffer(); + byteBuf.writeByte(1); + byteBuf.writeShort(3); + byteBuf.writeInt(encodeLength(length)); + byteBuf.writeBytes(contxtByts); + + ctx.writeAndFlush(byteBuf); + } + + private int encodeLength(int length){ + return length << 27 | length >>> 55; + } + + @Override + public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { + System.out.println("channelContext"+ctx); + System.out.println("message"+msg); + } + + @Override + public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception { + System.out.println(cause.getMessage()); + ctx.close().sync(); + } +} diff --git a/netty/src/main/java/com/tison/kong/basic/nio/NettyClientDemo.java b/netty/src/main/java/com/tison/kong/basic/nio/NettyClientDemo.java new file mode 100644 index 0000000..d98b95b --- /dev/null +++ b/netty/src/main/java/com/tison/kong/basic/nio/NettyClientDemo.java @@ -0,0 +1,49 @@ +package com.tison.kong.basic.nio; + +import io.netty.bootstrap.Bootstrap; +import io.netty.channel.Channel; +import io.netty.channel.ChannelFuture; +import io.netty.channel.ChannelInitializer; +import io.netty.channel.ChannelOption; +import io.netty.channel.nio.NioEventLoopGroup; +import io.netty.channel.socket.SocketChannel; +import io.netty.channel.socket.nio.NioSocketChannel; +import io.netty.handler.timeout.IdleStateHandler; + +import java.util.concurrent.TimeUnit; + +public class NettyClientDemo { + + public static void main(String args[]){ + NettyClientDemo clientDemo = new NettyClientDemo(); + clientDemo.createConnection(); + } + + public void createConnection(){ + NioEventLoopGroup eventLoopGroup = new NioEventLoopGroup(); + + Bootstrap bootstrap = new Bootstrap(); + + bootstrap.group(eventLoopGroup) + .channel(NioSocketChannel.class) + .option(ChannelOption.SO_KEEPALIVE, true) + .handler(new ChannelInitializer() { + @Override + protected void initChannel(SocketChannel socketChannel) throws Exception { + socketChannel.pipeline().addLast("IdleState", new IdleStateHandler(5,0,0, TimeUnit.MINUTES)); + socketChannel.pipeline().addLast("Chat", new LinkChatHandler()); + } + }); + + bootstrap.connect("bird-link.pingan.com.cn",16060).addListener(future -> { + Channel channel= ((ChannelFuture)future).channel(); + if(future.isSuccess()){ + System.out.println("connect success"); + // 关闭 + // channel.close(); + }else{ + System.out.println("connect failed"); + } + }); + } +} diff --git a/netty/src/main/java/com/tison/kong/rpc/client/proxy/ObjectProxy.java b/netty/src/main/java/com/tison/kong/rpc/client/proxy/ObjectProxy.java index 382658f..34051c7 100644 --- a/netty/src/main/java/com/tison/kong/rpc/client/proxy/ObjectProxy.java +++ b/netty/src/main/java/com/tison/kong/rpc/client/proxy/ObjectProxy.java @@ -14,7 +14,7 @@ /** * Created by luxiaoxun on 2016-03-16. */ -public class ObjectProxy implements InvocationHandler, IAsyncObjectProxy { +public class ObjectProxy implements InvocationHandler, IAsyncObjectProxy { private static final Logger LOGGER = LoggerFactory.getLogger(ObjectProxy.class); private Class clazz; diff --git a/pom.xml b/pom.xml index 220a874..1a61e2a 100644 --- a/pom.xml +++ b/pom.xml @@ -21,6 +21,7 @@ wiki netty basic + jvm