欢迎您: 游客   等级: 游客 | 注册 | 登陆 |
发 贴
请选择需要发布主题的板块
用户名 密码
欢迎新会员: fotso  
查看
12621
回复
2
jstruggle
级别超级管理员
精华0
积分100
财富100 jstruggle币
发帖数72
注册2009-8-20
状态 我暂时不在线
发表于2010-1-26 09:37 楼主
Tomcat内存溢出的原因

    在生产环境中tomcat内存设置不好很容易出现内存溢出。造成内存原因是不一样的,当然处理方式也不一样。

    这里根据平时遇到的情况和相关资料进行一个总结。常见的一般会有下面三种情况:

    1.OutOfMemoryError: Java heap space

    2.OutOfMemoryError: PermGen space

    3.OutOfMemoryError: unable to create new native thread.

    Tomcat内存溢出解决方案

    对于前两种情况,在应用本身没有内存泄露的情况下可以用设置tomcat jvm参数来解决。(-Xms -Xmx -XX:PermSize  -XX:MaxPermSize)

    最后一种可能需要调整操作系统和tomcat jvm参数同时调整才能达到目的。

    第一种:是堆溢出。

    在JVM中如果98%的时间是用于GC且可用的 Heap size 不足2%的时候将抛出此异常信息。

    没有内存泄露的情况下,调整-Xms -Xmx参数可以解决。

    -Xms:初始堆大小

    -Xmx:最大堆大小

    但堆的大小受下面三方面影响:

    1.相关操作系统的数据模型(32-bt还是64-bit)限制;(32位系统下,一般限制在1.5G~2G;我在2003 server 系统下(物理内存:4G和6G,jdk:1.6)测试 1612M,64为操作系统对内存无限制。)

    2.系统的可用虚拟内存限制;

    3.系统的可用物理内存限制。

    堆的大小可以使用 java -Xmx***M  version 命令来测试。支持的话会出现jdk的版本号,不支持会报错。

    -Xms -Xmx一般配置成一样比较好比如set JAVA_OPTS= -Xms1024m -Xmx1024m

    第二种:永久保存区域溢出

    PermGen space的全称是Permanent Generation space,是指内存的永久保存区域。这一部分用于存放Class和Meta的信息,Class在被 Load的时候被放入PermGen space区域,它和和存放Instance的Heap区域不同,GC(Garbage Collection)不会在主程序运行期对PermGen space进行清理,所以如果你的APP会LOAD很多CLASS的话,就很可能出现PermGen space错误。这种错误常见在web服务器对JSP进行pre compile的时候。但目前的hibernate和spring项目中也很容易出现这样的问题。http://www.javaeye.com/topic/80620?page=1 的帖子有讨论的这个问题。可能是由于这些框架会动态class,而且jvm的gc是不会清理PemGen space的,导致内存溢出。

    这一个一般是加大-XX:PermSize  -XX:MaxPermSize 来解决问题。

    -XX:PermSize 永久保存区域初始大小

    -XX:PermSize 永久保存区域初始最大值

    这一般结合第一条使用,比如 set JAVA_OPTS= -Xms1024m -Xmx1024m  -XX:PermSize=128M -XX:PermSize=256M

    有一点需要注意:java -Xmx***M  version 命令来测试的最大堆内存是 -Xmx与 -XX:PermSize的 和 比如系统支持最大的jvm堆大小事1.5G,那  -Xmx1024m  -XX:PermSize=768M 是无法运行的。

    第三种:无法创建新的线程。

    这种现象比较少见,也比较奇怪,主要是和jvm与系统内存的比例有关。

    这种怪事是因为JVM已经被系统分配了大量的内存(比如1.5G),并且它至少要占用可用内存的一半。有人发现,在线程个数很多的情况下,你分配给JVM的内存越多,那么,上述错误发生的可能性就越大。

    产生这种现象的原因如下(从这个blog中了解到原因:http://hi.baidu.com/hexiong/blog/item/16dc9e518fb10c2542a75b3c.html):

    每一个32位的进程最多可以使用2G的可用内存,因为另外2G被操作系统保留。这里假设使用1.5G给JVM,那么还余下500M可用内存。这500M内存中的一部分必须用于系统dll的加载,那么真正剩下的也许只有400M,现在关键的地方出现了:当你使用Java创建一个线程,在JVM的内存里也会创建一个Thread对象,但是同时也会在操作系统里创建一个真正的物理线程(参考JVM规范),操作系统会在余下的400兆内存里创建这个物理线程,而不是在JVM的1500M的内存堆里创建。在jdk1.4里头,默认的栈大小是256KB,但是在jdk1.5里头,默认的栈大小为1M每线程,因此,在余下400M的可用内存里边我们最多也只能创建400个可用线程。

    这样结论就出来了,要想创建更多的线程,你必须减少分配给JVM的最大内存。还有一种做法是让JVM宿主在你的JNI代码里边。

    给出一个有关能够创建线程的最大个数的估算公式:

    (MaxProcessMemory - JVMMemory - ReservedOsMemory) / (ThreadStackSize) = Number of threads

    对于jdk1.5而言,假设操作系统保留120M内存:

    1.5GB JVM: (2GB-1.5Gb-120MB)/(1MB) = ~380 threads

    1.0GB JVM: (2GB-1.0Gb-120MB)/(1MB) = ~880 threads

    在2000/XP/2003的boot.ini里头有一个启动选项,好像是:/PAE /3G ,可以让用户进程最大内存扩充至3G,这时操作系统只能占用最多1G的虚存。那样应该可以让JVM创建更多的线程。

    因此这种情况需要结合操作系统进行相关调整。

    因此:我们需要结合不同情况对tomcat内存分配进行不同的诊断才能从根本上解决问题。

    以上就是针对Tomcat内存溢出的几种解决方案。本文来自George的博客:《tomcat内存溢出总结》

WWW.8ISP.CN 为您提供专业的JSP虚拟主机!

分享  
king001
级别新手上路
精华0
积分1
财富0 jstruggle币
发帖数0
注册2018-11-16
状态 我暂时不在线
发表于2018-11-16 14:12    1
cc20181117

coach outlet online

ralph lauren outlet online

fitflops sale

coach outlet store online

athletics jerseys

adidas outlet

twins jerseys

uggs outlet store

canada goose coats

reds jerseys

michael kors outlet clearance

adidas ultra boost

ecco outlet

angels jerseys

adidas outlet online

retro 11

fitflops sale clearance

coach bags

adidas outlet online

fred perry polo shirts

ugg outlet

polo ralph lauren outlet online

cheap jordan shoes

nike outlet

cartier watches

michael kors outlet

fitflop sandals

michael kors outlet store

coach outlet online

pandora charms outlet

adidas sneakers

converse outlet

pandora jewelry

coach factory outlet online

new balance outlet

polo ralph lauren outlet

pandora charms

birkenstock sandals

air jordan retro

ronaldo jerseys

coach factory outlet online

uggs outlet

philipp plein

coach outlet

vans outlet

ugg outlet store

ugg outlet

adidas shoes

cheap jordan shoes

cheap air jordans

pandora charms sale clearance

kate spade handbags

nike huarache shoes

pandora charms sale clearance

longchamp

adidas nmd r1

moncler outlet store

cheap nfl jerseys wholesale

cheap air jordans

coach outlet

michael kors handbags

adidas superstar shoes

longchamp outlet

timberland outlet

nike air max 97

nike outlet online

nike outlet store online

rolex replica watches for sale

tiffany and co jewelry

white sox jerseys

louis vuitton handbags

cheap ray ban sunglasses

nfl jerseys

coach factory outlet online

ugg outlet online

kate spade handbags

polo ralph lauren outlet

discount oakley sunglasses

ugg boots outlet

coach outlet store online

nike sneakers

polo outlet store

gucci outlet online

air max outlet

moncler coats

fake rolex

prada shoes

coach factory outlet online

brewers jerseys

coach outlet online

nike free 5.0

coach outlet online

canada goose

kate spade outlet online

nike zoom

canada goose sale

coach outlet online

coach outlet online

salvatore ferragamo

ralph lauren sale clearance uk

philipp plein outlet

mariners jerseys

nike air max 2018

pandora jewelry

red bottoms

nike air max zero

michael kors outlet online

uggs outlet

pirates jerseys

cheap jordans for sale

kate spade outlet online

adidas stan smith

canada goose jacket

ralph lauren outlet online

ugg boots outlet

louboutin outlet

nike outlet store

mets jerseys

ugg outlet

ralph lauren

lebron james shoes

ugg outlet store

michael kors outlet clearance

new balance outlet store

pandora charms sale

air max 1

ugg outlet store

ralph lauren sale clearance uk

cheap jordans free shipping

ralph lauren sale

uggs outlet

adidas nmd r1

burberry outlet store

coach factory outlet online

adidas outlet store

cheap oakley sunglasses

ray ban glasses

fitflops uk

cheap nike shoes

oakley sunglasses outlet

adidas yeezy shoes

cheap air max
cc20181117

zzyytt
级别新手上路
精华0
积分1
财富0 jstruggle币
发帖数0
注册2018-5-11
状态 我暂时不在线
发表于2019-1-3 16:45    2
zzz

yeezy boost 350

birkin bag

coach outlet

lebron 10

adidas nmd

nike air max 270

hermes birkin

valentino shoes

retro jordans

goyard bag

supreme hoodie

coach outlet

michael kors outlet

adidas zx flux

yeezy boost

nike vapormax

adidas nmd

michael kors uk

adidas shoes

christian louboutin

balenciaga

birkin bag

yeezy 700

kd 11

nike jordans

cheap jordans

nike flyknit

nike flyknit racer

nike shox for men

air max 90

yeezy boost 350

nike max

nike sneakers for men

lacoste outlet

adidas nmd

lebron 16 shoes

polo ralph lauren

golden goose

adidas eqt support

adidas tubular shadow

mbt shoes

retro jordans

ysl handbags

hermes outlet online

adidas shoes online

michael kors outlet

nike basketball shoes

fila

tory burch

kd shoes

chrome hearts

jordan 6

adidas gazelle

adidas yeezy

yeezy

tory burch shoes

michael kors handbags outlet

adidas stan smith

yeezy boost 350 v2

yeezy boost

adidas superstar

adidas stan smith sneakers

adidas iniki

golden goose outlet

longchamp outlet

kobe 11

gucci belts

jimmy choo shoes

adidas stan smith

moncler jackets

nike air max

chrome hearts online

off white hoodie

lebron 16

rolex replica

louboutin shoes uk

yeezy boost 350

fila shoes

lebron 16

fila sneakers

yeezys

red bottom shoes

cheap jordans

goyard bag

curry 4

jordan shoes

goyard st louis tot

converse outlet store

fake rolex watches

stephen curry 5

lebron james shoes

kate spade handbags

longchamp

yeezy

nike air max 2017

reebok shoes

curry 5

nike air max 90

moncler outlet

adidas nmd runner

michael kors outlet

kyrie 4

golden goose outlet

michael kors outlet

adidas ultra boost uncaged

yeezy boost 350

adidas yeezy boost

stephen curry 5

canada goose jacket

nike air max 2018

yeezy 500

goyard

adidas ultra boost

off white

michael kors handbags

hogan outlet online

coach outlet sale

timberland boots

calvin klein outlet

nike lebron 16

jordan sneakers

nike hyperdunk

jordans

chrome hearts

moncler jackets

bape hoodie

goyard bags

nike huarache

nmd

kobe sneakers

fila shoes

birkin bag

cheap nba jerseys

lebron shoes

yeezy boost

nike air huarache

nfl jerseys

lacoste polo shirts

off white

yeezy boost

off white x jordan 1

pure boost

ferragamo belt

golden goose outlet

fake rolex

jordan 4

kobe shoes

yeezy boost

adidas pure boost

air yeezy

red bottom heels

off white shoes

fila shoes

kobe 9

yeezy boost 350 v2

michael kors outlet

off white shoes

yeezy shoes

yeezy boost 700

kobe 9

westbrook shoes

ferragamo belt

nike epic react

off white

pandora bracelet

basketball shoes

yeezy

nike react

fila shoes

Kanye West shoes

tory burch sandals

yeezy shoes

michael kors outlet online

nike roshe run

lacoste polo

nike react

hermes handbags

nike air max

fila

golden goose sneakers

michael kors handbags

offwhite

nike kd 11

birkin bag

asics shoes

nike air max

goyard wallet

jordan retro 12

goyard bags

coach outlet sale

crazy explosive

coach factory outlet

lacoste polo

coach outlet

michael kors outlet online

lacoste

adidas superstars

lebron shoes

nike shoes

canada goose

ferragamo belts

nike huarache

jordans

nike polo shirts

yeezy boost 350

yeezy boost 350 v2

100% real jordans for cheap

jordan shoes

hogan outlet

yeezys

balenciaga shoes

hermes handbags

cat boots

off white hoodie

nike polo

yeezy boost 350

balenciaga triple s

tory burch outlet

yeezy shoes

golden goose

valentino

air jordan 4

asics running shoes

nike epic react

james harden shoes

lacoste polo

reebok outlet

vans shoes

jordan 12

hermes handbags for sale

air max 270

nike foamposite

lebron 16 shoes

chrome hearts online

mlb jerseys

ultra boost

yeezy shoes

yeezy boost 350 v2

converse outlet

nike air force 1

air jordan

adidas tubular

jordan 13

adidas yeezy

kd 11 shoes

calvin klein outlet online

chrome hearts online

adidas tubular

hermes belt

kyrie irving shoes

nike sneakers for women

air max 2018

chrome hearts

nfl store

coach handbags

baseball jerseys

harden shoes

adidas outlet online

mbt shoes outlet

kyrie shoes

kd shoes

michael jordan shoes

kyrie 4 shoes

golden goose outlet

air jordans

coach outlet

lebron 15

balenciaga

air max 2019

coach outlet online

off white clothing

adidas nmd r1

kobe basketball shoes

off white jordan 1

ferragamo belts

michael kors factory outlet

michael kors handbags

louboutin shoes

off white clothing

hermes bags

yeezy shoes

golden goose sneakers

yeezy boost 350

hermes online shop

nhl jerseys

paul george shoes

nmd

supreme clothing

yeezy boost 500

goyard

balenciaga sneakers

cheap jordans

michael kors outlet online

nike air max

jordan retro

adidas outlet

moncler jacket

yeezy 500

fila

nike shox

yeezy shoes

cheap jordans

jordan shoes

ysl

yeezy boost 350 v2

vapormax

fitflops sale clearance

curry 4

lacoste online shop

replica rolex

air jordan

golden goose

caterpillar boots

golden goose

golden goose

kd 11

supreme hoodie

adidas eqt

yeezy boost 350

yeezy boost 350 v2

air force 1

links of london

gucci belt

goyard handbags

goyard handbags

nba jerseys

coach outlet online

cheap nfl jerseys

fila

balenciaga

russell westbrook shoes

ralph lauren uk

lebron 11

michael kors handbags

mbt shoes online

adidas ultra

yeezy boost

air jordan 13

kobe 11

jordan 11

lebron 15 shoes

nike air force

michael kors outlet

kyrie 3

fake rolex

off white clothing

coach factory outlet

curry 5

yeezy boost 350

nike roshe

lacoste outlet

adidas crazy explosive

adidas yeezy

air max

links of london outlet store

michael kors

adidas yeezy

michael kors purses

ralph lauren uk

cheap mlb jerseys

michael kors handbags

jordan shoes

adidas shoes outlet

adidas tubular

goyard handbags

iniki

nike sneakers

golden goose sneakers

michael kors

adidas stan smith shoes

lebron 16

curry 4 shoes

hermes belts for men

pandora jewelry

golden goose outlet

timberland outlet

jordan retro 6

yeezy boost

nike air max 2019

hermes belt

bape hoodie

jordan shoes

golden goose

jordans

kobe shoes

red bottoms

kobe byrant shoes

hermes handbags bag

kd shoes

cheap nba jerseys

nike cortez men

fila disruptor

michael kors handbags

jordan 11 retro

hermes belt

longchamp handbags

balenciaga shoes

kd 10

fitflops

yeezy shoes

nike cortez

vans outlet

zx flux

longchamp bags

off white nike

golden goose sneakers

kevin durant shoes

adidas ultra boost

balenciaga shoes

JStruggle BBS

Powered by Jstruggle! 1.8 © 2006-2009

Processed in 0.016s JStruggle BBS Surprise!

粤ICP备05106211号 - 皖ICP备06010590号

copyright©JStruggle工作室版权所有 - 联系我们