개요

Java Platform에서의 Stack추적은, 개발자 관리/운영자로 하여금, JVM Thread Monitor 대한 확실한 정보를 분석할 있는 수단으로 이용되고 있다.

문서에서는, major vendor 3개의 JVM 대하여 Thread State 중심으로, 차이점을

예제와 함께 다뤄보고자 한다.

(, JEUS 같이 Web Application Server 운영되는 JVM 대한 Dump Stack분석을 주로 설명할 것이다.)

 
환경

OS

Version

JDK Version

JEUS

SunOS

5.10 (64bit)

1.5.0_14

6.0

HP-UX

11.23 (64bit)

1.5.0.11

6.0

AIX

5.3 (64bit)

J2RE 1.5.0 SR6b / J2RE 1.4.2 SR5

6.0

 
Thread State

JVM Thread Dump상에서, 다시 말해 WAS등의 Multi Threading환경에서의 Thread Dump 정보에서, 각각의 Thread들은 다양한 상태(State)’ 가지고 있다.

물론, JVM 버전이라 던지, 내부적인 알고리즘에 의하여, 모든 플랫폼에 대하여 공통적으로 동일하게 나타나지는 않지만, 고유의 상태표시법을 가지고 있다.

 

아래는, 표준 JVM이라 있는 Sun JDK Thread State 분류이다.
(
이는, HP-UX / Linux / Windows 플랫폼에서 거의 같은 형식일 것이다.)

State

의미

R

Running or runnable thread

S

Suspended thread

CW

Thread waiting on a condition variable

MW

Thread waiting on a monitor lock

MS

Thread suspended waiting on a monitor lock

 

AIX JDK 경우, 크게 아래와 같은 분류를 가진다. (주의 : JDK버전에 따라 차이가 있을 있음)

보면 있듯이, 크게 ‘Thread 실행중 인지 아닌지 관점에서 분류되었다.

(* the thread is currently runnable or not)

State

의미

R

The thread is runnable

CW

Conditioned wait

MW

MUxSemWait

 

그러나, 아래 예제에서도 있겠지만, Vendor JDK 버전에 따라서 Thread State 상당히 차이를 보이는 점을 있을 것이다. 차이점을 비교해 보는 것을 중심으로 예제를 진행한다.

 

Thread Dump 생성

JVM Thread Stack 추적하는 방법에는 크게 3가지가 있는데, 여기서는 첫번째 방법인 외부Signal 형식을 살펴볼 것이다.

JVM에는 Signal Handler 내장되어 있으며, 특히 외부로부터 특정 QUIT 받았을 경우,

당시의 Thread, Monitor 정보를 재귀적으로 남기도록 프로그래밍 되어 있다.

형식) kill –Quit PID
        -.
여기서 PID Thread Dump 남기고자 하는 Process PID이다
.
           JEUS
경우, 일반적으로 Container 프로세스의 PID 사용한다.

) kill -3 1234

여기서 말하는 Quit 시그널은, 통상적으로 ANSI, POSIX 거의 모든 계열에서 ‘3’ 의미한다.

참고로, 플랫폼이 제공하는 Signal Table ‘kill –l’ 명령으로 조회해볼 있다.

Thread State 예제

Thread 상태 예제를, Sun JDK 기준으로 살펴보고, 기타 플랫폼도 같이 알아보도록 한다.

살펴볼 Thread 상태는 아래와 같다.

l          Running Monitor Wait

l          Condition Wait

그리고, 추가적으로 multi-threading 환경에서 문제가 있는 아래의 상황도 살펴볼 것이다.

l          Dead Lock

Running / Monitor Wait 상태

모든 객체는 Monitor 가지고 있고, 동기화가 필요한 경우 Thread 해당 Monitor Lock 있다. multi-threading 환경에서 경우, Monitor 선점한 Thread 동기화 블록을 벗어나기 전까지, Locked 객체를 사용하고자 하는 다른 Thread들은 동기화가 시작되는 부분에서 (Monitor cache lock)’ 들어가고, 상태가 MW(Monitor wait) 변하게 된다.

 


[사용된 코드 : thread-mw.jsp]

코드 설명 : 첫번째 Thread 동기화 블록에서, object 객체에 대한 Lock 걸고, 블록 안으로 들어가서, 일정기간 대기하게 된다( 15). 첫번째 Thread 동기화 블록을 빠져 나오기 전에, 두번째, 세번째 Thread 수행시키면, Thread object객체에 대한 Monitor 기다리면서, Monitor cache 들어가게 된다.

<%@ page language="java" contentType="text/html; charset=EUC-KR" pageEncoding="EUC-KR"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=EUC-KR">

<title>thread-mw.jsp</title>

</head>

<body>

<%!

        public static Object object = new Object();

%>

<%

        synchronized (object) {

                for (long i = 0; i < 10000000000L; i++) {

                }

                out.println("-- Finish --");

        }

%>

</body>

</html>

 

[SunOS]

l          Thread 실행 순서 : w2 à w1 à w0

l          Dump 내용

"http1-w2 [container1-15]" prio=10 tid=0x000000010140f2c0 nid=0x3b runnable [0xffffffff578fe000..0xffffffff578ff92
8]     at jeus_jspwork._600_thead_5fmw_5fjsp._jspService(_600_thead_5fmw_5fjsp.java:65)
        - waiting to lock <0xffffffff7238ca98> (a java.lang.Object)
        at jeus.servlet.jsp2.runtime.HttpJspBase.service(HttpJspBase.java:106)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:818)
        at jeus.servlet.jsp.JspServletWrapper.executeServlet(JspServletWrapper.java:94)
        at jeus.servlet.servlets.JspServlet.execute(JspServlet.java:359)
        at jeus.servlet.engine.HttpRequestProcessor.run(HttpRequestProcessor.java:265)

"http1-w0 [container1-13]" prio=10 tid=0x0000000101196f40 nid=0x39 waiting for monitor entry [0xffffffff57cfe000..
0xffffffff57cff828]
        at jeus_jspwork._600_thead_5fmw_5fjsp._jspService(_600_thead_5fmw_5fjsp.java:65)
        - waiting to lock <0xffffffff7238ca98> (a java.lang.Object)
        at jeus.servlet.jsp2.runtime.HttpJspBase.service(HttpJspBase.java:106)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:818)
        at jeus.servlet.jsp.JspServletWrapper.executeServlet(JspServletWrapper.java:94)
        at jeus.servlet.engine.ServletWrapper.execute(ServletWrapper.java:220)
        at jeus.servlet.jsp.JspServletWrapper.execute(JspServletWrapper.java:139)
        at jeus.servlet.engine.HttpRequestProcessor.run(HttpRequestProcessor.java:265)

"http1-w1 [container1-16]" prio=10 tid=0x0000000100aa7680 nid=0x3a waiting for monitor entry [0xffffffff57afe000..
0xffffffff57aff8a8]
        at jeus_jspwork._600_thead_5fmw_5fjsp._jspService(_600_thead_5fmw_5fjsp.java:64)
        - waiting to lock <0xffffffff7238ca98> (a java.lang.Object)
        at jeus.servlet.jsp2.runtime.HttpJspBase.service(HttpJspBase.java:106)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:818)
        at jeus.servlet.jsp.JspServletWrapper.executeServlet(JspServletWrapper.java:94)
        at jeus.servlet.engine.ServletWrapper.execute(ServletWrapper.java:220)
        at jeus.servlet.jsp.JspServletWrapper.execute(JspServletWrapper.java:139)
        at jeus.servlet.engine.HttpRequestProcessor.run(HttpRequestProcessor.java:265)

결과 설명 : w2 Thread 동기화 블럭에 진입하여 for문을 수행중이기 때문에, ‘runnable’으로 표시되고, w1 w0 Thread 동기화 블록 진입을 위하여, object 객체의 Lock 해제되기를 기다리면서, Monitor cache 들어가고 ‘waiting for monitor entry’ 표시된다.

 

 

[HP-UX]

l          Thread 실행 순서 : w2 à w0 à w1

l          Dump 내용

"http1-w2 [container1-15]" prio=10 tid=60000000024ffc40 nid=60 lwp_id=1583373 runnable [9fffffff786ff000..9fffffff
78700a40]
        at jeus_jspwork._600_thread_5fmw_5fjsp._jspService(_600_thread_5fmw_5fjsp.java:65)
        - waiting to lock <9fffffffb87909d0> (a java.lang.Object)
        at jeus.servlet.jsp2.runtime.HttpJspBase.service(HttpJspBase.java:106)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:818)
        at jeus.servlet.jsp.JspServletWrapper.executeServlet(JspServletWrapper.java:94)
        at jeus.servlet.servlets.JspServlet.execute(JspServlet.java:359)
        at jeus.servlet.engine.HttpRequestProcessor.run(HttpRequestProcessor.java:265)

"http1-w1 [container1-16]" prio=10 tid=60000000024bc480 nid=59 lwp_id=1583372 waiting for monitor entry [9fffffff7
8900000..9fffffff78900ac0]
        at jeus_jspwork._600_thread_5fmw_5fjsp._jspService(_600_thread_5fmw_5fjsp.java:64)
        - waiting to lock <9fffffffb87909d0> (a java.lang.Object)
        at jeus.servlet.jsp2.runtime.HttpJspBase.service(HttpJspBase.java:106)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:818)
        at jeus.servlet.jsp.JspServletWrapper.executeServlet(JspServletWrapper.java:94)
        at jeus.servlet.engine.ServletWrapper.execute(ServletWrapper.java:220)
        at jeus.servlet.jsp.JspServletWrapper.execute(JspServletWrapper.java:139)
        at jeus.servlet.engine.HttpRequestProcessor.run(HttpRequestProcessor.java:265)

"http1-w0 [container1-13]" prio=10 tid=60000000024b6180 nid=58 lwp_id=1583371 waiting for monitor entry [9fffffff7
8b00000..9fffffff78b00d40]
        at jeus_jspwork._600_thread_5fmw_5fjsp._jspService(_600_thread_5fmw_5fjsp.java:64)
        - waiting to lock <9fffffffb87909d0> (a java.lang.Object)
        at jeus.servlet.jsp2.runtime.HttpJspBase.service(HttpJspBase.java:106)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:818)
        at jeus.servlet.jsp.JspServletWrapper.executeServlet(JspServletWrapper.java:94)
        at jeus.servlet.engine.ServletWrapper.execute(ServletWrapper.java:220)
        at jeus.servlet.jsp.JspServletWrapper.execute(JspServletWrapper.java:139)
        at jeus.servlet.engine.HttpRequestProcessor.run(HttpRequestProcessor.java:265)

결과 설명 : 동기화 블록 진입 순서대로, w2 ‘runnable’으로 표시되고, w0 w1 Thread ‘waiting for monitor entry’ 표시된다. 이는 SunOS 플랫폼에서와 마찬가지로 HotSpot계열의 JVM 사용하기 때문에 매우 유사하다.

 

[AIX / JDK 1.5]

l          Thread 실행 순서 : w2 à w1 à w0

l          Dump 내용

3XMTHREADINFO      "http1-w0" (TID:0x0000000114948E00, sys_thread_t:0x00000001146DE4D0, state:B, native ID:0x00000000000D00E7) prio=5
4XESTACKTRACE          at jeus_jspwork/_600_thread_5fmw_5fjsp._jspService(_600_thread_5fmw_5fjsp.java:63(Compiled Code))
4XESTACKTRACE          at jeus/servlet/jsp2/runtime/HttpJspBase.service(HttpJspBase.java:106)
4XESTACKTRACE          at javax/servlet/http/HttpServlet.service(HttpServlet.java:818)
4XESTACKTRACE          at jeus/servlet/jsp/JspServletWrapper.executeServlet(JspServletWrapper.java:94)
4XESTACKTRACE          at jeus/servlet/engine/ServletWrapper.execute(ServletWrapper.java:220)
4XESTACKTRACE          at jeus/servlet/jsp/JspServletWrapper.execute(JspServletWrapper.java:139)
4XESTACKTRACE          at jeus/servlet/engine/HttpRequestProcessor.run(HttpRequestProcessor.java:265)
3XMTHREADINFO      "http1-w1" (TID:0x0000000114A91900, sys_thread_t:0x00000001149E9F70, state:B, native ID:0x00000000001AA06F) prio=5
4XESTACKTRACE          at jeus_jspwork/_600_thread_5fmw_5fjsp._jspService(_600_thread_5fmw_5fjsp.java:63)
4XESTACKTRACE          at jeus/servlet/jsp2/runtime/HttpJspBase.service(HttpJspBase.java:106)
4XESTACKTRACE          at javax/servlet/http/HttpServlet.service(HttpServlet.java:818)
4XESTACKTRACE          at jeus/servlet/jsp/JspServletWrapper.executeServlet(JspServletWrapper.java:94)
4XESTACKTRACE          at jeus/servlet/engine/ServletWrapper.execute(ServletWrapper.java:220)
4XESTACKTRACE          at jeus/servlet/jsp/JspServletWrapper.execute(JspServletWrapper.java:139)
4XESTACKTRACE          at jeus/servlet/engine/HttpRequestProcessor.run(HttpRequestProcessor.java:265)
3XMTHREADINFO      "http1-w2" (TID:0x0000000114CC6000, sys_thread_t:0x00000001149EA450, state:CW, native ID:0x00000000001460CB) prio=5
4XESTACKTRACE          at jeus_jspwork/_600_thread_5fmw_5fjsp._jspService(_600_thread_5fmw_5fjsp.java:64)
4XESTACKTRACE          at jeus/servlet/jsp2/runtime/HttpJspBase.service(HttpJspBase.java:106)
4XESTACKTRACE          at javax/servlet/http/HttpServlet.service(HttpServlet.java:818)
4XESTACKTRACE          at jeus/servlet/jsp/JspServletWrapper.executeServlet(JspServletWrapper.java:94)
4XESTACKTRACE          at jeus/servlet/servlets/JspServlet.execute(JspServlet.java:359)
4XESTACKTRACE          at jeus/servlet/engine/HttpRequestProcessor.run(HttpRequestProcessor.java:265)

결과 설명 : 첫번째 Thread w2 동기화 블록 진입 ‘state:CW’상태가 되었고, w1 w0 Monitor 대한 Lock 기다리면서 ‘state:B’ 변하는 것을 있다.

 

[AIX / JDK 1.4]

l          Thread 실행 순서 : w1 à w2 à w0

l          Dump 내용

3XMTHREADINFO      "http1-w2" (TID:0x3031E040, sys_thread_t:0x387295A8, state:CW, native ID:0x393C) prio=5
4XESTACKTRACE          at jeus_jspwork._500_thread_5fmw_5fjsp._jspService(_500_thread_5fmw_5fjsp.java(Compiled Code))
4XESTACKTRACE          at jeus.servlet.jsp.HttpJspBase.service(HttpJspBase.java:53)
4XESTACKTRACE          at javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
4XESTACKTRACE          at jeus.servlet.jsp.JspServletWrapper.executeServlet(JspServletWrapper.java:94)
4XESTACKTRACE          at jeus.servlet.engine.ServletWrapper.execute(ServletWrapper.java:213)
4XESTACKTRACE          at jeus.servlet.jsp.JspServletWrapper.execute(JspServletWrapper.java:140)
4XESTACKTRACE          at jeus.servlet.engine.HttpRequestProcessor.run(HttpRequestProcessor.java:251)
3XHNATIVESTACK       Native Stack
NULL                 ------------
3XHSTACKLINE         at 0x38EC9E24 in
3XHSTACKLINE         at 0xD012316C in _event_wait
3XHSTACKLINE         at 0xD012E9DC in _cond_wait_local
3XHSTACKLINE         at 0xD012EEB0 in _cond_wait
3XHSTACKLINE         at 0xD012F874 in pthread_cond_timedwait
3XHSTACKLINE         at 0xD22A6A10 in condvarTimedWaitUpTo248Days
3XHSTACKLINE         at 0xD22A6BA0 in condvarTimedWait
3XHSTACKLINE         at 0xD22A5988 in sysMonitorWait
3XHSTACKLINE         at 0xD21604F4 in lkMonitorEnter
3XHSTACKLINE         at 0xD2318F08 in _jit_monitorEnterQuicker
3XHSTACKLINE         at 0xD2509220 in JITSigSegvHandler
3XHSTACKLINE         at 0x353396E4 in
3XHSTACKLINE         at 0x353396E4 in
3XMTHREADINFO      "http1-w1" (TID:0x3031E150, sys_thread_t:0x38726F28, state:R, native ID:0x383B) prio=5
4XESTACKTRACE          at jeus_jspwork._500_thread_5fmw_5fjsp._jspService(_500_thread_5fmw_5fjsp.java(Compiled Code))
4XESTACKTRACE          at jeus.servlet.jsp.HttpJspBase.service(HttpJspBase.java:53)
4XESTACKTRACE          at javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
4XESTACKTRACE          at jeus.servlet.jsp.JspServletWrapper.executeServlet(JspServletWrapper.java:94)
4XESTACKTRACE          at jeus.servlet.servlets.JspServlet.execute(JspServlet.java:359)
4XESTACKTRACE          at jeus.servlet.engine.HttpRequestProcessor.run(HttpRequestProcessor.java:251)
3XHNATIVESTACK       Native Stack
NULL                 ------------
3XHSTACKLINE         at 0x38E45390 in
3XMTHREADINFO      "http1-w0 [container1-13]" (TID:0x3031BDD0, sys_thread_t:0x38726928, state:CW, native ID:0x373A) prio=5
4XESTACKTRACE          at jeus_jspwork._500_thread_5fmw_5fjsp._jspService(_500_thread_5fmw_5fjsp.java(Compiled Code))
4XESTACKTRACE          at jeus.servlet.jsp.HttpJspBase.service(HttpJspBase.java:53)
4XESTACKTRACE          at javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
4XESTACKTRACE          at jeus.servlet.jsp.JspServletWrapper.executeServlet(JspServletWrapper.java:94)
4XESTACKTRACE          at jeus.servlet.engine.ServletWrapper.execute(ServletWrapper.java:213)
4XESTACKTRACE          at jeus.servlet.jsp.JspServletWrapper.execute(JspServletWrapper.java:140)
4XESTACKTRACE          at jeus.servlet.engine.HttpRequestProcessor.run(HttpRequestProcessor.java:251)
3XHNATIVESTACK       Native Stack
NULL                 ------------
3XHSTACKLINE         at 0x38D43804 in
3XHSTACKLINE         at 0xD012316C in _event_wait
3XHSTACKLINE         at 0xD012E9DC in _cond_wait_local
3XHSTACKLINE         at 0xD012EEB0 in _cond_wait
3XHSTACKLINE         at 0xD012F874 in pthread_cond_timedwait
3XHSTACKLINE         at 0xD22A6A10 in condvarTimedWaitUpTo248Days
3XHSTACKLINE         at 0xD22A6BA0 in condvarTimedWait
3XHSTACKLINE         at 0xD22A5988 in sysMonitorWait
3XHSTACKLINE         at 0xD21604F4 in lkMonitorEnter
3XHSTACKLINE         at 0xD2318F08 in _jit_monitorEnterQuicker
3XHSTACKLINE         at 0xD2509220 in JITSigSegvHandler
3XHSTACKLINE         at 0x353396E4 in
3XHSTACKLINE         at 0x353396E4 in

결과 설명 : 첫번째 Thread w1 동기화 블록 진입 ‘state:R’상태가 되었고, w2 w0 Monitor 대한 Lock 기다리면서, ‘state:CW’ 변하였다.


Condition Wait 상태

조건대기상태로도 표현되는 CW, 흔히 Thread 동기화 블록 안에 있거나, 혹은 Thread.sleep, object.wait()상태에 머물면서 event 기다리는 상황에서 감지가 된다.

여기서 주의할 점은, wait()상태에 머물던 Thread notify계열의 event 전달 받았다고 해도,

다른 Thread들은, Thread 동기화 블록을 떠나기 전까지는, 객체 Monitor Lock 획득 없다는 점이다.

 

[사용된 코드 : thread-cw.jsp]

코드설명 : 첫번째 Thread if조건에 의해, object 객체에 Lock 걸음과 동시에, 동기화 블록에 진입하게 되고, wait상태로 빠지게 되며, 이벤트를 대기하는 상태가 된다. 그와 동시에 동기화 블록에 대한 Lock 해제되게 된다. 이후 두번째 Thread역시 if조건에 의해 동기화 블록에 진입하고, object객체가 깨어나기를 대기하고 있는 상태가 된다. 세번째 Thread else루틴을 지나, finally절에 진입하고, 15 이후 object 객체에 대해 notifyAll() 이벤트를 전송한다.

<%@ page language="java" contentType="text/html; charset=EUC-KR"

        pageEncoding="EUC-KR"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTL 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=EUC-KR">

<title>thread-cw.jsp</title>

</head>

<body>

<%!

        public static Object object = new Object();

        public static int count = 0;

%>

<%

        try {

                if (count <= 1) {

                        synchronized (object) {

                        count++;

                        object.wait(100000);

                        }

                } else {

                }

        } catch (Exception e) {

                e.printStackTrace();

        } finally {

                for (long i = 0; i < 10000000000L; i++) {

                }

                object.notifyAll();

                out.println("-- Finish --");

        }

%>

</body>

</html>

 

 

[SunOS]

l          Thread 실행 순서 : w0 à w1 à w2

l          Dump 내용

"http1-w2" prio=10 tid=0x000000010140f2c0 nid=0x3b runnable [0xffffffff578fe000..0xffffffff578ff928]
        at jeus_jspwork._600_thread_5fcw_5fjsp._jspService(_600_thread_5fcw_5fjsp.java:76)
        at jeus.servlet.jsp2.runtime.HttpJspBase.service(HttpJspBase.java:106)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:818)
        at jeus.servlet.jsp.JspServletWrapper.executeServlet(JspServletWrapper.java:94)
        at jeus.servlet.engine.ServletWrapper.execute(ServletWrapper.java:220)
        at jeus.servlet.jsp.JspServletWrapper.execute(JspServletWrapper.java:139)
        at jeus.servlet.engine.HttpRequestProcessor.run(HttpRequestProcessor.java:265)

"http1-w1" prio=10 tid=0x0000000100aa7680 nid=0x3a in Object.wait() [0xffffffff57afe000..0xffffffff57aff8a8]
        at java.lang.Object.wait(Native Method)
        - waiting on <0xffffffff7211db78> (a java.lang.Object)
        at jeus_jspwork._600_thread_5fcw_5fjsp._jspService(_600_thread_5fcw_5fjsp.java:69)
        - locked <0xffffffff7211db78> (a java.lang.Object)
        at jeus.servlet.jsp2.runtime.HttpJspBase.service(HttpJspBase.java:106)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:818)
        at jeus.servlet.jsp.JspServletWrapper.executeServlet(JspServletWrapper.java:94)
        at jeus.servlet.engine.ServletWrapper.execute(ServletWrapper.java:220)
        at jeus.servlet.jsp.JspServletWrapper.execute(JspServletWrapper.java:139)
        at jeus.servlet.engine.HttpRequestProcessor.run(HttpRequestProcessor.java:265)

"http1-w0 [container1-13]" prio=10 tid=0x0000000101196f40 nid=0x39 in Object.wait() [0xffffffff57cfe000..0xfffffff
f57cff828]
        at java.lang.Object.wait(Native Method)
        - waiting on <0xffffffff7211db78> (a java.lang.Object)
        at jeus_jspwork._600_thread_5fcw_5fjsp._jspService(_600_thread_5fcw_5fjsp.java:69)
        - locked <0xffffffff7211db78> (a java.lang.Object)
        at jeus.servlet.jsp2.runtime.HttpJspBase.service(HttpJspBase.java:106)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:818)
        at jeus.servlet.jsp.JspServletWrapper.executeServlet(JspServletWrapper.java:94)
        at jeus.servlet.servlets.JspServlet.execute(JspServlet.java:359)
        at jeus.servlet.engine.HttpRequestProcessor.run(HttpRequestProcessor.java:265)

결과 설명 : 첫번째 Thread w0 동기화 블록 진입 , object 오브젝트에 대해 wait 메서드를 호출 하면서 Object.wait()상태가 되었고, w1 뒤따라 동기화 블록에 진입하면서, object 오브젝트가 notify되기를 기다리면서 Object.wait()상태가 되었고, w2 Thread else절을 지나, finally절에 진입하여 for문을 수행 중이기 때문에, ‘runnable’ 나타나고 있다.

 

[HP-UX]

l          Thread 실행 순서 : w0 à w1 à w2

l          Dump 내용

"http1-w2" prio=3 tid=60000000024ffc40 nid=60 lwp_id=1583373 runnable [9fffffff786ff000..9fffffff78700a40]
        at jeus_jspwork._600_thread_5fcw_5fjsp._jspService(_600_thread_5fcw_5fjsp.java:76)
        at jeus.servlet.jsp2.runtime.HttpJspBase.service(HttpJspBase.java:106)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:818)
        at jeus.servlet.jsp.JspServletWrapper.executeServlet(JspServletWrapper.java:94)
        at jeus.servlet.engine.ServletWrapper.execute(ServletWrapper.java:220)
        at jeus.servlet.jsp.JspServletWrapper.execute(JspServletWrapper.java:139)
        at jeus.servlet.engine.HttpRequestProcessor.run(HttpRequestProcessor.java:265)

"http1-w1" prio=10 tid=60000000024bc480 nid=59 lwp_id=1583372 in Object.wait() [9fffffff78900000..9fffffff78900ac0
]
        at java.lang.Object.wait(Native Method)
        - waiting on <9fffffffb86c5a20> (a java.lang.Object)
        at jeus_jspwork._600_thread_5fcw_5fjsp._jspService(_600_thread_5fcw_5fjsp.java:69)
        - locked <9fffffffb86c5a20> (a java.lang.Object)
        at jeus.servlet.jsp2.runtime.HttpJspBase.service(HttpJspBase.java:106)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:818)
        at jeus.servlet.jsp.JspServletWrapper.executeServlet(JspServletWrapper.java:94)
        at jeus.servlet.engine.ServletWrapper.execute(ServletWrapper.java:220)
        at jeus.servlet.jsp.JspServletWrapper.execute(JspServletWrapper.java:139)
        at jeus.servlet.engine.HttpRequestProcessor.run(HttpRequestProcessor.java:265)

"http1-w0 [container1-13]" prio=10 tid=60000000024b6180 nid=58 lwp_id=1583371 in Object.wait() [9fffffff78b00000..
9fffffff78b00d40]
        at java.lang.Object.wait(Native Method)
        - waiting on <9fffffffb86c5a20> (a java.lang.Object)
        at jeus_jspwork._600_thread_5fcw_5fjsp._jspService(_600_thread_5fcw_5fjsp.java:69)
        - locked <9fffffffb86c5a20> (a java.lang.Object)
        at jeus.servlet.jsp2.runtime.HttpJspBase.service(HttpJspBase.java:106)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:818)
        at jeus.servlet.jsp.JspServletWrapper.executeServlet(JspServletWrapper.java:94)
        at jeus.servlet.servlets.JspServlet.execute(JspServlet.java:359)
        at jeus.servlet.engine.HttpRequestProcessor.run(HttpRequestProcessor.java:265)

결과 설명 : 역시 SunOS플랫폼의 결과와 유사하게 나타난다.

 

[AIX / JDK 1.5]

l          Thread 실행 순서 : w2 à w1 à w0

l          Dump 내용

3XMTHREADINFO      "http1-w0 [container1-15]" (TID:0x0000000114B88000, sys_thread_t:0x00000001147E06D0, state:CW, native ID:0x000000
00003230B3) prio=5
4XESTACKTRACE          at jeus_jspwork/_600_thread_5fcw_5fjsp._jspService(_600_thread_5fcw_5fjsp.java:75)
4XESTACKTRACE          at jeus/servlet/jsp2/runtime/HttpJspBase.service(HttpJspBase.java:1 06)
4XESTACKTRACE          at javax/servlet/http/HttpServlet.service(HttpServlet.java:818)
4XESTACKTRACE          at jeus/servlet/jsp/JspServletWrapper.executeServlet(JspServletWrapper.java:94)
4XESTACKTRACE          at jeus/servlet/engine/ServletWrapper.execute(ServletWrapper.java:220)
4XESTACKTRACE          at jeus/servlet/jsp/JspServletWrapper.execute(JspServletWrapper.java:139)
4XESTACKTRACE          at jeus/servlet/engine/HttpRequestProcessor.run(HttpRequestProcessor.java:265)
3XMTHREADINFO      "http1-w1 [container1-14]" (TID:0x0000000114C76E00, sys_thread_t:0x0000000114B88F30, state:CW, native ID:0x000000
00003DD0E7) prio=5
4XESTACKTRACE          at java/lang/Object.wait(Native Method)
4XESTACKTRACE          at java/lang/Object.wait(Object.java:231)

4XESTACKTRACE          at jeus_jspwork/_600_thread_5fcw_5fjsp._jspService(_600_thread_5fcw_5fjsp.java:68)
4XESTACKTRACE          at jeus/servlet/jsp2/runtime/HttpJspBase.service(HttpJspBase.java:106)
4XESTACKTRACE          at javax/servlet/http/HttpServlet.service(HttpServlet.java:818)
4XESTACKTRACE          at jeus/servlet/jsp/JspServletWrapper.executeServlet(JspServletWrapper.java:94)
4XESTACKTRACE          at jeus/servlet/engine/ServletWrapper.execute(ServletWrapper.java:220)
4XESTACKTRACE          at jeus/servlet/jsp/JspServletWrapper.execute(JspServletWrapper.java:139)
4XESTACKTRACE          at jeus/servlet/engine/HttpRequestProcessor.run(HttpRequestProcessor.java:265)
3XMTHREADINFO      "http1-w2 [container1-13]" (TID:0x0000000114C7B600, sys_thread_t:0x0000000114B89410, state:CW, native ID:0x000000
00003E00DB) prio=5
4XESTACKTRACE          at java/lang/Object.wait(Native Method)
4XESTACKTRACE          at java/lang/Object.wait(Object.java:231)

4XESTACKTRACE          at jeus_jspwork/_600_thread_5fcw_5fjsp._jspService(_600_thread_5fcw_5fjsp.java:68)
4XESTACKTRACE          at jeus/servlet/jsp2/runtime/HttpJspBase.service(HttpJspBase.java:106)
4XESTACKTRACE          at javax/servlet/http/HttpServlet.service(HttpServlet.java:818)
4XESTACKTRACE          at jeus/servlet/jsp/JspServletWrapper.executeServlet(JspServletWrapper.java:94)
4XESTACKTRACE          at jeus/servlet/servlets/JspServlet.execute(JspServlet.java:359)
4XESTACKTRACE          at jeus/servlet/engine/HttpRequestProcessor.run(HttpRequestProcessor.java:265)

결과 설명 : 첫번째와 두번째, 세번째 Thread 모두 ‘state:CW’ 나타나는 것을 있다.

하지만, w2 w1 Stack 보면, Object.wait 상태로 w0 차이가 있는 것을 있다.


[AIX / JDK 1.4]

l          Thread 실행 순서 : w1 à w2 à w0

l          Dump 내용

3XMTHREADINFO      "http1-w2 [container1-17]" (TID:0x3031E040, sys_thread_t:0x387295A8, state:CW, native ID:0x393C) prio=5

4XESTACKTRACE          at java.lang.Object.wait(Native Method)

4XESTACKTRACE          at jeus_jspwork._500_thread_5fcw_5fjsp._jspService(_500_thread_5fcw_5fjsp.java:52)

4XESTACKTRACE          at jeus.servlet.jsp.HttpJspBase.service(HttpJspBase.java:53)

4XESTACKTRACE          at javax.servlet.http.HttpServlet.service(HttpServlet.java:856)

4XESTACKTRACE          at jeus.servlet.jsp.JspServletWrapper.executeServlet(JspServletWrapper.java:94)

4XESTACKTRACE          at jeus.servlet.engine.ServletWrapper.execute(ServletWrapper.java:213)

4XESTACKTRACE          at jeus.servlet.jsp.JspServletWrapper.execute(JspServletWrapper.java:140)

4XESTACKTRACE          at jeus.servlet.engine.HttpRequestProcessor.run(HttpRequestProcessor.java:251)

3XHNATIVESTACK       Native Stack

NULL                 ------------

3XHSTACKLINE         at 0xD012316C in _event_wait

3XHSTACKLINE         at 0xD012E9DC in _cond_wait_local

3XHSTACKLINE         at 0xD012EEB0 in _cond_wait

3XHSTACKLINE         at 0xD012F874 in pthread_cond_timedwait

3XHSTACKLINE         at 0xD22A6A10 in condvarTimedWaitUpTo248Days

3XHSTACKLINE         at 0xD22A6BA0 in condvarTimedWait

3XHSTACKLINE         at 0xD22A5988 in sysMonitorWait

3XHSTACKLINE         at 0xD215E57C in lkMonitorWait

3XHSTACKLINE         at 0xD20E1518 in JVM_MonitorWait

3XHSTACKLINE         at 0xD2086958 in

3XHSTACKLINE         at 0xD2116074 in sysInvokeNative

3XHSTACKLINE         at 0xD210D938 in mmipInvokeJniMethod

3XHSTACKLINE         at 0xD20EB708 in mmipExecuteJava

3XHSTACKLINE         at 0xD20E3334 in xeRunJavaVarArgMethod

3XHSTACKLINE         at 0xD20E35C8 in xeRunDynamicMethod

3XHSTACKLINE         at 0xD20D06D4 in threadRT0

3XHSTACKLINE         at 0xD216380C in xmExecuteThread

3XHSTACKLINE         at 0xD2167CAC in threadStart

3XHSTACKLINE         at 0xD229EE50 in _start

3XHSTACKLINE         at 0xD011167C in _pthread_body

3XHSTACKLINE         at 0xD011167C in _pthread_body

3XMTHREADINFO      "http1-w1 [container1-16]" (TID:0x3031E150, sys_thread_t:0x38726F28, state:CW, native ID:0x383B) prio=5

4XESTACKTRACE          at java.lang.Object.wait(Native Method)

4XESTACKTRACE          at jeus_jspwork._500_thread_5fcw_5fjsp._jspService(_500_thread_5fcw_5fjsp.java:52)

4XESTACKTRACE          at jeus.servlet.jsp.HttpJspBase.service(HttpJspBase.java:53)

4XESTACKTRACE          at javax.servlet.http.HttpServlet.service(HttpServlet.java:856)

4XESTACKTRACE          at jeus.servlet.jsp.JspServletWrapper.executeServlet(JspServletWrapper.java:94)

4XESTACKTRACE          at jeus.servlet.servlets.JspServlet.execute(JspServlet.java:359)

4XESTACKTRACE          at jeus.servlet.engine.HttpRequestProcessor.run(HttpRequestProcessor.java:251)

3XHNATIVESTACK       Native Stack

NULL                 ------------

3XHSTACKLINE         at 0xD012316C in _event_wait

3XHSTACKLINE         at 0xD012E9DC in _cond_wait_local

3XHSTACKLINE         at 0xD012EEB0 in _cond_wait

3XHSTACKLINE         at 0xD012F874 in pthread_cond_timedwait

3XHSTACKLINE         at 0xD22A6A10 in condvarTimedWaitUpTo248Days

3XHSTACKLINE         at 0xD22A6BA0 in condvarTimedWait

3XHSTACKLINE         at 0xD22A5988 in sysMonitorWait

3XHSTACKLINE         at 0xD215E57C in lkMonitorWait

3XHSTACKLINE         at 0xD20E1518 in JVM_MonitorWait

3XHSTACKLINE         at 0xD2086958 in

3XHSTACKLINE         at 0xD2116074 in sysInvokeNative

3XHSTACKLINE         at 0xD210D938 in mmipInvokeJniMethod

3XHSTACKLINE         at 0xD20EB708 in mmipExecuteJava

3XHSTACKLINE         at 0xD20E3334 in xeRunJavaVarArgMethod

3XHSTACKLINE         at 0xD20E35C8 in xeRunDynamicMethod

3XHSTACKLINE         at 0xD20D06D4 in threadRT0

3XHSTACKLINE         at 0xD216380C in xmExecuteThread

3XHSTACKLINE         at 0xD2167CAC in threadStart

3XHSTACKLINE         at 0xD229EE50 in _start

3XHSTACKLINE         at 0xD011167C in _pthread_body

3XHSTACKLINE         at 0xD011167C in _pthread_body

3XMTHREADINFO      "http1-w0 [container1-13]" (TID:0x3031BDD0, sys_thread_t:0x38726928, state:R, native ID:0x373A) prio=5

4XESTACKTRACE          at jeus_jspwork._500_thread_5fcw_5fjsp._jspService(_500_thread_5fcw_5fjsp.java:59)

4XESTACKTRACE          at jeus.servlet.jsp.HttpJspBase.service(HttpJspBase.java:53)

4XESTACKTRACE          at javax.servlet.http.HttpServlet.service(HttpServlet.java:856)

4XESTACKTRACE          at jeus.servlet.jsp.JspServletWrapper.executeServlet(JspServletWrapper.java:94)

4XESTACKTRACE          at jeus.servlet.engine.ServletWrapper.execute(ServletWrapper.java:213)

4XESTACKTRACE          at jeus.servlet.jsp.JspServletWrapper.execute(JspServletWrapper.java:140)

4XESTACKTRACE          at jeus.servlet.engine.HttpRequestProcessor.run(HttpRequestProcessor.java:251)

3XHNATIVESTACK       Native Stack

NULL                 ------------

3XHSTACKLINE         at 0xD20EB708 in mmipExecuteJava

3XHSTACKLINE         at 0xD20E3334 in xeRunJavaVarArgMethod

3XHSTACKLINE         at 0xD20E35C8 in xeRunDynamicMethod

3XHSTACKLINE         at 0xD20D06D4 in threadRT0

3XHSTACKLINE         at 0xD216380C in xmExecuteThread

3XHSTACKLINE         at 0xD2167CAC in threadStart

3XHSTACKLINE         at 0xD229EE50 in _start

3XHSTACKLINE         at 0xD011167C in _pthread_body

3XHSTACKLINE         at 0xD011167C in _pthread_body

결과 설명 : 동기화 블록 안에서 object 오브젝트를 기다리는 Thread ‘state:CW’ 나타나고, finally절을 수행중인 w0 Thread ‘state:R’ 표시되고 있다.

 


deadlock 상태

상태는, 쉽게말해 두개의 Thread 동기화 블록 내부에서, 상대방의 method 호출하는 상황에서, 서로 상대방 Thread (key) 획득하기 위해, 무한정 대기하는 상황을 말한다.

이경우, JVM 그대로 Hangup상태에 빠지게 된다.

 

JDK1.5에서는, 이러한 동기화문제를 해결하기 위해 java.util.concurrent 패키지를 제공한다.

(기존 JSR-166)
java.util.concurrent
패키지에는 동기화,Lock,Queue,ThreadPool 더불어 동기화패턴에 사용될 있는, Time base class들이 추가되어 있다.

주요 클래스들은 아래와 같다.

 

* java.util.concurrent 패키지의 주요 Class

l          Thread pool

-. 캐시 Thread pool, 고정크기 Thread pool, 스케쥴링 Thread pool등을 지원한다.

l          Executor, Future

-. Executor interface, Thread 실행시키는 새로운 방법이며, 기존의 tart() 메서드를 대신하기도 하며, Callable 실행시키는 방법이다.

l          Future interface 비동기 방식으로 Thread 수행시킬 있도록 한다.

l          Queue Class

-. 블록킹 구조의 BlockingQueue interface , non-blocking 구조의 ConcurrentLinkedQueue 등이 있다.

l          세마포어 Class

-. ‘세마포어 내부적으로 숫자를 유지하고 있다가, acquire 호출 -1 수행하고,

release 호출 +1 증가시키는 방식으로 작동한다.

-. 결국 값이 ‘0’ 되면, acquire 요청한 Thread 대기상태로 만들고,

이렇게 하여 multi-threading 환경에서 하나의 resource 접근하는 Thread 개수를

제한하는 방식으로 작동한다.

l          ReadWriteLock 클래스

-. 쉽게 말해, ‘쓰기보다 읽기작업이 많은 multi-threading 환경에서, ‘읽기작업에 대한 배타적(exclusive) 접근을 막겠다는 것이다. 동시 접근을 허용한다.

l          이외에도 CyclicBarrier Class, CountDownLatch Class, Exchanger Class등이 있다.


[thread-deadlock.jsp]

코드설명 : 첫번째 Thread else루틴을 수행하며, object2 객체의 Monitor 대한 Lock 잡고, object1객체에 대해 동기화를 시키고, 해제하고를 계속 반복한다. 이때, 두번째 Thread 실행되면, if절을 타게 되고, object1 대한 Monitor 있을 , 순간적으로 동기화 블록으로 진입하여, object2 대한 Monitor 기다리고 있다. 하지만, object2 대한 Monitor 이미 Thread1 가지고 있으며, Thread1 Thread2 object1 Monitor 기다리게 된다.

따라서, deadlock condition 빠지게 된다.

<%@ page language="java" contentType="text/html; charset=EUC-KR"

    pageEncoding="EUC-KR"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=EUC-KR">

<title>thread-cw.jsp</title>

</head>

<body>

<%!

        public static Object object1 = new Object();

        public static Object object2 = new Object();

        public static int count = 1;

%>

<%

        if(count%2 == 0){

                count++;

                synchronized(object1){

                        for(long i = 0; i < 10000000000L; i++){

                                synchronized(object2){}

                        }

                }

        }else{

                count++;

                synchronized(object2){

                        for(long i = 0; i < 10000000000L; i++){

                                synchronized(object1){}

                        }

                }

        }

%>

</body>

</html>

 

 

[SunOS]

"http1-w1" prio=10 tid=0x00000001003d1cc0 nid=0x3a waiting for monitor entry [0xffffffff57afe000..0xffffffff57aff6
28]   at jeus_jspwork._600_thread_5fdeadlock_5fjsp._jspService(_600_thread_5fdeadlock_5fjsp.java:70)
        - waiting to lock <0xffffffff71857638> (a java.lang.Object)
        - locked <0xffffffff71857628> (a java.lang.Object)
        at jeus.servlet.jsp2.runtime.HttpJspBase.service(HttpJspBase.java:106)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:818)
        at jeus.servlet.jsp.JspServletWrapper.executeServlet(JspServletWrapper.java:94)
        at jeus.servlet.engine.ServletWrapper.execute(ServletWrapper.java:220)
        at jeus.servlet.jsp.JspServletWrapper.execute(JspServletWrapper.java:139)
        at jeus.servlet.engine.HttpRequestProcessor.run(HttpRequestProcessor.java:265)

"http1-w0 [container1-13]" prio=10 tid=0x00000001003d1950 nid=0x39 waiting for monitor entry [0xffffffff57cfe000..
0xffffffff57cff6a8]
        at jeus_jspwork._600_thread_5fdeadlock_5fjsp._jspService(_600_thread_5fdeadlock_5fjsp.java:77)
        - waiting to lock <0xffffffff71857628> (a java.lang.Object)
        - locked <0xffffffff71857638> (a java.lang.Object)
        at jeus.servlet.jsp2.runtime.HttpJspBase.service(HttpJspBase.java:106)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:818)
        at jeus.servlet.jsp.JspServletWrapper.executeServlet(JspServletWrapper.java:94)
        at jeus.servlet.servlets.JspServlet.execute(JspServlet.java:359)
        at jeus.servlet.engine.HttpRequestProcessor.run(HttpRequestProcessor.java:265)

결과 설명 : 각각의 Thread, for 안에서 서로의 객체에 대한 Monitor 기다리면서 동기화 블록 안으로 진입을 대기 하고 있음으로,  ‘waiting for monitor entry’ 표시된다.

Stack 정보에는, 해당 Thread ‘0xffffffff71857638’ ‘0xffffffff71857628’ Locked하고 있는 정보를 있다.


 

[HP-UX]

"http1-w2 [container1-15]" prio=10 tid=60000000024ffc40 nid=60 lwp_id=1583373 waiting for monitor entry [9fffffff7
8700000..9fffffff78700a40]
        at jeus_jspwork._600_thread_5fdeadlock_5fjsp._jspService(_600_thread_5fdeadlock_5fjsp.java:77)
        - waiting to lock <9fffffffb8cde050> (a java.lang.Object)
        - locked <9fffffffb8cde060> (a java.lang.Object)
        at jeus.servlet.jsp2.runtime.HttpJspBase.service(HttpJspBase.java:106)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:818)
        at jeus.servlet.jsp.JspServletWrapper.executeServlet(JspServletWrapper.java:94)
        at jeus.servlet.servlets.JspServlet.execute(JspServlet.java:359)
        at jeus.servlet.engine.HttpRequestProcessor.run(HttpRequestProcessor.java:265)

"http1-w1 [container1-16]" prio=10 tid=60000000024bc480 nid=59 lwp_id=1583372 waiting for monitor entry [9fffffff7
8900000..9fffffff78900ac0]
        at jeus_jspwork._600_thread_5fdeadlock_5fjsp._jspService(_600_thread_5fdeadlock_5fjsp.java:70)
        - waiting to lock <9fffffffb8cde060> (a java.lang.Object)
        - locked <9fffffffb8cde050> (a java.lang.Object)
        at jeus.servlet.jsp2.runtime.HttpJspBase.service(HttpJspBase.java:106)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:818)
        at jeus.servlet.jsp.JspServletWrapper.executeServlet(JspServletWrapper.java:94)
        at jeus.servlet.engine.ServletWrapper.execute(ServletWrapper.java:220)
        at jeus.servlet.jsp.JspServletWrapper.execute(JspServletWrapper.java:139)
        at jeus.servlet.engine.HttpRequestProcessor.run(HttpRequestProcessor.java:265)

결과 설명 : SunOS 거의 유사한 패턴을 보이고 있다.

 


 

[AIX / JDK 1.5]

l          Thread 실행 순서 : w1 à w2 à w0

l          Dump 내용

3XMTHREADINFO      "http1-w0 [container1-13]" (TID:0x0000000114A07100, sys_thread_t:0x00000001147764F0, state:B, native ID:0x0000000
000372005) prio=5
4XESTACKTRACE          at jeus_jspwork/_600_thread_5fdeadlock_5fjsp._jspService(_600_thread_5fdeadlock_5fjsp.java:76)
4XESTACKTRACE          at jeus/servlet/jsp2/runtime/HttpJspBase.service(HttpJspBase.java:106)
4XESTACKTRACE          at javax/servlet/http/HttpServlet.service(HttpServlet.java:818)
4XESTACKTRACE          at jeus/servlet/jsp/JspServletWrapper.executeServlet(JspServletWrapper.java:94)
4XESTACKTRACE          at jeus/servlet/servlets/JspServlet.execute(JspServlet.java:359)
4XESTACKTRACE          at jeus/servlet/engine/HttpRequestProcessor.run(HttpRequestProcessor.java:265)
3XMTHREADINFO      "http1-w1 [container1-14]" (TID:0x0000000114A15C00, sys_thread_t:0x0000000114A11350, state:B, native ID:0x0000000
0003D00BD) prio=5
4XESTACKTRACE          at jeus_jspwork/_600_thread_5fdeadlock_5fjsp._jspService(_600_thread_5fdeadlock_5fjsp.java:69(Compiled Code))
4XESTACKTRACE          at jeus/servlet/jsp2/runtime/HttpJspBase.service(HttpJspBase.java:106)
4XESTACKTRACE          at javax/servlet/http/HttpServlet.service(HttpServlet.java:818)
4XESTACKTRACE          at jeus/servlet/jsp/JspServletWrapper.executeServlet(JspServletWrapper.java:94)
4XESTACKTRACE          at jeus/servlet/engine/ServletWrapper.execute(ServletWrapper.java:220)
4XESTACKTRACE          at jeus/servlet/jsp/JspServletWrapper.execute(JspServletWrapper.java:139)
4XESTACKTRACE          at jeus/servlet/engine/HttpRequestProcessor.run(HttpRequestProcessor.java:265)
3XMTHREADINFO      "http1-w2" (TID:0x0000000114C6C300, sys_thread_t:0x0000000114A11830, state:P, native ID:0x000000000008B031) prio=
5
4XESTACKTRACE          at sun/misc/Unsafe.park(Native Method)
4XESTACKTRACE          at java/util/concurrent/locks/LockSupport.park(LockSupport.java:169)
4XESTACKTRACE          at java/util/concurrent/locks/AbstractQueuedSynchronizer$ConditionObject.await(AbstractQueuedSynchronizer.jav
a:1793)
4XESTACKTRACE          at java/util/concurrent/LinkedBlockingQueue.take(LinkedBlockingQueue.java:379)
4XESTACKTRACE          at jeus/servlet/util/StandardQueue.get(StandardQueue.java:53)
4XESTACKTRACE          at jeus/servlet/engine/ThreadPoolManager.getConnection(ThreadPoolManager.java:332)
4XESTACKTRACE          at jeus/servlet/engine/HttpRequestProcessor.run(HttpRequestProcessor.java:95)

결과 설명 : java.util.concurrent 관련한 클래스들이 작동하고 있는 모습이 보인다.

경우, Dump Header 부분에서 아래와 같은 메시지가 같이 출력된다.

1LKDEADLOCK    Deadlock detected !!!
NULL           ---------------------
NULL
2LKDEADLOCKTHR  Thread "http1-w0 [container1-13]" (0x0000000114A07100)
3LKDEADLOCKWTR    is waiting for:
4LKDEADLOCKMON      sys_mon_t:0x0000000112E0C9E0 infl_mon_t: 0x0000000112E0CA30:
4LKDEADLOCKOBJ     
java/lang/Object@0700000002309EF8/0700000002309F10:
3LKDEADLOCKOWN    which is owned by:
2LKDEADLOCKTHR  Thread "http1-w1 [container1-14]" (0x0000000114A15C00)
3LKDEADLOCKWTR    which is waiting for:
4LKDEADLOCKMON      sys_mon_t:0x000000011498DA00 infl_mon_t: 0x000000011498DA50:
4LKDEADLOCKOBJ     
java/lang/Object@0700000002309F10/0700000002309F28:
3LKDEADLOCKOWN    which is owned by:
2LKDEADLOCKTHR  Thread "http1-w0 [container1-13]" (0x0000000114A07100)

 

 [AIX / JDK 1.4]

l          Thread 실행 순서 : w1 à w2 à w0

l          Dump 내용

3XMTHREADINFO      "http1-w1" (TID:0x304F7768, sys_thread_t:0x38E21528, state:CW, native ID:0x383B) prio=5
4XESTACKTRACE          at jeus_jspwork._500_thread_5fdeadlock_5fjsp._jspService(_500_thread_5fdeadlock_5fjsp.java(Compiled Code))
4XESTACKTRACE          at jeus.servlet.jsp.HttpJspBase.service(HttpJspBase.java:53)
4XESTACKTRACE          at javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
4XESTACKTRACE          at jeus.servlet.jsp.JspServletWrapper.executeServlet(JspServletWrapper.java:94)
4XESTACKTRACE          at jeus.servlet.engine.ServletWrapper.execute(ServletWrapper.java:213)
4XESTACKTRACE          at jeus.servlet.jsp.JspServletWrapper.execute(JspServletWrapper.java:140)
4XESTACKTRACE          at jeus.servlet.engine.HttpRequestProcessor.run(HttpRequestProcessor.java:251)
3XHNATIVESTACK       Native Stack
NULL                 ------------
3XHSTACKLINE         at 0x38EE6804 in
3XHSTACKLINE         at 0xD012316C in _event_wait
3XHSTACKLINE         at 0xD012E9DC in _cond_wait_local
3XHSTACKLINE         at 0xD012EEB0 in _cond_wait
3XHSTACKLINE         at 0xD012F874 in pthread_cond_timedwait
3XHSTACKLINE         at 0xD22A6A10 in condvarTimedWaitUpTo248Days
3XHSTACKLINE         at 0xD22A6BA0 in condvarTimedWait
3XHSTACKLINE         at 0xD22A5988 in sysMonitorWait
3XHSTACKLINE         at 0xD21604F4 in lkMonitorEnter
3XHSTACKLINE         at 0xD2318F08 in _jit_monitorEnterQuicker
3XHSTACKLINE         at 0xD2509220 in JITSigSegvHandler
3XHSTACKLINE         at 0x35339254 in
3XHSTACKLINE         at 0x35339254 in
3XMTHREADINFO      "http1-w0" (TID:0x304C93B0, sys_thread_t:0x38E20F28, state:MW, native ID:0x373A) prio=5
4XESTACKTRACE          at jeus_jspwork._500_thread_5fdeadlock_5fjsp._jspService(_500_thread_5fdeadlock_5fjsp.java(Compiled Code))
4XESTACKTRACE          at jeus.servlet.jsp.HttpJspBase.service(HttpJspBase.java:53)
4XESTACKTRACE          at javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
4XESTACKTRACE          at jeus.servlet.jsp.JspServletWrapper.executeServlet(JspServletWrapper.java:94)
4XESTACKTRACE          at jeus.servlet.servlets.JspServlet.execute(JspServlet.java:359)
4XESTACKTRACE          at jeus.servlet.engine.HttpRequestProcessor.run(HttpRequestProcessor.java:251)
3XHNATIVESTACK       Native Stack
NULL                 ------------
3XHSTACKLINE         at 0xD230F26C in release_m_block
3XHSTACKLINE         at 0xD011D4A4 in _mutex_lock
3XHSTACKLINE         at 0xD22A66E4 in cooperative_mutex_lock
3XHSTACKLINE         at 0xD22A6334 in sysMonitorEnter
3XHSTACKLINE         at 0xD21604F4 in lkMonitorEnter
3XHSTACKLINE         at 0xD2318F08 in _jit_monitorEnterQuicker
3XHSTACKLINE         at 0xD2509220 in JITSigSegvHandler
3XHSTACKLINE         at 0x35339254 in

경우, Dump Header 부분에서 아래와 같은 메시지가 같이 출력된다.

1LKDEADLOCK    Deadlock detected !!!

NULL           ---------------------

NULL

2LKDEADLOCKTHR  Thread "http1-w1" (0x38E21528)

3LKDEADLOCKWTR    is waiting for:

4LKDEADLOCKMON      sys_mon_t:0x37C2A968 infl_mon_t: 0x00000000:

4LKDEADLOCKOBJ      java.lang.Object@30358DD0/30358DD8:

3LKDEADLOCKOWN    which is owned by:

2LKDEADLOCKTHR  Thread "http1-w0" (0x38E20F28)

3LKDEADLOCKWTR    which is waiting for:

4LKDEADLOCKMON      sys_mon_t:0x37C2A4F8 infl_mon_t: 0x38CF3AD4:

4LKDEADLOCKOBJ      java.lang.Object@30358DE0/30358DE8:

3LKDEADLOCKOWN    which is owned by:

2LKDEADLOCKTHR  Thread "http1-w1" (0x38E21528)

 


맺음말

지금까지 Thread dump생성 , 플랫폼 주요 Thread State 어떤 식으로 보여지는지 간략하게 살펴 보았다. 하지만, 실제 운영환경에서 발생하는 Java ThreadDump 상에는 보다 복잡 다단한 상황이 많이 벌어지게 마련이다. 문서는, 그러한 복합상황의 해석의 기초가 되는, Thread State 대해 주로 다뤄본 것이 목적이다.

지금까지 소개한 주요 패턴 이외에도, Thread 정상적으로 작동하는 처럼 보이지만, 실제로는 Hang-up상태로 빠지는 경우 등의 변수가 많이 존재한다. 실제로 그러한 이유로, Service 느려지거나, 멈추는 현상들이 주로 발생하는 것이 현실이다. 따라서, WAS 근간으로 하는 System에의 Thread Dump 분석 스킬을 향상시키기 위해서는, 해당 문서에서 다뤄본 Thread State 기초로 하여, 다양한 실제 Dump 많이 접해보는 것이 가장 좋은 방법이다.

문서에서 다뤄지지 않은 보다 자세한 내용은, Vendor 기술홈페이지나 관련서적을 참조하도록 한다.

 

l          IBM : http://www-1.ibm.com/support/docview.wss?fdoc=aimwas&rs=180&uid=swg21181068

l          SUN : http://java.sun.com/developer/onlineTraining/Programming/JDCBook/stack.html


출처 : http://blog.daum.net/_blog/BlogView.do?blogid=0JvJB&articleno=7577652#ajax_history_home
반응형
블로그 이미지

Good Joon

IT Professionalist Since 1999

,