tomcat启动产生多个java进程并有defunct现象

我们在日常使用tomcat的时候有时候启动tomcat莫名其妙的就会产生多个java进程,而且这些进程还是有效的。这样会导致端口冲突进而使tomcat假死或者挂掉。有时候强行杀掉进程还会出现defunct现象,导致java进程在好久的时间内无法杀掉。

这个问题进过调查,暂时发现可能与jdk调用的linux内核的LD_ASSUME_KERNEL参数有关。在经过不断在网上查了些资料显示:

首先介绍下LD_ASSUME_KERNEL参数主要跟linux的线程实现方式有关。

那么它到底是怎么一回事了呢?在系统中起到一个什么作用了呢?且往下看:

其实就是一个linux对于线程thread的支持, 就目前的发展而言,有如下三种。

In current Linux implementations, a thread is supported with the Portable Operating System Interface for UNIX (POSIX) compliant library (pthread). Several thread implementations are available in the Linux operating system. The following are the widely used.
1、 LinuxThreads
LinuxThreads have been the default thread implementation since Linux kernel 2.0. The LinuxThread has some noncompliant implementations with the POSIX standard. Native POSIX Thread Library (NPTL) is taking the place of LinuxThreads. The LinuxThreads will not be supported in future release of Enterprise Linux distributions.
2、 Native POSIX Thread Library (NPTL)
The NPTL was originally developed by Red Hat. NPTL is more compliant with POSIX
standards. By taking advantage of enhancements in kernel 2.6 such as the new clone() system call, signal handling implementation, and so on, it has better performance and scalability than LinuxThreads.NPTL has some incompatibility with LinuxThreads. An application which has a dependence on LinuxThread might not work with the NPTL implementation.
3、 Next Generation POSIX Thread (NGPT)
NGPT is an IBM developed version of POSIX thread library. It is currently under
maintenance operation and no further development is planned
.

简单的讲我们下载JDK的时候下载的都是释放包,无论SUN在发布JDK时考虑得如何完美,当时jdk本地库都可能和当前系统的版本号不一致。举个例子,假如System.gc()调用了本地库glic6.0.2.so那么在当前系统上没有这个版本的库或没有这个版本的库的链结,那么gc()方法肯定不能正确工作。当然sun在发布的时候可能会把这个本地库打包在JDK发行包中,但glic6.0.2.so中又调用了其它库,如subglic6.0.21.so,即使系统中存在完全相同的glic6.0.2.so,它调用的库又不一定完全匹配,才使得需要调用本地库的JVM底层功可能会产生异常,导致清除/退出进程等工作就可能无法完成,产生了java defunct,甚至有些时候还会出现tomcat产生多进程的情况

修改方案:强行设置LD_ASSUME_KERNEL参数与当前系统的参数保持一致

首先查看当前linux版本

uname -r

编辑配置文件

vi /etc/profile

添加参数

export LD_ASSUME_KERNEL=2.6.32



你可能感兴趣的:(java,系统架构)