// 에드센스

지난번 JVM 포스팅에서 다음과 같은 개념을 다뤘다.

 

이때 Method Area에는 클래스, 인터페이스, 메소드, 필드, Static 변수가 보관되고

Heap Area에는 new 키워드로 생성된 객체와 배열이 보관된다고 했었다.

 

Method Area에 저장되는 Static 키워드는 지금까지 어디엔가 많이 붙혀서 써오긴 했는데 정확히 뭐하는 놈인지 모호했다. 이 기회에 정리해보자.

 

 

한 줄 요약

static 키워드를 사용한 변수는 클래스가 메모리에 올라갈 때 자동으로 생성이 된다.

즉, 인스턴스(객체) 생성 없이 바로 사용가능 하다. (그래서 편리하고 빠르다)

 

 

non-static 멤버 VS static 멤버

non-static 멤버

1. 공간적 특성: 멤버는 객체마다 별도로 존재한다.
    1.1. 인스턴스 멤버 라고 부른다.
2. 시간적 특성: 객체 생성 시에 멤버가 생성된다.
    2.1. 객체가 생길 때 멤버도 생성된다.
    2.2. 객체 생성 후 멤버 사용이 가능하다.
    2.3. 객체가 사라지면 멤버도 사라진다.
3. 공유의 특성: 공유되지 않는다.
    3.1. 멤버는 객체 내에 각각의 공간을 유지한다.

 

static 멤버

1. 공간적 특성: 멤버는 클래스당 하나가 생성된다.
    1.1. 멤버는 객체 내부가 아닌 별도의 공간에 생성된다.
    1.2. 클래스 멤버 라고 부른다.
2. 시간적 특성: 클래스 로딩 시에 멤버가 생성된다.
    2.1. 객체가 생기기 전에 이미 생성된다.
    2.2. 객체가 생기기 전에도 사용이 가능하다. (즉, 객체를 생성하지 않고도 사용할 수 있다.)
    2.3. 객체가 사라져도 멤버는 사라지지 않는다.
    2.4. 멤버는 프로그램이 종료될 때 사라진다.
3. 공유의 특성: 동일한 클래스의 모든 객체들에 의해 공유된다.

 

 

 

 

Static 키워드를 사용하는 이유

1. 자주 변하지 않는 일정한 값이나 설정 정보같은 공용자원에 대한 접근시 매번 메모리에 로딩하는 것 보다 비용을 줄일 수 있고 효율을 높일 수 있기 때문.

 

2. 인스턴스 생성 없이 바로 사용가능하기 때문에 프로그램에서 공통으로 사용되는 데이터들을 관리할 때 사용된다.

 

 

 

 

예제로 알아보자

class Foo{
	public static String s1 = "i am static";
	public String s2 = "i am instance";
}


public class static_practice {
	public static void main(String[] args) {
		System.out.println(Foo.s1);
		System.out.println(Foo.s2);	//에러
		
		Foo foo = new Foo();
		System.out.println(foo.s1);
		System.out.println(foo.s2); 
	}
}

 

Foo라는 클래스를 만들고 문자열 변수 두개를 초기화 시켰다. 한개는 static을 붙혔다.

여기서 주목할 것은 Foo.s1은 에러가 안떴고 Foo.s2는 에러가 발생했다는 것이다.

 

 

static 변수 s1은 new 키워드를 통해 객체를 생성하지 않아도 바로 사용할 수 있다. 반면 그냥 인스턴스 변수 s2는 객체를 생성한 후 접근이 가능하므로 에러가 발생한다.

 

 

 

 

class Foo{
	public static String s1 = "i am static";
	public String s2 = "i am instance";
}


public class static_practice {
	public static void main(String[] args) {
		//System.out.println(Foo.s1);
		//System.out.println(Foo.s2);
		
		Foo foo1 = new Foo();
		System.out.println("foo1.s1: "+foo1.s1);
		System.out.println("foo1.s2: "+foo1.s2);
		
		Foo foo2 = new Foo();
		System.out.println("foo2.s1: "+foo2.s1);
		System.out.println("foo2.s2: "+foo2.s2);
		
		System.out.println("====변경====");
		
		foo2.s1 = "changed s1 (foo2)";
		foo2.s2 = "changed s2 (foo2)";
		
		System.out.println("foo1.s1: "+foo1.s1);
		System.out.println("foo1.s2: "+foo1.s2);
		System.out.println("foo2.s1: "+foo2.s1);
		System.out.println("foo2.s2: "+foo2.s2);
	}
}

 

이번에는 static의 공유 속성을 알아보는 예제다.

 

결과부터 보면 이러하다.

 

====변경==== 부분에서 foo2객체의 값들을 다 바꾸었더니 건들지도 않은 foo1 객체의 static 변수 값도 바뀌었다

foo2의 값들은 당연히 바뀌는것이고.

 

Foo클래스의 static 변수는 해당 클래스의 모든 객체에 공통으로 사용되기 때문이다.

 

이처럼 static 변수, 메서드는 클래스 원형의 것을 참조하는 형태기에 한개라도 바뀌면 다 바뀐다.

 

 

 

참고:

개발을 하면서 jvm, jdk, jre와 같은 용어들을 많이 보며 지나갔는데 한번 정리가 필요할 것 같아서 글을 쓴다.

 

JVM이란

JVM은 자바 가상머신으로 자바 바이트코드를 실행 할 수 있는 주체로 JVM 덕분에 CPU나 플랫폼(OS+CPU아키텍처)과 독릭접으로 동작 가능하다. 예를들어 리눅스에서 컴파일한 C프로그램을 윈도우에서 실행했을때 환경이 달라서 작동하지 않는다는 문제가 있다고 한다. C/C++은 플랫폼 종속적이기에 크로스컴파일이 필요하다. 

 

 

자바는 JVM이 설치된 곳이라면 어디든 똑같이 작동한다. 하지만 이 JVM은 플랫폼 종속적이라는 모순이 있는데 어찌보면 당연한 것이다. 플랫폼이 다른 환경에서 일어나는 다양한 문제들을 JVM이 한번에 퉁쳐서 해결해 주기 때문이다. 또 JVM은 다른 하드웨어와 다르게 레지스터기반이 아닌 스택기반으로 동작한다. 이 부분도 해당 플랫폼이 레지스터를 사용하는지 안하는지 알 수 없기에 플랫폼 독립적으로 사용할 수 있는 스택을 사용하는 것이다.

 

자바 프로그램은 우리가 작성한 소스코드가 JAVAC compiler를 통해 바이트코드로 변환되고 이를 JVM이 읽어들이는 방식으로 진행된다.

 

 

 

 

JVM구조

JVM의 구조는 크게 보면, Garbage Collector, Execution Engine, Class Loader, Runtime Data Area로, 4가지로 나눌 수 있다. 

 

 

1. Class Loader

JVM 내로 클래스 파일을 로드하고, 링크를 통해 배치하는 작업을 수행하는 모듈이다. 런타임 시에 동적으로 클래스를 로드한다.

 

2. Execution Engine

클래스 로더를 통해 JVM 내의 Runtime Data Area에 배치된 바이트 코드들을 명렁어 단위로 읽어서 실행한다. 최초 JVM이 나왔을 당시에는 인터프리터 방식이었기때문에 속도가 느리다는 단점이 있었지만 JIT 컴파일러 방식을 통해 이 점을 보완하였다. JIT는 바이트 코드를 어셈블러 같은 네이티브 코드로 바꿈으로써 실행이 빠르지만 역시 변환하는데 비용이 발생한다. 이 같은 이유로 JVM은 모든 코드를 JIT 컴파일러 방식으로 실행하지 않고, 인터프리터 방식을 사용하다가 일정한 기준이 넘어가면 JIT 컴파일러 방식으로 실행한다.

 

 

3. Garbage Collector

Garbage Collector(GC)는 힙 메모리 영역에 생성된 객체들 중에서 참조되지 않은 객체들을 탐색 후 제거하는 역할을 한다. 이때, GC가 역할을 하는 시간은 언제인지 정확히 알 수 없다.

 

 

4. Runtime Data Area

JVM의 메모리 영역으로 자바 애플리케이션을 실행할 때 사용되는 데이터들을 적재하는 영역. 이 영역은 크게 Method Area, Heap Area, Stack Area, PC Register, Native Method Stack로 나눌 수 있다. 

 

Method Area, Heap Area는 모든 쓰레드에서 공유, 나머지는 쓰레드마다 각각 존재한다.

 

이 Runtime Data Area를 살펴보자

 

4.1. Method area 

모든 쓰레드가 공유하는 메모리 영역. 메소드 영역은 클래스, 인터페이스, 메소드, 필드, Static 변수 등의 바이트 코드를 보관한다.

 

 

4.2. Heap area

모든 쓰레드가 공유하며, new 키워드로 생성된 객체와 배열이 생성되는 영역. 또한, 메소드 영역에 로드된 클래스만 생성이 가능하고 Garbage Collector가 참조되지 않는 메모리를 확인하고 제거하는 영역이다.

 

 

4.3. Stack area 

 

메서드 호출 시마다 각각의 스택 프레임(그 메서드만을 위한 공간)이 생성한다. 그리고 메서드 안에서 사용되는 값들을 저장하고, 호출된 메서드의 매개변수, 지역변수, 리턴 값 및 연산 시 일어나는 값들을 임시로 저장한다. 마지막으로, 메서드 수행이 끝나면 프레임별로 삭제한다.

 

 

4.4. PC Register

쓰레드가 시작될 때 생성되며, 생성될 때마다 생성되는 공간으로 쓰레드마다 하나씩 존재한다. 쓰레드가 어떤 부분을 무슨 명령으로 실행해야할 지에 대한 기록을 하는 부분으로 현재 수행중인 JVM 명령의 주소를 갖는다.

 

 

4.5. Native method stack

자바 외 언어로 작성된 네이티브 코드를 위한 메모리 영역.

 

 

 

 

 

 

참고:

https://steady-coding.tistory.com/305

 

JVM 메모리 구조란? (JAVA)

안녕하세요? 코딩 중독입니다. 오늘은 JVM 메모리 구조에 대해 알아보겠습니다. JVM이란? JVM 메모리 구조를 설명하기 전에 JVM이 무엇인지 알아야 합니다. JVM은 Java Virtual Machine의 약자로, 자바 가상

steady-coding.tistory.com

https://youtu.be/UzaGOXKVhwU

 

스프링을 많이 써온건 아니지만 그래도 쓰긴 쓰고있는 이 시점에서 문뜩 의문이 들었다. 친구가 나에게 만약 "스프링이 뭐야?" 라고 물어온다면 나는 뭐라고 대답 할 것인가? 스프링을 써오면서 이게 뭔지 정확히 모르고 사용해온 것 같아서 스스로 부끄러움을 느꼈다. 그래서 한번 조사해보았다. 스프링 기본 원리를.

 

한 마디로 요약하면?

"IoC와 AOP를 지원하는 경량의 컨테이너 프레임워크"

 

이제 이 문장을 하나씩 뜯어보자

 

컨테이너가 뭘까?

컨테이너는 특정 객체의 생성과 관리를 담당하며 객체 운용에 필요한 다양한 기능을 제공한다. 애플리케이션 운용에 필요한 객체를 생성하고 객체 간의 의존관계를 관리한다는 점에서 스프링도 일종의 컨테이너라고 할 수 있다.

 

컨테이너의 종류

스프링에서는 BeanFactory와 이를 상속한 ApplicationContext 두 가지 유형의 컨테이너를 제공한다. BeanFactory는 스프링 빈을 관리하고 조회하는 역할을 담당한다. BeanFactory를 전부 상속받는 ApplicationContext는 메시지 소스를 활용한 국제화 기능, 환경변수, 애플리케이션 이벤트, 편리한 리소스 조회 와 같은 편리한 부가기능이 있다. BeanFactory를 직접 사용할 일은 거의 없으며 보통  Applicationcontext를 사용한다. 

 

출처: 김영한님의 스프링 핵심 원리

 

자 그럼 IoC는 뭘까?

애플리케이션 개발 시 중요한점 중에 하나는 낮은 결합도와 높은 응집도이다. 스프링의 IoC는 객체 생성을 자바 코드로 직접 처리하는 것이 아니라 컨테이너가 대신 처리하게 한다. 그리고 객체와 객체 사이의 의존관계 역시 컨테이너가 처리한다. 이처럼 프로그램의 제어 흐름을 개발자가 직접 제어하는 것이 아니라 외부에서 관리하는 것을 제어의 역전(IoC)라고 한다.

 

의존성 주입

의존 관계란 객체와 객체간의 결합 관계이다. 한 객체에서 다른 객체의 변수나 메소드를 사용하려면 해당 객체의 레퍼런스 정보가 필요하다. DI기능을 사용하지 않고 순수 자바코드처럼 코드에서 new를 통해 객체를 직접 생성해서 사용하면 이는 높은 결합도를 가지게 된다. new를 사용하지 않고 의존성을 주입하는 방법은

 

1. XML을 통한 의존성 주입

2. 속성을 통한 의존성 주입

3. 어노테이션을 통한 의존성 주입

 

이 있는데 이중 3번에 대해서 3가지를 패턴을 소개하겠다.

 

1. 생성자 주입

@Component
public class SampleController {
    private SampleRepository sampleRepository;
 
    @Autowired
    public SampleController(SampleRepository sampleRepository) {
        this.sampleRepository = sampleRepository;
    }
}

 

2. 필드 주입

@Component
public class SampleController {
    @Autowired
    private SampleRepository sampleRepository;
}

 

3. Setter 주입

@Component
public class SampleController {
    private SampleRepository sampleRepository;
 
    @Autowired
    public void setSampleRepository(SampleRepository sampleRepository) {
        this.sampleRepository = sampleRepository;
    }
}

 

 

 

AOP는 뭘까?

직역하면 "관점지향프로그래밍"이다.

개발을 하다보면 코드 곳곳에서 공통적으로 요구되는 기능들이 있다. 예를들어 메소드들의 실행시간 로그라던가, 컨트롤러 호출 시 세션검사라던가 이런 기능을 구현하고 싶을때 모든 메소드마다 코드를 추가해가며 개발하기는 너무 비효율 적이기에 AOP라는 기능이 있는것이다. 

 

즉, AOP는 중복을 제거하기에 아주 효과적인 방법이다.

 

이또한 XML을 사용한 설정과 어노테이션을 사용한 설정이 있는데 나는 주로 후자를 많이 사용했다. (XML 너무 복잡해ㅠㅠ) AOP에 관해서는 나중에 따로 포스팅을 해보겠다.

 

 

오늘은 간단하게 스프링이 무엇인지에 대한 얕은 개념들을 알아보았는데 사실 너무 방대해서 눈감고 더듬는 그런 느낌이다. 언젠가 내가 알던 개념들이 한군대로 파파팍 모이며 스프링의 전체 모양을 이해하는 날이 빨리 오면 좋겠다. (1일 1포스팅만 해도 훨씬 일찍 올듯..)

 

 

참고:

https://asfirstalways.tistory.com/334

https://atoz-develop.tistory.com/entry/Spring-%EC%9D%98%EC%A1%B4%EC%84%B1-%EC%A3%BC%EC%9E%85DI-Dependency-Injection%EC%9D%98-%EC%84%B8%EA%B0%80%EC%A7%80-%EB%B0%A9%EB%B2%95

 

Spring 의 시작, 프레임워크의 구성요소와 동작원리

Spring Framework의 구성요소와 동작원리 POJO 스프링의 특징을 살펴보면 POJO라는 단어가 등장한다. POJO란 Plain Old Java Object로 직역하자면 평범한 옛날 자바 객체이다. 말 그대로 자바 객체인 것이다..

asfirstalways.tistory.com

 

블로그 이름이 하루에 딱 한개만임에도 불구하고 포스팅 3개만에 지키지 못했다ㅠㅠ

 

간만에 자전거좀 탄다는걸 신나가지고 너무 빡세게 타서 몸살이온것! 덕분에 이틀동안 누워만 있었다...

 

암튼 이번에는 소셜로그인 연습을 할 생각이다. 원래는 구글로그인부터 해보려했지만 왜인지 구글 클라우드에서 프로젝트를 생성하고 설정할때 "앱을 저장하는 중에 오류가 발생했습니다"가 떠서 진행이 안됐다. 해결법을 찾지 못하여서 네이버부터 해본다

 

공식문서: https://developers.naver.com/docs/login/api/api.md

 

네이버 아이디로 로그인 API 명세 - LOGIN

'네이버 아이디로 로그인 API는 네이버 로그인 인증 요청 API, 접근 토큰 발급/갱신/삭제 요청API로 구성되어 있습니다. 네이버 로그인 인증 요청 API는 여러분의 웹 또는 앱에 네이버 로그인 화면을

developers.naver.com

 

 

전체적인 흐름

 

Naver Developers에서 애플리케이션 생성하기

네이버 로그인 api를 사용하기 위해 오픈 api 사용 신청을 해준다.

받을수 있는 정보는 다 받아보자

서비스 URL은 네이버 로그인하기 버튼이 있는 페이지를 지정

Callback URL은 로그인 후 결과 페이지를 지정

 

적으라는 것들 적은 후 저장하기 누르면 

이렇게 ID와 Secret코드를 준다. 

1. Client ID

2. Client Secret

3. 서비스 URL

4. Callback URL

이 네가지 정보를 활용하여 간단한 컨트롤러와 뷰를 작성해보자.

 

 

전체적인 구조는 

이와같이 매우 간단하게 구성했다.

 

UserController.java

package com.example.loginapiprac.controller;

import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import javax.servlet.http.HttpSession;

@Controller
@Slf4j
public class UserController {

    @RequestMapping(value="/", method= RequestMethod.GET)
    public String index() {
        log.info("home controller");
        return "APIExamNaverLogin";
    }

    @RequestMapping(value="login/oauth2/code/naver", method=RequestMethod.GET)
    public String loginPOSTNaver(HttpSession session) {
        log.info("callback controller");
        return "callback";
    }
}

첫번째 메서드는 로그인 버튼이 있는 뷰페이지를 반환하고 두번째 메서드는 로그인 이후 보여질 페이지를 반환한다.

두번째 메서드의 value="/login/oauth2/code/naver"는 네이버 개발자 페이지에서 지정한 Callback URL과 통일시켜준다.

 

 

APIExamNaverLogin.html

<!doctype html>
<html lang="ko">
<head>
    <meta charset="utf-8">
    <title>네이버 로그인</title>
    <script type="text/javascript" src="https://static.nid.naver.com/js/naverLogin_implicit-1.0.3.js" charset="utf-8"></script>
    <script type="text/javascript" src="http://code.jquery.com/jquery-1.11.3.min.js"></script>
</head>
<body>
<!-- 네이버아이디로로그인 버튼 노출 영역 -->
test
<div id="naver_id_login"></div>
<!-- //네이버아이디로로그인 버튼 노출 영역 -->
<script type="text/javascript">
    var naver_id_login = new naver_id_login("Client_ID", "http://localhost:8080/login/oauth2/code/naver");
    var state = naver_id_login.getUniqState();
    naver_id_login.setButton("white", 2,40);
    naver_id_login.setDomain("http://localhost:8080/");
    naver_id_login.setState(state);
    naver_id_login.setPopup();
    naver_id_login.init_naver_id_login();
</script>
</body>
</html>

 

callback.html

<!doctype html>
<html lang="ko">
<head>
    <script type="text/javascript" src="https://static.nid.naver.com/js/naverLogin_implicit-1.0.3.js"
            charset="utf-8"></script>
    <script type="text/javascript" src="http://code.jquery.com/jquery-1.11.3.min.js"></script>
</head>
<body>
callback
<script type="text/javascript">
    var naver_id_login = new naver_id_login("Client_ID", "http://localhost:8080/login/oauth2/code/naver");
    // 접근 토큰 값 출력
    alert(naver_id_login.oauthParams.access_token);
    // 네이버 사용자 프로필 조회
    naver_id_login.get_naver_userprofile("naverSignInCallback()");

    // 네이버 사용자 프로필 조회 이후 프로필 정보를 처리할 callback function
    function naverSignInCallback() {
        alert(naver_id_login.getProfileData('email'));
        alert(naver_id_login.getProfileData('nickname'));
        alert(naver_id_login.getProfileData('age'));
        alert(naver_id_login.getProfileData('id'));
        alert(naver_id_login.getProfileData('birthday'));
        alert(naver_id_login.getProfileData('gender'));
        alert(naver_id_login.getProfileData('mobile'));
    }

</script>
</body>
</html>

 

 

실행결과

이렇게 귀여운 네이버 로그인 버튼이 생기는것을 확인할 수 있다. 이걸 클릭하면

 

 

access token
email

 

gender

등등 요청한 나의 네이버 계정 정보가 다 받아진다.

 

개발자도구에서 넘어온 json파일을 확인할 수 있다.

 

 

Naver Developers에 따르면 요청과 응답은 다음과 같은 형식으로 진행된다고 한다.

 

 

여기에 하나씩 살을 붙혀가며 발전시켜 봐야겠다.

 

참고: https://thiago6.tistory.com/44

 

 

 

 

 

저번 포스팅의 마지막처럼 여러개의 쓰레드를 구현하기 위해서

Thread t1 = new Thread(task);

Thread t1 = new Thread(task);

Thread t1 = new Thread(task);

Thread t1 = new Thread(task);

Thread t1 = new Thread(task);

...

 

과 같은 무지성 선언이 좋지 않은 이유가 뭘까?

 

쓰레드 풀을 사용해야하는 이유

1. 프로그램 성능저하를 방지하기 위해

 

매번 발생되는 작업을 병렬처리하기 위해 스레드를 생성/수거하는데 따른 부담은 프로그램 전체적인 퍼포먼스 저하시킨다. 따라서 스레드풀을 만들어 놓는다.

 

 

2. 다수의 사용자 요청을 처리하기 위해

 

서비스적인 측면으로 바라볼 때, 특히 대규모 프로젝트에서 중요하다. 다수의 사용자의 요청을 수용하고, 빠르게 처리하고 대응하기 위해 스레드풀을 사용한다.

 

 

 

 

쓰레드 풀의 단점

1. 한번에 너무 많은 쓰레드를 생성하면 메모리 낭비가 발생한다

 

많은 병렬처리를 예상해서 1억개의 스레드를 만들어 놓았다고 생각해보자. 실제로 100개정도의 요청과 병렬처리를 했다. 그렇다면.. 나머지 스레드들은 아무일도 하지않고 메모리만 차지하는 최악의 경우가 발생될 수 있다.

 

 

2. 노는 스레드가 발생될 수 있다.

 

1번과 비슷하지만 조금 다르다. 

예를 들어 A,B,C 스레드 3개가 있는데, 병렬적으로 일을 처리하는 과정에서 A,B,C 작업완료 소요시간이 다른 경우 스레드 유휴시간 즉, A스레드는 아직 일이 많아서 허덕이고 있는데, B,C는 일을 다하고 A가 열심히 일하는 것을 보고 놀고만 있는 유휴시간이 발생된다. 자바에서는 이를 방지하기 위해 forkJoinPool 을 지원한다. 아래 링크를 통해 알아보자

https://hamait.tistory.com/612

 

쓰레드풀 과 ForkJoinPool

쓰레드 똑똑똑! 누구니? 쓰레드 에요.. 프로그램(프로세스) 안에서 실행 되는 하나의 흐름 단위에요. 내부에서 while 을 돌면 엄청 오랬동안 일을 할 수 도 있답니다. 쓰레드 끼리는 값 (메모리)

hamait.tistory.com

 

 

쓰레드 풀을 사용한 멀티 쓰레드 구현 예제

package Thread_Practice;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

public class ThreadPool2 {

	public static void main(String[] args) {
		BlockingQueue<Runnable> bq = new ArrayBlockingQueue<>(1);
		
		/* corePoolSize = 100	(쓰레드 풀이 기본적으로 몇개의 쓰레드를 풀에 가지고 있을지
		 * maximumPoolSize = 100(이 값을 넘어가면 RejectedExecutionException 발생)
		 * keepAliveTime = 10	(idle 쓰레드의 keep alive time)
		 * TimeUnit.SECONDS		(keepAliveTime의 시간 단위)
		 * workQueue = bq		(corePoolSize를  넘어서는 쓰레드들을 큐잉 처리하기 위한 큐 선언)
		 * */
		ThreadPoolExecutor threadPoolExecutor
        		= new ThreadPoolExecutor(100,100,10,TimeUnit.SECONDS, bq);
		
		Runnable task = new Task2();
		for(int i=0;i<100;i++) {
			threadPoolExecutor.execute(task);
		}
		System.out.println("쓰레드 콜 종료"); 
	}

}

class Task2 implements Runnable{
	
	int num = 0;
	@Override
	public void run() {
		for(int i=0;i<10;i++) {
			System.out.println(Thread.currentThread().getName()+", num = "+num++);
		}
	}
}

 

 

ThreadPoolExecutor threadPoolExecutor

= new ThreadPoolExecutor(corePoolSize , maximumPoolSize , keepAliveTime , TimeUnit.SECONDS , workQueue );

 

각각의 인자들은 다음의 의미를 가진다.

 

 * corePoolSize = 100 (쓰레드 풀이 기본적으로 몇개의 쓰레드를 풀에 가지고 있을지
 * maximumPoolSize = 100(이 값을 넘어가면 RejectedExecutionException 발생)
 * keepAliveTime = 10 (idle 쓰레드의 keep alive time)
 * TimeUnit.SECONDS (keepAliveTime의 시간 단위)
 * workQueue = bq (corePoolSize를  넘어서는 쓰레드들을 큐잉 처리하기 위한 큐 선언)

 

즉 위 코드는

 

[기본적으로 100개의 쓰레드를 가지고있으며]

[100개의 쓰레드가 넘어가면 예외가 발생하고]

[keepAliveTime 가 10초이며]

[ArrayBlockingQueue를 사용한 쓰레드 큐잉]

 

을 하는 쓰레드 풀을 선언한 것이다

 

실행결과는 더보기를 누르면 나온다.

 

더보기

pool-1-thread-2, num = 0
pool-1-thread-3, num = 2
pool-1-thread-3, num = 4
pool-1-thread-3, num = 5
pool-1-thread-1, num = 1
pool-1-thread-4, num = 7
pool-1-thread-3, num = 6
pool-1-thread-2, num = 3
pool-1-thread-3, num = 10
pool-1-thread-5, num = 12
pool-1-thread-4, num = 9
pool-1-thread-4, num = 15
pool-1-thread-1, num = 8
pool-1-thread-1, num = 17
pool-1-thread-4, num = 16
pool-1-thread-6, num = 20
pool-1-thread-6, num = 21
pool-1-thread-6, num = 22
pool-1-thread-6, num = 23
pool-1-thread-6, num = 24
pool-1-thread-6, num = 25
pool-1-thread-6, num = 26
pool-1-thread-6, num = 27
pool-1-thread-6, num = 28
pool-1-thread-6, num = 29
pool-1-thread-1, num = 18
pool-1-thread-7, num = 30
pool-1-thread-7, num = 32
pool-1-thread-7, num = 33
pool-1-thread-7, num = 34
pool-1-thread-7, num = 35
pool-1-thread-7, num = 36
pool-1-thread-7, num = 37
pool-1-thread-7, num = 38
pool-1-thread-7, num = 39
pool-1-thread-7, num = 40
pool-1-thread-5, num = 14
pool-1-thread-5, num = 41
pool-1-thread-5, num = 42
pool-1-thread-5, num = 43
pool-1-thread-5, num = 44
pool-1-thread-5, num = 45
pool-1-thread-5, num = 46
pool-1-thread-3, num = 13
pool-1-thread-2, num = 11
pool-1-thread-3, num = 48
pool-1-thread-5, num = 47
pool-1-thread-1, num = 31
pool-1-thread-1, num = 52
pool-1-thread-1, num = 53
pool-1-thread-1, num = 54
pool-1-thread-1, num = 55
pool-1-thread-1, num = 56
pool-1-thread-4, num = 19
pool-1-thread-4, num = 57
pool-1-thread-4, num = 58
pool-1-thread-4, num = 59
pool-1-thread-4, num = 60
pool-1-thread-4, num = 61
pool-1-thread-5, num = 51
pool-1-thread-3, num = 50
pool-1-thread-3, num = 62
pool-1-thread-3, num = 63
pool-1-thread-2, num = 49
pool-1-thread-2, num = 64
pool-1-thread-2, num = 65
pool-1-thread-2, num = 66
pool-1-thread-2, num = 67
pool-1-thread-2, num = 68
pool-1-thread-2, num = 69
pool-1-thread-12, num = 70
pool-1-thread-12, num = 71
pool-1-thread-12, num = 72
pool-1-thread-12, num = 73
pool-1-thread-11, num = 74
pool-1-thread-11, num = 76
pool-1-thread-10, num = 77
pool-1-thread-10, num = 79
pool-1-thread-10, num = 80
pool-1-thread-10, num = 81
pool-1-thread-10, num = 83
pool-1-thread-10, num = 84
pool-1-thread-10, num = 85
pool-1-thread-10, num = 86
pool-1-thread-10, num = 87
pool-1-thread-10, num = 88
pool-1-thread-13, num = 82
pool-1-thread-13, num = 89
pool-1-thread-13, num = 90
pool-1-thread-13, num = 91
pool-1-thread-13, num = 92
pool-1-thread-13, num = 93
pool-1-thread-13, num = 94
pool-1-thread-13, num = 95
pool-1-thread-13, num = 96
pool-1-thread-13, num = 97
pool-1-thread-9, num = 98
pool-1-thread-9, num = 99
pool-1-thread-9, num = 100
pool-1-thread-9, num = 101
pool-1-thread-9, num = 102
pool-1-thread-9, num = 103
pool-1-thread-9, num = 104
pool-1-thread-9, num = 105
pool-1-thread-9, num = 106
pool-1-thread-9, num = 107
pool-1-thread-12, num = 75
pool-1-thread-12, num = 108
pool-1-thread-12, num = 109
pool-1-thread-12, num = 110
pool-1-thread-12, num = 111
pool-1-thread-12, num = 112
pool-1-thread-11, num = 78
pool-1-thread-11, num = 113
pool-1-thread-11, num = 114
pool-1-thread-11, num = 115
pool-1-thread-11, num = 116
pool-1-thread-11, num = 117
pool-1-thread-11, num = 118
pool-1-thread-11, num = 119
pool-1-thread-8, num = 120
pool-1-thread-8, num = 121
pool-1-thread-8, num = 122
pool-1-thread-8, num = 123
pool-1-thread-8, num = 124
pool-1-thread-8, num = 125
pool-1-thread-8, num = 126
pool-1-thread-8, num = 127
pool-1-thread-8, num = 128
pool-1-thread-8, num = 129
pool-1-thread-15, num = 131
pool-1-thread-15, num = 132
pool-1-thread-15, num = 133
pool-1-thread-15, num = 134
pool-1-thread-15, num = 135
pool-1-thread-15, num = 136
pool-1-thread-15, num = 137
pool-1-thread-15, num = 138
pool-1-thread-15, num = 139
pool-1-thread-15, num = 140
pool-1-thread-14, num = 130
pool-1-thread-14, num = 141
pool-1-thread-14, num = 142
pool-1-thread-14, num = 143
pool-1-thread-14, num = 144
pool-1-thread-14, num = 145
pool-1-thread-14, num = 146
pool-1-thread-14, num = 147
pool-1-thread-14, num = 148
pool-1-thread-14, num = 149
pool-1-thread-16, num = 150
pool-1-thread-16, num = 151
pool-1-thread-16, num = 152
pool-1-thread-16, num = 153
pool-1-thread-16, num = 154
pool-1-thread-16, num = 155
pool-1-thread-16, num = 156
pool-1-thread-17, num = 157
pool-1-thread-17, num = 159
pool-1-thread-17, num = 160
pool-1-thread-17, num = 161
pool-1-thread-17, num = 162
pool-1-thread-17, num = 163
pool-1-thread-17, num = 164
pool-1-thread-17, num = 165
pool-1-thread-17, num = 166
pool-1-thread-17, num = 167
pool-1-thread-16, num = 158
pool-1-thread-16, num = 168
pool-1-thread-16, num = 169
pool-1-thread-18, num = 170
pool-1-thread-18, num = 171
pool-1-thread-18, num = 172
pool-1-thread-18, num = 173
pool-1-thread-18, num = 174
pool-1-thread-18, num = 175
pool-1-thread-18, num = 176
pool-1-thread-18, num = 177
pool-1-thread-18, num = 178
pool-1-thread-18, num = 179
pool-1-thread-19, num = 180
pool-1-thread-19, num = 182
pool-1-thread-19, num = 183
pool-1-thread-19, num = 184
pool-1-thread-19, num = 185
pool-1-thread-19, num = 186
pool-1-thread-19, num = 187
pool-1-thread-19, num = 188
pool-1-thread-20, num = 181
pool-1-thread-20, num = 189
pool-1-thread-20, num = 190
pool-1-thread-20, num = 191
pool-1-thread-20, num = 192
pool-1-thread-20, num = 193
pool-1-thread-20, num = 194
pool-1-thread-20, num = 195
pool-1-thread-20, num = 196
pool-1-thread-20, num = 197
pool-1-thread-19, num = 198
pool-1-thread-19, num = 199
pool-1-thread-21, num = 200
pool-1-thread-21, num = 201
pool-1-thread-21, num = 202
pool-1-thread-22, num = 203
pool-1-thread-22, num = 204
pool-1-thread-22, num = 205
pool-1-thread-22, num = 206
pool-1-thread-22, num = 207
pool-1-thread-22, num = 209
pool-1-thread-22, num = 210
pool-1-thread-22, num = 211
pool-1-thread-22, num = 212
pool-1-thread-22, num = 213
pool-1-thread-23, num = 208
pool-1-thread-23, num = 215
pool-1-thread-23, num = 216
pool-1-thread-23, num = 217
pool-1-thread-23, num = 218
pool-1-thread-23, num = 219
pool-1-thread-23, num = 220
pool-1-thread-23, num = 221
pool-1-thread-23, num = 222
pool-1-thread-23, num = 223
pool-1-thread-21, num = 214
pool-1-thread-21, num = 224
pool-1-thread-21, num = 225
pool-1-thread-21, num = 226
pool-1-thread-21, num = 227
pool-1-thread-21, num = 228
pool-1-thread-21, num = 229
pool-1-thread-24, num = 230
pool-1-thread-25, num = 231
pool-1-thread-25, num = 232
pool-1-thread-25, num = 233
pool-1-thread-25, num = 234
pool-1-thread-25, num = 235
pool-1-thread-25, num = 236
pool-1-thread-25, num = 237
pool-1-thread-25, num = 238
pool-1-thread-25, num = 239
pool-1-thread-25, num = 240
pool-1-thread-24, num = 241
pool-1-thread-26, num = 242
pool-1-thread-24, num = 243
pool-1-thread-24, num = 244
pool-1-thread-24, num = 246
pool-1-thread-24, num = 247
pool-1-thread-24, num = 248
pool-1-thread-24, num = 249
pool-1-thread-24, num = 250
pool-1-thread-24, num = 251
pool-1-thread-26, num = 245
pool-1-thread-26, num = 252
pool-1-thread-26, num = 253
pool-1-thread-26, num = 254
pool-1-thread-26, num = 255
pool-1-thread-26, num = 256
pool-1-thread-26, num = 257
pool-1-thread-26, num = 258
pool-1-thread-26, num = 259
pool-1-thread-27, num = 260
pool-1-thread-27, num = 261
pool-1-thread-27, num = 262
pool-1-thread-27, num = 263
pool-1-thread-27, num = 264
pool-1-thread-28, num = 265
pool-1-thread-28, num = 267
pool-1-thread-28, num = 268
pool-1-thread-28, num = 269
pool-1-thread-28, num = 270
pool-1-thread-28, num = 271
pool-1-thread-27, num = 266
pool-1-thread-27, num = 274
pool-1-thread-27, num = 275
pool-1-thread-27, num = 276
pool-1-thread-27, num = 277
pool-1-thread-28, num = 272
pool-1-thread-28, num = 278
pool-1-thread-28, num = 280
pool-1-thread-28, num = 281
pool-1-thread-29, num = 282
pool-1-thread-29, num = 283
pool-1-thread-29, num = 284
pool-1-thread-29, num = 285
pool-1-thread-29, num = 286
pool-1-thread-29, num = 287
pool-1-thread-29, num = 288
pool-1-thread-29, num = 289
pool-1-thread-29, num = 290
pool-1-thread-29, num = 291
pool-1-thread-30, num = 273
pool-1-thread-30, num = 292
pool-1-thread-30, num = 293
pool-1-thread-30, num = 294
pool-1-thread-30, num = 295
pool-1-thread-30, num = 296
pool-1-thread-30, num = 297
pool-1-thread-30, num = 298
pool-1-thread-30, num = 299
pool-1-thread-30, num = 300
pool-1-thread-31, num = 279
pool-1-thread-31, num = 301
pool-1-thread-31, num = 302
pool-1-thread-31, num = 303
pool-1-thread-31, num = 304
pool-1-thread-31, num = 305
pool-1-thread-31, num = 306
pool-1-thread-31, num = 307
pool-1-thread-31, num = 308
pool-1-thread-31, num = 309
pool-1-thread-32, num = 310
pool-1-thread-33, num = 311
pool-1-thread-33, num = 312
pool-1-thread-34, num = 313
pool-1-thread-34, num = 314
pool-1-thread-34, num = 315
pool-1-thread-34, num = 316
pool-1-thread-34, num = 317
pool-1-thread-34, num = 318
pool-1-thread-34, num = 319
pool-1-thread-34, num = 321
pool-1-thread-34, num = 322
pool-1-thread-34, num = 323
pool-1-thread-33, num = 320
pool-1-thread-33, num = 324
pool-1-thread-33, num = 325
pool-1-thread-33, num = 326
pool-1-thread-33, num = 327
pool-1-thread-33, num = 328
pool-1-thread-33, num = 329
pool-1-thread-33, num = 330
pool-1-thread-32, num = 331
pool-1-thread-32, num = 332
pool-1-thread-32, num = 333
pool-1-thread-32, num = 334
pool-1-thread-32, num = 335
pool-1-thread-32, num = 336
pool-1-thread-32, num = 337
pool-1-thread-32, num = 338
pool-1-thread-32, num = 339
pool-1-thread-37, num = 340
pool-1-thread-37, num = 341
pool-1-thread-37, num = 342
pool-1-thread-37, num = 343
pool-1-thread-37, num = 344
pool-1-thread-37, num = 345
pool-1-thread-37, num = 346
pool-1-thread-37, num = 347
pool-1-thread-37, num = 348
pool-1-thread-37, num = 349
pool-1-thread-36, num = 340
pool-1-thread-36, num = 350
pool-1-thread-36, num = 351
pool-1-thread-36, num = 352
pool-1-thread-36, num = 353
pool-1-thread-36, num = 354
pool-1-thread-36, num = 355
pool-1-thread-36, num = 356
pool-1-thread-36, num = 357
pool-1-thread-36, num = 358
pool-1-thread-38, num = 359
pool-1-thread-38, num = 360
pool-1-thread-38, num = 361
pool-1-thread-38, num = 362
pool-1-thread-38, num = 363
pool-1-thread-38, num = 364
pool-1-thread-38, num = 365
pool-1-thread-38, num = 366
pool-1-thread-38, num = 367
pool-1-thread-38, num = 368
pool-1-thread-39, num = 369
pool-1-thread-39, num = 370
pool-1-thread-39, num = 371
pool-1-thread-39, num = 372
pool-1-thread-39, num = 374
pool-1-thread-39, num = 375
pool-1-thread-39, num = 376
pool-1-thread-39, num = 377
pool-1-thread-39, num = 379
pool-1-thread-39, num = 380
pool-1-thread-41, num = 381
pool-1-thread-41, num = 382
pool-1-thread-41, num = 383
pool-1-thread-41, num = 384
pool-1-thread-41, num = 385
pool-1-thread-41, num = 386
pool-1-thread-41, num = 387
pool-1-thread-41, num = 388
pool-1-thread-41, num = 389
pool-1-thread-41, num = 390
pool-1-thread-42, num = 391
pool-1-thread-42, num = 392
pool-1-thread-42, num = 393
pool-1-thread-42, num = 394
pool-1-thread-42, num = 395
pool-1-thread-42, num = 396
pool-1-thread-42, num = 397
pool-1-thread-42, num = 398
pool-1-thread-42, num = 399
pool-1-thread-42, num = 400
pool-1-thread-35, num = 373
pool-1-thread-35, num = 401
pool-1-thread-35, num = 402
pool-1-thread-35, num = 403
pool-1-thread-35, num = 404
pool-1-thread-35, num = 405
pool-1-thread-35, num = 406
pool-1-thread-35, num = 407
pool-1-thread-35, num = 408
pool-1-thread-35, num = 409
pool-1-thread-43, num = 410
pool-1-thread-43, num = 411
pool-1-thread-43, num = 412
pool-1-thread-43, num = 413
pool-1-thread-43, num = 414
pool-1-thread-43, num = 415
pool-1-thread-40, num = 378
pool-1-thread-40, num = 417
pool-1-thread-40, num = 418
pool-1-thread-40, num = 419
pool-1-thread-40, num = 420
pool-1-thread-40, num = 421
pool-1-thread-40, num = 422
pool-1-thread-40, num = 423
pool-1-thread-40, num = 424
pool-1-thread-40, num = 425
pool-1-thread-43, num = 416
pool-1-thread-43, num = 426
pool-1-thread-44, num = 427
pool-1-thread-44, num = 429
pool-1-thread-44, num = 430
pool-1-thread-44, num = 431
pool-1-thread-44, num = 432
pool-1-thread-44, num = 433
pool-1-thread-44, num = 434
pool-1-thread-44, num = 435
pool-1-thread-44, num = 436
pool-1-thread-44, num = 437
pool-1-thread-43, num = 428
pool-1-thread-43, num = 438
pool-1-thread-45, num = 439
pool-1-thread-45, num = 440
pool-1-thread-45, num = 441
pool-1-thread-45, num = 442
pool-1-thread-45, num = 443
pool-1-thread-45, num = 444
pool-1-thread-45, num = 445
pool-1-thread-45, num = 446
pool-1-thread-45, num = 447
pool-1-thread-45, num = 448
pool-1-thread-46, num = 442
pool-1-thread-46, num = 449
pool-1-thread-46, num = 450
pool-1-thread-46, num = 451
pool-1-thread-46, num = 452
pool-1-thread-46, num = 453
pool-1-thread-46, num = 454
pool-1-thread-46, num = 455
pool-1-thread-46, num = 456
pool-1-thread-46, num = 457
pool-1-thread-47, num = 458
pool-1-thread-47, num = 459
pool-1-thread-47, num = 460
pool-1-thread-47, num = 461
pool-1-thread-47, num = 462
pool-1-thread-47, num = 463
pool-1-thread-47, num = 464
pool-1-thread-47, num = 465
pool-1-thread-47, num = 466
pool-1-thread-47, num = 467
pool-1-thread-48, num = 468
pool-1-thread-48, num = 469
pool-1-thread-48, num = 471
pool-1-thread-48, num = 472
pool-1-thread-48, num = 473
pool-1-thread-48, num = 474
pool-1-thread-48, num = 475
pool-1-thread-48, num = 476
pool-1-thread-48, num = 477
pool-1-thread-48, num = 478
pool-1-thread-50, num = 470
pool-1-thread-50, num = 479
pool-1-thread-50, num = 480
pool-1-thread-50, num = 481
pool-1-thread-50, num = 483
pool-1-thread-50, num = 484
pool-1-thread-50, num = 485
pool-1-thread-50, num = 486
pool-1-thread-50, num = 487
pool-1-thread-50, num = 488
pool-1-thread-49, num = 482
pool-1-thread-49, num = 489
pool-1-thread-49, num = 490
pool-1-thread-49, num = 491
pool-1-thread-49, num = 492
pool-1-thread-49, num = 493
pool-1-thread-49, num = 494
pool-1-thread-49, num = 495
pool-1-thread-49, num = 496
pool-1-thread-51, num = 497
pool-1-thread-51, num = 499
pool-1-thread-51, num = 500
pool-1-thread-51, num = 501
pool-1-thread-51, num = 502
pool-1-thread-51, num = 503
pool-1-thread-51, num = 504
pool-1-thread-51, num = 505
pool-1-thread-51, num = 506
pool-1-thread-51, num = 507
pool-1-thread-49, num = 498
pool-1-thread-52, num = 508
pool-1-thread-52, num = 509
pool-1-thread-52, num = 511
pool-1-thread-53, num = 510
pool-1-thread-53, num = 513
pool-1-thread-53, num = 514
pool-1-thread-53, num = 515
pool-1-thread-53, num = 516
pool-1-thread-53, num = 517
pool-1-thread-53, num = 518
pool-1-thread-53, num = 519
pool-1-thread-53, num = 520
pool-1-thread-53, num = 521
pool-1-thread-52, num = 512
pool-1-thread-52, num = 522
pool-1-thread-52, num = 523
pool-1-thread-52, num = 524
pool-1-thread-52, num = 525
pool-1-thread-52, num = 526
pool-1-thread-52, num = 527
pool-1-thread-54, num = 528
pool-1-thread-54, num = 529
pool-1-thread-54, num = 530
pool-1-thread-54, num = 531
pool-1-thread-54, num = 532
pool-1-thread-54, num = 533
pool-1-thread-54, num = 534
pool-1-thread-54, num = 535
pool-1-thread-54, num = 536
pool-1-thread-54, num = 537
pool-1-thread-55, num = 538
pool-1-thread-55, num = 539
pool-1-thread-55, num = 540
pool-1-thread-55, num = 541
pool-1-thread-55, num = 542
pool-1-thread-55, num = 543
pool-1-thread-55, num = 544
pool-1-thread-55, num = 545
pool-1-thread-55, num = 546
pool-1-thread-55, num = 547
pool-1-thread-56, num = 548
pool-1-thread-56, num = 549
pool-1-thread-56, num = 550
pool-1-thread-56, num = 551
pool-1-thread-56, num = 552
pool-1-thread-56, num = 553
pool-1-thread-56, num = 554
pool-1-thread-56, num = 555
pool-1-thread-56, num = 556
pool-1-thread-57, num = 557
pool-1-thread-57, num = 559
pool-1-thread-57, num = 560
pool-1-thread-57, num = 561
pool-1-thread-57, num = 562
pool-1-thread-57, num = 563
pool-1-thread-57, num = 564
pool-1-thread-57, num = 565
pool-1-thread-57, num = 566
pool-1-thread-57, num = 567
pool-1-thread-56, num = 558
pool-1-thread-58, num = 568
pool-1-thread-58, num = 569
pool-1-thread-58, num = 570
pool-1-thread-59, num = 572
pool-1-thread-59, num = 573
pool-1-thread-59, num = 574
pool-1-thread-59, num = 575
pool-1-thread-59, num = 576
pool-1-thread-59, num = 577
pool-1-thread-59, num = 578
pool-1-thread-59, num = 579
pool-1-thread-59, num = 580
pool-1-thread-59, num = 581
pool-1-thread-58, num = 571
pool-1-thread-58, num = 582
pool-1-thread-58, num = 583
pool-1-thread-58, num = 584
pool-1-thread-58, num = 585
pool-1-thread-58, num = 586
pool-1-thread-58, num = 587
pool-1-thread-60, num = 588
pool-1-thread-60, num = 589
pool-1-thread-60, num = 590
pool-1-thread-60, num = 591
pool-1-thread-60, num = 592
pool-1-thread-60, num = 593
pool-1-thread-60, num = 594
pool-1-thread-60, num = 595
pool-1-thread-60, num = 596
pool-1-thread-60, num = 597
pool-1-thread-61, num = 598
pool-1-thread-61, num = 599
pool-1-thread-61, num = 600
pool-1-thread-61, num = 601
pool-1-thread-61, num = 602
pool-1-thread-61, num = 603
pool-1-thread-61, num = 604
pool-1-thread-61, num = 605
pool-1-thread-61, num = 606
pool-1-thread-61, num = 607
pool-1-thread-68, num = 608
pool-1-thread-68, num = 610
pool-1-thread-68, num = 611
pool-1-thread-68, num = 612
pool-1-thread-68, num = 613
pool-1-thread-68, num = 614
pool-1-thread-68, num = 615
pool-1-thread-68, num = 616
pool-1-thread-68, num = 617
pool-1-thread-68, num = 618
pool-1-thread-67, num = 609
pool-1-thread-67, num = 620
pool-1-thread-67, num = 621
pool-1-thread-67, num = 622
pool-1-thread-67, num = 623
pool-1-thread-67, num = 624
pool-1-thread-67, num = 625
pool-1-thread-67, num = 626
pool-1-thread-67, num = 627
pool-1-thread-67, num = 629
pool-1-thread-63, num = 619
pool-1-thread-66, num = 631
pool-1-thread-65, num = 633
pool-1-thread-65, num = 635
pool-1-thread-64, num = 630
pool-1-thread-64, num = 638
pool-1-thread-64, num = 639
pool-1-thread-64, num = 640
pool-1-thread-64, num = 641
pool-1-thread-64, num = 642
pool-1-thread-64, num = 643
pool-1-thread-64, num = 644
pool-1-thread-64, num = 645
pool-1-thread-64, num = 646
pool-1-thread-65, num = 637
pool-1-thread-65, num = 648
pool-1-thread-65, num = 649
pool-1-thread-65, num = 650
pool-1-thread-65, num = 651
pool-1-thread-65, num = 652
pool-1-thread-65, num = 653
pool-1-thread-65, num = 654
pool-1-thread-62, num = 628
pool-1-thread-62, num = 657
pool-1-thread-62, num = 658
pool-1-thread-62, num = 659
pool-1-thread-62, num = 660
pool-1-thread-62, num = 661
pool-1-thread-62, num = 662
pool-1-thread-62, num = 663
pool-1-thread-62, num = 664
pool-1-thread-62, num = 665
pool-1-thread-72, num = 666
pool-1-thread-72, num = 667
pool-1-thread-72, num = 668
pool-1-thread-72, num = 669
pool-1-thread-72, num = 670
pool-1-thread-72, num = 671
pool-1-thread-72, num = 672
pool-1-thread-72, num = 673
pool-1-thread-72, num = 674
pool-1-thread-72, num = 675
pool-1-thread-74, num = 676
pool-1-thread-74, num = 677
pool-1-thread-74, num = 678
pool-1-thread-74, num = 679
pool-1-thread-74, num = 680
pool-1-thread-74, num = 682
pool-1-thread-73, num = 656
pool-1-thread-73, num = 685
pool-1-thread-73, num = 686
pool-1-thread-73, num = 687
pool-1-thread-73, num = 688
pool-1-thread-73, num = 689
pool-1-thread-73, num = 690
pool-1-thread-73, num = 691
pool-1-thread-73, num = 692
pool-1-thread-73, num = 693
pool-1-thread-78, num = 694
pool-1-thread-78, num = 695
pool-1-thread-78, num = 696
pool-1-thread-78, num = 697
pool-1-thread-78, num = 698
pool-1-thread-78, num = 699
pool-1-thread-78, num = 700
pool-1-thread-92, num = 701
pool-1-thread-92, num = 704
pool-1-thread-71, num = 655
pool-1-thread-71, num = 706
pool-1-thread-71, num = 707
pool-1-thread-70, num = 647
pool-1-thread-70, num = 710
pool-1-thread-70, num = 712
pool-1-thread-70, num = 713
pool-1-thread-69, num = 636
pool-1-thread-69, num = 716
pool-1-thread-69, num = 718
pool-1-thread-69, num = 719
pool-1-thread-66, num = 634
쓰레드 콜 종료
pool-1-thread-89, num = 725
pool-1-thread-89, num = 726
pool-1-thread-89, num = 727
pool-1-thread-89, num = 728
pool-1-thread-89, num = 729
pool-1-thread-89, num = 730
pool-1-thread-89, num = 731
pool-1-thread-89, num = 732
pool-1-thread-89, num = 733
pool-1-thread-89, num = 734
pool-1-thread-63, num = 632
pool-1-thread-76, num = 738
pool-1-thread-76, num = 741
pool-1-thread-76, num = 742
pool-1-thread-76, num = 743
pool-1-thread-76, num = 744
pool-1-thread-76, num = 745
pool-1-thread-76, num = 746
pool-1-thread-76, num = 747
pool-1-thread-76, num = 748
pool-1-thread-90, num = 737
pool-1-thread-90, num = 750
pool-1-thread-88, num = 735
pool-1-thread-88, num = 754
pool-1-thread-88, num = 755
pool-1-thread-88, num = 756
pool-1-thread-88, num = 757
pool-1-thread-88, num = 758
pool-1-thread-88, num = 759
pool-1-thread-88, num = 760
pool-1-thread-88, num = 761
pool-1-thread-88, num = 762
pool-1-thread-93, num = 736
pool-1-thread-93, num = 763
pool-1-thread-97, num = 765
pool-1-thread-97, num = 766
pool-1-thread-87, num = 724
pool-1-thread-87, num = 769
pool-1-thread-87, num = 770
pool-1-thread-87, num = 771
pool-1-thread-87, num = 772
pool-1-thread-87, num = 774
pool-1-thread-87, num = 775
pool-1-thread-98, num = 776
pool-1-thread-98, num = 778
pool-1-thread-98, num = 779
pool-1-thread-98, num = 780
pool-1-thread-98, num = 781
pool-1-thread-98, num = 782
pool-1-thread-98, num = 783
pool-1-thread-98, num = 784
pool-1-thread-84, num = 723
pool-1-thread-84, num = 787
pool-1-thread-84, num = 788
pool-1-thread-84, num = 790
pool-1-thread-84, num = 791
pool-1-thread-66, num = 722
pool-1-thread-66, num = 793
pool-1-thread-66, num = 794
pool-1-thread-66, num = 795
pool-1-thread-66, num = 796
pool-1-thread-66, num = 797
pool-1-thread-66, num = 798
pool-1-thread-66, num = 799
pool-1-thread-69, num = 721
pool-1-thread-69, num = 800
pool-1-thread-69, num = 801
pool-1-thread-69, num = 802
pool-1-thread-69, num = 803
pool-1-thread-69, num = 804
pool-1-thread-85, num = 720
pool-1-thread-85, num = 805
pool-1-thread-85, num = 806
pool-1-thread-85, num = 807
pool-1-thread-85, num = 808
pool-1-thread-85, num = 809
pool-1-thread-85, num = 810
pool-1-thread-85, num = 811
pool-1-thread-85, num = 812
pool-1-thread-85, num = 813
pool-1-thread-83, num = 717
pool-1-thread-83, num = 814
pool-1-thread-83, num = 815
pool-1-thread-83, num = 816
pool-1-thread-70, num = 715
pool-1-thread-70, num = 818
pool-1-thread-70, num = 819
pool-1-thread-82, num = 714
pool-1-thread-82, num = 821
pool-1-thread-82, num = 822
pool-1-thread-82, num = 823
pool-1-thread-82, num = 824
pool-1-thread-82, num = 825
pool-1-thread-82, num = 826
pool-1-thread-82, num = 827
pool-1-thread-82, num = 828
pool-1-thread-81, num = 711
pool-1-thread-81, num = 830
pool-1-thread-81, num = 831
pool-1-thread-81, num = 832
pool-1-thread-71, num = 709
pool-1-thread-71, num = 834
pool-1-thread-71, num = 835
pool-1-thread-71, num = 836
pool-1-thread-71, num = 837
pool-1-thread-71, num = 838
pool-1-thread-71, num = 839
pool-1-thread-80, num = 708
pool-1-thread-80, num = 840
pool-1-thread-80, num = 841
pool-1-thread-80, num = 842
pool-1-thread-80, num = 843
pool-1-thread-80, num = 844
pool-1-thread-80, num = 845
pool-1-thread-92, num = 705
pool-1-thread-92, num = 847
pool-1-thread-92, num = 848
pool-1-thread-79, num = 703
pool-1-thread-79, num = 850
pool-1-thread-79, num = 851
pool-1-thread-79, num = 852
pool-1-thread-79, num = 853
pool-1-thread-79, num = 854
pool-1-thread-79, num = 855
pool-1-thread-78, num = 702
pool-1-thread-78, num = 857
pool-1-thread-78, num = 858
pool-1-thread-74, num = 684
pool-1-thread-74, num = 859
pool-1-thread-74, num = 860
pool-1-thread-74, num = 861
pool-1-thread-77, num = 683
pool-1-thread-77, num = 862
pool-1-thread-77, num = 863
pool-1-thread-77, num = 864
pool-1-thread-77, num = 865
pool-1-thread-77, num = 866
pool-1-thread-77, num = 867
pool-1-thread-77, num = 868
pool-1-thread-77, num = 869
pool-1-thread-77, num = 870
pool-1-thread-75, num = 681
pool-1-thread-75, num = 871
pool-1-thread-75, num = 872
pool-1-thread-75, num = 873
pool-1-thread-75, num = 874
pool-1-thread-75, num = 875
pool-1-thread-75, num = 876
pool-1-thread-79, num = 856
pool-1-thread-79, num = 878
pool-1-thread-79, num = 879
pool-1-thread-92, num = 849
pool-1-thread-92, num = 880
pool-1-thread-92, num = 881
pool-1-thread-92, num = 882
pool-1-thread-92, num = 883
pool-1-thread-80, num = 846
pool-1-thread-80, num = 884
pool-1-thread-80, num = 885
pool-1-thread-81, num = 833
pool-1-thread-81, num = 886
pool-1-thread-81, num = 887
pool-1-thread-82, num = 829
pool-1-thread-70, num = 820
pool-1-thread-70, num = 889
pool-1-thread-83, num = 817
pool-1-thread-83, num = 891
pool-1-thread-83, num = 892
pool-1-thread-84, num = 792
pool-1-thread-84, num = 894
pool-1-thread-99, num = 789
pool-1-thread-99, num = 896
pool-1-thread-99, num = 897
pool-1-thread-99, num = 898
pool-1-thread-99, num = 899
pool-1-thread-98, num = 786
pool-1-thread-98, num = 901
pool-1-thread-100, num = 785
pool-1-thread-100, num = 902
pool-1-thread-87, num = 777
pool-1-thread-87, num = 904
pool-1-thread-95, num = 773
pool-1-thread-95, num = 906
pool-1-thread-95, num = 907
pool-1-thread-95, num = 908
pool-1-thread-95, num = 909
pool-1-thread-95, num = 910
pool-1-thread-95, num = 911
pool-1-thread-95, num = 912
pool-1-thread-95, num = 913
pool-1-thread-95, num = 914
pool-1-thread-97, num = 768
pool-1-thread-97, num = 915
pool-1-thread-97, num = 916
pool-1-thread-97, num = 917
pool-1-thread-97, num = 918
pool-1-thread-97, num = 919
pool-1-thread-97, num = 920
pool-1-thread-97, num = 921
pool-1-thread-96, num = 767
pool-1-thread-96, num = 922
pool-1-thread-96, num = 923
pool-1-thread-96, num = 924
pool-1-thread-96, num = 925
pool-1-thread-96, num = 926
pool-1-thread-96, num = 927
pool-1-thread-96, num = 928
pool-1-thread-96, num = 929
pool-1-thread-96, num = 930
pool-1-thread-93, num = 764
pool-1-thread-93, num = 931
pool-1-thread-86, num = 753
pool-1-thread-86, num = 933
pool-1-thread-86, num = 934
pool-1-thread-86, num = 935
pool-1-thread-86, num = 936
pool-1-thread-86, num = 937
pool-1-thread-86, num = 938
pool-1-thread-86, num = 939
pool-1-thread-90, num = 752
pool-1-thread-90, num = 941
pool-1-thread-90, num = 942
pool-1-thread-90, num = 943
pool-1-thread-94, num = 751
pool-1-thread-94, num = 945
pool-1-thread-94, num = 946
pool-1-thread-94, num = 947
pool-1-thread-76, num = 749
pool-1-thread-91, num = 740
pool-1-thread-91, num = 949
pool-1-thread-91, num = 950
pool-1-thread-91, num = 951
pool-1-thread-91, num = 952
pool-1-thread-91, num = 953
pool-1-thread-91, num = 954
pool-1-thread-91, num = 955
pool-1-thread-91, num = 956
pool-1-thread-63, num = 739
pool-1-thread-63, num = 958
pool-1-thread-63, num = 959
pool-1-thread-63, num = 960
pool-1-thread-63, num = 961
pool-1-thread-91, num = 957
pool-1-thread-94, num = 948
pool-1-thread-94, num = 963
pool-1-thread-94, num = 964
pool-1-thread-94, num = 965
pool-1-thread-90, num = 944
pool-1-thread-90, num = 967
pool-1-thread-90, num = 968
pool-1-thread-90, num = 969
pool-1-thread-86, num = 940
pool-1-thread-86, num = 970
pool-1-thread-93, num = 932
pool-1-thread-93, num = 971
pool-1-thread-93, num = 972
pool-1-thread-93, num = 973
pool-1-thread-87, num = 905
pool-1-thread-100, num = 903
pool-1-thread-100, num = 975
pool-1-thread-100, num = 976
pool-1-thread-100, num = 977
pool-1-thread-99, num = 900
pool-1-thread-99, num = 979
pool-1-thread-99, num = 980
pool-1-thread-99, num = 981
pool-1-thread-84, num = 895
pool-1-thread-84, num = 983
pool-1-thread-84, num = 984
pool-1-thread-83, num = 893
pool-1-thread-83, num = 985
pool-1-thread-83, num = 986
pool-1-thread-70, num = 890
pool-1-thread-81, num = 888
pool-1-thread-81, num = 987
pool-1-thread-81, num = 988
pool-1-thread-75, num = 877
pool-1-thread-75, num = 989
pool-1-thread-75, num = 990
pool-1-thread-99, num = 982
pool-1-thread-100, num = 978
pool-1-thread-100, num = 991
pool-1-thread-100, num = 992
pool-1-thread-100, num = 993
pool-1-thread-93, num = 974
pool-1-thread-93, num = 994
pool-1-thread-94, num = 966
pool-1-thread-94, num = 995
pool-1-thread-63, num = 962
pool-1-thread-63, num = 996
pool-1-thread-63, num = 997

이런 결과가 나온다.

 

 

pool-1-thread-1 ~ pool-1-thread-100의 쓰레드가 동작한다.

 

 

num을 1000까지 증가시키기위해 100개의 쓰레드드리이 각각 10번의 연산을 한 모습이다.

이때 맨 마지막의 numdl 997로 끝난것을 보아 num의 값들이 순서대로 증가한것이 아니라는 것을 알 수 있는데 이는  num++ 오퍼레시연이 Thread Safe하지 않음을 의미한다. 이에대한 해결방법은 추후에 공부하도록 해보자!

 

 

다시 위의 코드에서 corePoolSize을 1로 설정하고 실행해보자, 즉 쓰레드풀에 기본적으로 1개의쓰레드를 가지고 시작한다는 의미이다.

 

 

결과는 다음과 같다

 

더보기

pool-1-thread-2, num = 0
pool-1-thread-2, num = 3
pool-1-thread-2, num = 4
pool-1-thread-2, num = 5
pool-1-thread-3, num = 2
pool-1-thread-1, num = 1
pool-1-thread-3, num = 7
pool-1-thread-2, num = 6
pool-1-thread-4, num = 10
pool-1-thread-3, num = 9
pool-1-thread-1, num = 8
pool-1-thread-5, num = 14
pool-1-thread-3, num = 13
pool-1-thread-4, num = 12
pool-1-thread-2, num = 11
pool-1-thread-4, num = 18
pool-1-thread-3, num = 17
pool-1-thread-5, num = 16
pool-1-thread-1, num = 15
pool-1-thread-5, num = 22
pool-1-thread-5, num = 24
pool-1-thread-5, num = 26
pool-1-thread-5, num = 27
pool-1-thread-3, num = 21
pool-1-thread-3, num = 29
pool-1-thread-3, num = 30
pool-1-thread-3, num = 31
pool-1-thread-4, num = 20
pool-1-thread-7, num = 33
pool-1-thread-2, num = 19
pool-1-thread-2, num = 36
pool-1-thread-7, num = 35
pool-1-thread-7, num = 38
pool-1-thread-7, num = 39
pool-1-thread-4, num = 34
pool-1-thread-3, num = 32
pool-1-thread-5, num = 28
pool-1-thread-5, num = 43
pool-1-thread-5, num = 45
pool-1-thread-6, num = 25
pool-1-thread-6, num = 47
pool-1-thread-6, num = 48
pool-1-thread-1, num = 23
pool-1-thread-1, num = 50
pool-1-thread-6, num = 49
pool-1-thread-5, num = 46
pool-1-thread-6, num = 52
pool-1-thread-5, num = 53
pool-1-thread-3, num = 44
pool-1-thread-3, num = 57
pool-1-thread-3, num = 58
pool-1-thread-3, num = 59
pool-1-thread-3, num = 60
pool-1-thread-3, num = 61
pool-1-thread-3, num = 62
pool-1-thread-3, num = 63
pool-1-thread-3, num = 64
pool-1-thread-3, num = 65
pool-1-thread-3, num = 66
pool-1-thread-3, num = 67
pool-1-thread-3, num = 68
pool-1-thread-3, num = 69
pool-1-thread-3, num = 70
pool-1-thread-3, num = 71
pool-1-thread-3, num = 72
pool-1-thread-3, num = 74
pool-1-thread-3, num = 75
pool-1-thread-3, num = 76
pool-1-thread-3, num = 77
pool-1-thread-3, num = 78
pool-1-thread-3, num = 79
pool-1-thread-3, num = 80
pool-1-thread-3, num = 81
pool-1-thread-3, num = 82
pool-1-thread-3, num = 83
pool-1-thread-3, num = 84
pool-1-thread-3, num = 85
pool-1-thread-3, num = 86
pool-1-thread-11, num = 87
pool-1-thread-4, num = 42
pool-1-thread-4, num = 90
pool-1-thread-7, num = 41
pool-1-thread-4, num = 91
pool-1-thread-8, num = 40
pool-1-thread-2, num = 37
pool-1-thread-8, num = 94
pool-1-thread-4, num = 93
pool-1-thread-7, num = 92
pool-1-thread-11, num = 89
pool-1-thread-12, num = 88
pool-1-thread-10, num = 73
pool-1-thread-10, num = 101
pool-1-thread-10, num = 102
pool-1-thread-10, num = 103
pool-1-thread-10, num = 104
pool-1-thread-10, num = 106
pool-1-thread-10, num = 107
pool-1-thread-10, num = 108
pool-1-thread-3, num = 109
pool-1-thread-3, num = 111
pool-1-thread-3, num = 112
pool-1-thread-9, num = 55
pool-1-thread-5, num = 56
pool-1-thread-6, num = 54
pool-1-thread-6, num = 117
pool-1-thread-6, num = 118
pool-1-thread-15, num = 119
pool-1-thread-15, num = 121
pool-1-thread-15, num = 122
pool-1-thread-1, num = 51
pool-1-thread-15, num = 123
pool-1-thread-6, num = 120
pool-1-thread-5, num = 116
pool-1-thread-5, num = 127
pool-1-thread-5, num = 128
pool-1-thread-5, num = 129
pool-1-thread-9, num = 115
pool-1-thread-9, num = 132
pool-1-thread-9, num = 133
pool-1-thread-9, num = 134
pool-1-thread-9, num = 135
pool-1-thread-9, num = 136
pool-1-thread-17, num = 137
pool-1-thread-17, num = 139
pool-1-thread-17, num = 140
pool-1-thread-3, num = 114
pool-1-thread-14, num = 113
pool-1-thread-14, num = 143
pool-1-thread-10, num = 110
pool-1-thread-13, num = 105
pool-1-thread-12, num = 100
pool-1-thread-11, num = 99
pool-1-thread-7, num = 98
pool-1-thread-4, num = 97
pool-1-thread-7, num = 150
pool-1-thread-4, num = 151
pool-1-thread-8, num = 96
pool-1-thread-8, num = 154
pool-1-thread-2, num = 95
pool-1-thread-8, num = 155
pool-1-thread-8, num = 158
pool-1-thread-4, num = 153
pool-1-thread-7, num = 152
pool-1-thread-11, num = 149
pool-1-thread-18, num = 147
pool-1-thread-12, num = 148
pool-1-thread-20, num = 164
pool-1-thread-13, num = 146
pool-1-thread-13, num = 167
pool-1-thread-21, num = 168
pool-1-thread-21, num = 171
pool-1-thread-10, num = 145
pool-1-thread-10, num = 172
pool-1-thread-21, num = 173
pool-1-thread-21, num = 175
pool-1-thread-21, num = 176
pool-1-thread-21, num = 177
pool-1-thread-21, num = 178
pool-1-thread-14, num = 144
pool-1-thread-3, num = 142
pool-1-thread-3, num = 181
pool-1-thread-3, num = 182
pool-1-thread-3, num = 183
pool-1-thread-17, num = 141
pool-1-thread-17, num = 185
pool-1-thread-17, num = 186
pool-1-thread-9, num = 138
pool-1-thread-9, num = 189
pool-1-thread-9, num = 190
pool-1-thread-5, num = 131
pool-1-thread-5, num = 192
pool-1-thread-5, num = 193
pool-1-thread-5, num = 194
pool-1-thread-24, num = 195
pool-1-thread-24, num = 197
pool-1-thread-24, num = 198
pool-1-thread-24, num = 199
pool-1-thread-24, num = 200
pool-1-thread-24, num = 201
pool-1-thread-16, num = 130
pool-1-thread-6, num = 126
pool-1-thread-15, num = 125
pool-1-thread-15, num = 205
pool-1-thread-15, num = 206
pool-1-thread-15, num = 207
pool-1-thread-1, num = 124
pool-1-thread-15, num = 208
pool-1-thread-15, num = 210
pool-1-thread-6, num = 204
pool-1-thread-16, num = 203
pool-1-thread-24, num = 202
pool-1-thread-24, num = 215
pool-1-thread-24, num = 216
pool-1-thread-24, num = 217
pool-1-thread-5, num = 196
pool-1-thread-5, num = 219
pool-1-thread-5, num = 220
pool-1-thread-5, num = 221
pool-1-thread-5, num = 223
pool-1-thread-5, num = 224
pool-1-thread-9, num = 191
pool-1-thread-9, num = 226
pool-1-thread-9, num = 227
pool-1-thread-9, num = 228
pool-1-thread-9, num = 229
pool-1-thread-27, num = 230
pool-1-thread-27, num = 232
pool-1-thread-17, num = 188
pool-1-thread-17, num = 234
pool-1-thread-17, num = 235
pool-1-thread-17, num = 236
pool-1-thread-28, num = 237
pool-1-thread-23, num = 187
pool-1-thread-23, num = 239
pool-1-thread-23, num = 240
pool-1-thread-23, num = 241
pool-1-thread-23, num = 242
pool-1-thread-23, num = 243
pool-1-thread-23, num = 244
pool-1-thread-23, num = 245
pool-1-thread-3, num = 184
pool-1-thread-14, num = 180
pool-1-thread-21, num = 179
pool-1-thread-10, num = 174
pool-1-thread-20, num = 166
pool-1-thread-22, num = 170
pool-1-thread-13, num = 169
pool-1-thread-12, num = 165
pool-1-thread-18, num = 163
pool-1-thread-11, num = 162
pool-1-thread-11, num = 257
pool-1-thread-7, num = 161
pool-1-thread-4, num = 160
pool-1-thread-8, num = 159
pool-1-thread-19, num = 156
pool-1-thread-2, num = 157
pool-1-thread-19, num = 262
pool-1-thread-8, num = 261
pool-1-thread-4, num = 260
pool-1-thread-7, num = 259
pool-1-thread-11, num = 258
pool-1-thread-18, num = 256
pool-1-thread-12, num = 255
pool-1-thread-13, num = 254
pool-1-thread-22, num = 253
pool-1-thread-20, num = 252
pool-1-thread-28, num = 250
pool-1-thread-10, num = 251
pool-1-thread-21, num = 249
pool-1-thread-21, num = 276
pool-1-thread-21, num = 277
pool-1-thread-21, num = 278
pool-1-thread-21, num = 279
pool-1-thread-21, num = 280
pool-1-thread-21, num = 281
pool-1-thread-21, num = 282
pool-1-thread-21, num = 283
pool-1-thread-21, num = 284
pool-1-thread-21, num = 285
pool-1-thread-21, num = 286
pool-1-thread-21, num = 287
pool-1-thread-14, num = 248
pool-1-thread-3, num = 247
pool-1-thread-23, num = 246
pool-1-thread-17, num = 238
pool-1-thread-27, num = 233
pool-1-thread-9, num = 231
pool-1-thread-5, num = 225
pool-1-thread-24, num = 222
pool-1-thread-26, num = 218
pool-1-thread-16, num = 214
pool-1-thread-29, num = 298
pool-1-thread-6, num = 213
pool-1-thread-6, num = 300
pool-1-thread-6, num = 301
pool-1-thread-6, num = 302
pool-1-thread-6, num = 303
pool-1-thread-6, num = 304
pool-1-thread-25, num = 212
pool-1-thread-15, num = 211
pool-1-thread-1, num = 209
pool-1-thread-15, num = 308
pool-1-thread-15, num = 310
pool-1-thread-15, num = 311
pool-1-thread-15, num = 312
pool-1-thread-15, num = 313
pool-1-thread-15, num = 314
pool-1-thread-15, num = 315
pool-1-thread-30, num = 316
pool-1-thread-25, num = 307
pool-1-thread-25, num = 319
pool-1-thread-25, num = 320
pool-1-thread-25, num = 321
pool-1-thread-25, num = 322
pool-1-thread-29, num = 306
pool-1-thread-6, num = 305
pool-1-thread-16, num = 299
pool-1-thread-16, num = 326
pool-1-thread-26, num = 297
pool-1-thread-26, num = 329
pool-1-thread-26, num = 330
pool-1-thread-26, num = 331
pool-1-thread-26, num = 332
pool-1-thread-26, num = 333
pool-1-thread-26, num = 334
pool-1-thread-26, num = 335
pool-1-thread-26, num = 336
pool-1-thread-26, num = 337
pool-1-thread-26, num = 338
pool-1-thread-26, num = 339
pool-1-thread-26, num = 340
pool-1-thread-26, num = 341
pool-1-thread-26, num = 342
pool-1-thread-26, num = 343
pool-1-thread-26, num = 344
pool-1-thread-26, num = 345
pool-1-thread-26, num = 346
pool-1-thread-24, num = 296
pool-1-thread-5, num = 295
pool-1-thread-5, num = 349
pool-1-thread-5, num = 350
pool-1-thread-9, num = 294
pool-1-thread-27, num = 293
pool-1-thread-17, num = 292
pool-1-thread-23, num = 291
pool-1-thread-3, num = 290
pool-1-thread-3, num = 355
pool-1-thread-14, num = 289
pool-1-thread-14, num = 357
pool-1-thread-14, num = 358
pool-1-thread-21, num = 288
pool-1-thread-21, num = 361
pool-1-thread-10, num = 275
pool-1-thread-10, num = 363
pool-1-thread-28, num = 274
pool-1-thread-20, num = 273
pool-1-thread-22, num = 272
pool-1-thread-13, num = 271
pool-1-thread-12, num = 270
pool-1-thread-18, num = 269
pool-1-thread-11, num = 268
pool-1-thread-11, num = 371
pool-1-thread-7, num = 267
pool-1-thread-4, num = 266
pool-1-thread-4, num = 374
pool-1-thread-8, num = 265
pool-1-thread-19, num = 264
pool-1-thread-2, num = 263
pool-1-thread-19, num = 377
pool-1-thread-19, num = 380
pool-1-thread-8, num = 376
pool-1-thread-4, num = 375
pool-1-thread-8, num = 382
pool-1-thread-7, num = 373
pool-1-thread-11, num = 372
pool-1-thread-18, num = 370
pool-1-thread-12, num = 369
pool-1-thread-13, num = 368
pool-1-thread-13, num = 388
pool-1-thread-13, num = 389
pool-1-thread-22, num = 367
pool-1-thread-20, num = 366
pool-1-thread-20, num = 393
pool-1-thread-28, num = 365
pool-1-thread-10, num = 364
pool-1-thread-21, num = 362
pool-1-thread-21, num = 397
pool-1-thread-21, num = 398
pool-1-thread-14, num = 360
pool-1-thread-23, num = 359
pool-1-thread-23, num = 401
pool-1-thread-23, num = 402
pool-1-thread-3, num = 356
pool-1-thread-3, num = 404
pool-1-thread-17, num = 354
pool-1-thread-27, num = 353
pool-1-thread-9, num = 352
pool-1-thread-9, num = 408
pool-1-thread-5, num = 351
pool-1-thread-5, num = 410
pool-1-thread-5, num = 411
pool-1-thread-5, num = 412
pool-1-thread-5, num = 413
pool-1-thread-5, num = 414
pool-1-thread-5, num = 417
pool-1-thread-5, num = 418
pool-1-thread-5, num = 419
pool-1-thread-5, num = 420
pool-1-thread-35, num = 421
pool-1-thread-35, num = 422
pool-1-thread-35, num = 424
pool-1-thread-35, num = 425
pool-1-thread-35, num = 426
pool-1-thread-35, num = 427
pool-1-thread-35, num = 428
pool-1-thread-35, num = 429
pool-1-thread-35, num = 431
pool-1-thread-35, num = 432
pool-1-thread-24, num = 348
pool-1-thread-24, num = 433
pool-1-thread-24, num = 434
pool-1-thread-24, num = 436
pool-1-thread-26, num = 347
pool-1-thread-31, num = 328
pool-1-thread-31, num = 439
pool-1-thread-31, num = 442
pool-1-thread-31, num = 443
pool-1-thread-16, num = 327
pool-1-thread-16, num = 446
pool-1-thread-6, num = 325
pool-1-thread-29, num = 324
pool-1-thread-25, num = 323
pool-1-thread-30, num = 318
pool-1-thread-30, num = 451
pool-1-thread-15, num = 317
pool-1-thread-15, num = 453
pool-1-thread-1, num = 309
pool-1-thread-30, num = 452
pool-1-thread-25, num = 450
pool-1-thread-29, num = 449
pool-1-thread-29, num = 457
pool-1-thread-6, num = 448
pool-1-thread-29, num = 459
pool-1-thread-16, num = 447
pool-1-thread-31, num = 445
pool-1-thread-35, num = 444
pool-1-thread-35, num = 463
pool-1-thread-38, num = 440
pool-1-thread-38, num = 465
pool-1-thread-38, num = 466
pool-1-thread-5, num = 441
pool-1-thread-26, num = 438
pool-1-thread-24, num = 437
pool-1-thread-37, num = 435
pool-1-thread-36, num = 430
pool-1-thread-39, num = 423
pool-1-thread-39, num = 473
pool-1-thread-33, num = 415
pool-1-thread-34, num = 416
pool-1-thread-34, num = 476
pool-1-thread-34, num = 477
pool-1-thread-9, num = 409
pool-1-thread-27, num = 407
pool-1-thread-27, num = 480
pool-1-thread-27, num = 481
pool-1-thread-27, num = 482
pool-1-thread-17, num = 406
pool-1-thread-3, num = 405
pool-1-thread-23, num = 403
pool-1-thread-14, num = 400
pool-1-thread-21, num = 399
pool-1-thread-21, num = 488
pool-1-thread-10, num = 396
pool-1-thread-10, num = 491
pool-1-thread-10, num = 493
pool-1-thread-10, num = 494
pool-1-thread-28, num = 395
pool-1-thread-20, num = 394
pool-1-thread-20, num = 496
pool-1-thread-22, num = 392
pool-1-thread-22, num = 498
pool-1-thread-13, num = 391
pool-1-thread-11, num = 390
pool-1-thread-11, num = 500
pool-1-thread-11, num = 501
pool-1-thread-11, num = 502
pool-1-thread-11, num = 503
pool-1-thread-11, num = 504
pool-1-thread-11, num = 505
pool-1-thread-12, num = 387
pool-1-thread-18, num = 386
pool-1-thread-18, num = 509
pool-1-thread-7, num = 385
pool-1-thread-8, num = 384
pool-1-thread-8, num = 511
pool-1-thread-8, num = 513
pool-1-thread-8, num = 514
pool-1-thread-8, num = 515
pool-1-thread-8, num = 516
pool-1-thread-8, num = 517
pool-1-thread-8, num = 518
pool-1-thread-8, num = 519
pool-1-thread-18, num = 520
pool-1-thread-4, num = 383
pool-1-thread-19, num = 381
pool-1-thread-19, num = 524
pool-1-thread-19, num = 526
pool-1-thread-32, num = 379
pool-1-thread-32, num = 528
pool-1-thread-2, num = 378
pool-1-thread-32, num = 529
pool-1-thread-32, num = 531
pool-1-thread-19, num = 527
pool-1-thread-19, num = 533
pool-1-thread-13, num = 534
pool-1-thread-13, num = 536
pool-1-thread-13, num = 537
pool-1-thread-13, num = 538
pool-1-thread-13, num = 539
pool-1-thread-40, num = 525
pool-1-thread-40, num = 542
pool-1-thread-40, num = 544
pool-1-thread-40, num = 545
pool-1-thread-40, num = 546
pool-1-thread-40, num = 547
pool-1-thread-40, num = 548
pool-1-thread-40, num = 549
pool-1-thread-40, num = 550
pool-1-thread-40, num = 551
pool-1-thread-4, num = 523
pool-1-thread-18, num = 522
pool-1-thread-8, num = 521
pool-1-thread-49, num = 557
pool-1-thread-7, num = 512
pool-1-thread-46, num = 510
pool-1-thread-46, num = 560
pool-1-thread-46, num = 561
pool-1-thread-46, num = 562
pool-1-thread-46, num = 563
pool-1-thread-46, num = 564
pool-1-thread-46, num = 565
pool-1-thread-19, num = 566
pool-1-thread-12, num = 508
pool-1-thread-19, num = 568
pool-1-thread-19, num = 570
pool-1-thread-19, num = 571
pool-1-thread-19, num = 572
pool-1-thread-19, num = 573
pool-1-thread-19, num = 574
pool-1-thread-19, num = 575
pool-1-thread-19, num = 577
pool-1-thread-19, num = 578
pool-1-thread-11, num = 507
pool-1-thread-51, num = 579
pool-1-thread-51, num = 581
pool-1-thread-51, num = 582
pool-1-thread-51, num = 584
pool-1-thread-51, num = 585
pool-1-thread-51, num = 586
pool-1-thread-51, num = 587
pool-1-thread-51, num = 588
pool-1-thread-51, num = 589
pool-1-thread-51, num = 590
pool-1-thread-14, num = 506
pool-1-thread-14, num = 592
pool-1-thread-14, num = 594
pool-1-thread-14, num = 595
pool-1-thread-14, num = 596
pool-1-thread-14, num = 597
pool-1-thread-14, num = 598
pool-1-thread-14, num = 599
pool-1-thread-14, num = 600
pool-1-thread-14, num = 601
pool-1-thread-22, num = 499
pool-1-thread-22, num = 602
pool-1-thread-22, num = 603
pool-1-thread-22, num = 604
pool-1-thread-53, num = 605
pool-1-thread-53, num = 606
pool-1-thread-53, num = 607
pool-1-thread-53, num = 609
pool-1-thread-53, num = 610
pool-1-thread-53, num = 611
pool-1-thread-53, num = 612
pool-1-thread-53, num = 613
pool-1-thread-53, num = 614
pool-1-thread-53, num = 615
pool-1-thread-20, num = 497
pool-1-thread-20, num = 616
pool-1-thread-28, num = 495
pool-1-thread-28, num = 617
pool-1-thread-28, num = 618
pool-1-thread-28, num = 619
pool-1-thread-9, num = 492
pool-1-thread-51, num = 622
pool-1-thread-51, num = 624
pool-1-thread-51, num = 625
pool-1-thread-51, num = 626
pool-1-thread-51, num = 627
pool-1-thread-51, num = 628
pool-1-thread-51, num = 629
pool-1-thread-51, num = 630
pool-1-thread-51, num = 631
pool-1-thread-51, num = 632
pool-1-thread-42, num = 490
pool-1-thread-42, num = 634
pool-1-thread-42, num = 635
pool-1-thread-21, num = 489
pool-1-thread-21, num = 637
pool-1-thread-21, num = 638
pool-1-thread-21, num = 639
pool-1-thread-21, num = 640
pool-1-thread-23, num = 487
pool-1-thread-23, num = 642
pool-1-thread-23, num = 643
pool-1-thread-23, num = 645
pool-1-thread-23, num = 646
pool-1-thread-23, num = 647
pool-1-thread-3, num = 486
pool-1-thread-41, num = 485
pool-1-thread-41, num = 649
pool-1-thread-41, num = 650
pool-1-thread-17, num = 484
pool-1-thread-17, num = 653
pool-1-thread-17, num = 654
pool-1-thread-17, num = 655
pool-1-thread-17, num = 656
pool-1-thread-17, num = 657
pool-1-thread-27, num = 483
pool-1-thread-34, num = 479
pool-1-thread-34, num = 658
pool-1-thread-34, num = 659
pool-1-thread-34, num = 660
pool-1-thread-34, num = 661
pool-1-thread-34, num = 662
pool-1-thread-34, num = 663
pool-1-thread-57, num = 664
pool-1-thread-57, num = 666
pool-1-thread-57, num = 667
pool-1-thread-57, num = 668
pool-1-thread-57, num = 669
pool-1-thread-57, num = 670
pool-1-thread-57, num = 672
pool-1-thread-20, num = 673
쓰레드 콜 종료
pool-1-thread-6, num = 478
pool-1-thread-6, num = 676
pool-1-thread-6, num = 677
pool-1-thread-6, num = 678
pool-1-thread-6, num = 679
pool-1-thread-6, num = 680
pool-1-thread-6, num = 681
pool-1-thread-6, num = 682
pool-1-thread-6, num = 683
pool-1-thread-6, num = 684
pool-1-thread-33, num = 475
pool-1-thread-33, num = 685
pool-1-thread-33, num = 686
pool-1-thread-33, num = 687
pool-1-thread-33, num = 688
pool-1-thread-33, num = 689
pool-1-thread-33, num = 690
pool-1-thread-33, num = 691
pool-1-thread-33, num = 692
pool-1-thread-39, num = 474
pool-1-thread-39, num = 693
pool-1-thread-39, num = 694
pool-1-thread-39, num = 695
pool-1-thread-39, num = 696
pool-1-thread-36, num = 472
pool-1-thread-36, num = 699
pool-1-thread-36, num = 700
pool-1-thread-36, num = 701
pool-1-thread-36, num = 702
pool-1-thread-36, num = 703
pool-1-thread-36, num = 704
pool-1-thread-36, num = 705
pool-1-thread-36, num = 706
pool-1-thread-37, num = 471
pool-1-thread-37, num = 707
pool-1-thread-37, num = 708
pool-1-thread-37, num = 709
pool-1-thread-24, num = 470
pool-1-thread-24, num = 711
pool-1-thread-24, num = 712
pool-1-thread-26, num = 469
pool-1-thread-26, num = 713
pool-1-thread-26, num = 714
pool-1-thread-5, num = 468
pool-1-thread-38, num = 467
pool-1-thread-38, num = 717
pool-1-thread-38, num = 718
pool-1-thread-38, num = 719
pool-1-thread-38, num = 720
pool-1-thread-38, num = 721
pool-1-thread-35, num = 464
pool-1-thread-35, num = 723
pool-1-thread-35, num = 724
pool-1-thread-35, num = 725
pool-1-thread-31, num = 462
pool-1-thread-31, num = 727
pool-1-thread-31, num = 728
pool-1-thread-31, num = 729
pool-1-thread-31, num = 730
pool-1-thread-16, num = 461
pool-1-thread-16, num = 731
pool-1-thread-29, num = 460
pool-1-thread-29, num = 732
pool-1-thread-29, num = 733
pool-1-thread-29, num = 734
pool-1-thread-15, num = 458
pool-1-thread-15, num = 735
pool-1-thread-15, num = 736
pool-1-thread-15, num = 737
pool-1-thread-15, num = 738
pool-1-thread-15, num = 739
pool-1-thread-15, num = 740
pool-1-thread-15, num = 741
pool-1-thread-15, num = 742
pool-1-thread-15, num = 743
pool-1-thread-25, num = 456
pool-1-thread-25, num = 744
pool-1-thread-30, num = 455
pool-1-thread-30, num = 745
pool-1-thread-30, num = 746
pool-1-thread-30, num = 747
pool-1-thread-30, num = 748
pool-1-thread-30, num = 749
pool-1-thread-1, num = 454
pool-1-thread-35, num = 726
pool-1-thread-35, num = 750
pool-1-thread-35, num = 751
pool-1-thread-35, num = 752
pool-1-thread-38, num = 722
pool-1-thread-5, num = 716
pool-1-thread-5, num = 753
pool-1-thread-5, num = 754
pool-1-thread-5, num = 755
pool-1-thread-5, num = 756
pool-1-thread-5, num = 757
pool-1-thread-5, num = 758
pool-1-thread-5, num = 759
pool-1-thread-26, num = 715
pool-1-thread-26, num = 760
pool-1-thread-26, num = 761
pool-1-thread-37, num = 710
pool-1-thread-37, num = 763
pool-1-thread-37, num = 764
pool-1-thread-59, num = 698
pool-1-thread-59, num = 766
pool-1-thread-59, num = 767
pool-1-thread-59, num = 768
pool-1-thread-59, num = 769
pool-1-thread-59, num = 770
pool-1-thread-59, num = 771
pool-1-thread-59, num = 772
pool-1-thread-59, num = 773
pool-1-thread-59, num = 774
pool-1-thread-39, num = 697
pool-1-thread-57, num = 675
pool-1-thread-57, num = 776
pool-1-thread-20, num = 674
pool-1-thread-20, num = 778
pool-1-thread-20, num = 779
pool-1-thread-20, num = 780
pool-1-thread-20, num = 781
pool-1-thread-20, num = 782
pool-1-thread-20, num = 783
pool-1-thread-20, num = 784
pool-1-thread-20, num = 785
pool-1-thread-58, num = 671
pool-1-thread-58, num = 786
pool-1-thread-58, num = 787
pool-1-thread-34, num = 665
pool-1-thread-34, num = 789
pool-1-thread-34, num = 790
pool-1-thread-34, num = 791
pool-1-thread-34, num = 792
pool-1-thread-34, num = 793
pool-1-thread-34, num = 794
pool-1-thread-34, num = 795
pool-1-thread-34, num = 796
pool-1-thread-34, num = 797
pool-1-thread-41, num = 652
pool-1-thread-41, num = 798
pool-1-thread-41, num = 799
pool-1-thread-41, num = 800
pool-1-thread-41, num = 801
pool-1-thread-41, num = 802
pool-1-thread-41, num = 803
pool-1-thread-22, num = 651
pool-1-thread-22, num = 804
pool-1-thread-22, num = 805
pool-1-thread-3, num = 648
pool-1-thread-3, num = 807
pool-1-thread-3, num = 808
pool-1-thread-3, num = 809
pool-1-thread-56, num = 644
pool-1-thread-56, num = 810
pool-1-thread-56, num = 811
pool-1-thread-21, num = 641
pool-1-thread-21, num = 813
pool-1-thread-21, num = 814
pool-1-thread-42, num = 636
pool-1-thread-42, num = 816
pool-1-thread-42, num = 817
pool-1-thread-55, num = 633
pool-1-thread-55, num = 819
pool-1-thread-55, num = 820
pool-1-thread-9, num = 623
pool-1-thread-9, num = 822
pool-1-thread-9, num = 823
pool-1-thread-28, num = 621
pool-1-thread-54, num = 620
pool-1-thread-54, num = 825
pool-1-thread-54, num = 826
pool-1-thread-54, num = 827
pool-1-thread-54, num = 828
pool-1-thread-54, num = 829
pool-1-thread-54, num = 830
pool-1-thread-54, num = 831
pool-1-thread-54, num = 832
pool-1-thread-19, num = 608
pool-1-thread-19, num = 834
pool-1-thread-19, num = 835
pool-1-thread-19, num = 836
pool-1-thread-19, num = 837
pool-1-thread-19, num = 838
pool-1-thread-19, num = 839
pool-1-thread-19, num = 840
pool-1-thread-19, num = 841
pool-1-thread-19, num = 842
pool-1-thread-52, num = 593
pool-1-thread-52, num = 843
pool-1-thread-52, num = 844
pool-1-thread-52, num = 845
pool-1-thread-52, num = 846
pool-1-thread-52, num = 847
pool-1-thread-52, num = 848
pool-1-thread-52, num = 849
pool-1-thread-52, num = 850
pool-1-thread-52, num = 851
pool-1-thread-40, num = 591
pool-1-thread-40, num = 852
pool-1-thread-40, num = 853
pool-1-thread-40, num = 854
pool-1-thread-40, num = 855
pool-1-thread-40, num = 856
pool-1-thread-40, num = 857
pool-1-thread-40, num = 858
pool-1-thread-40, num = 859
pool-1-thread-40, num = 860
pool-1-thread-50, num = 583
pool-1-thread-50, num = 861
pool-1-thread-50, num = 862
pool-1-thread-50, num = 863
pool-1-thread-50, num = 864
pool-1-thread-50, num = 865
pool-1-thread-50, num = 866
pool-1-thread-50, num = 867
pool-1-thread-50, num = 868
pool-1-thread-50, num = 869
pool-1-thread-11, num = 580
pool-1-thread-11, num = 870
pool-1-thread-49, num = 576
pool-1-thread-49, num = 871
pool-1-thread-49, num = 872
pool-1-thread-49, num = 873
pool-1-thread-49, num = 874
pool-1-thread-49, num = 875
pool-1-thread-49, num = 876
pool-1-thread-49, num = 877
pool-1-thread-49, num = 878
pool-1-thread-12, num = 569
pool-1-thread-46, num = 567
pool-1-thread-46, num = 879
pool-1-thread-46, num = 880
pool-1-thread-7, num = 559
pool-1-thread-7, num = 881
pool-1-thread-7, num = 882
pool-1-thread-7, num = 883
pool-1-thread-7, num = 884
pool-1-thread-8, num = 558
pool-1-thread-8, num = 885
pool-1-thread-8, num = 886
pool-1-thread-8, num = 887
pool-1-thread-48, num = 556
pool-1-thread-48, num = 889
pool-1-thread-48, num = 890
pool-1-thread-48, num = 891
pool-1-thread-48, num = 892
pool-1-thread-48, num = 893
pool-1-thread-10, num = 555
pool-1-thread-10, num = 895
pool-1-thread-10, num = 896
pool-1-thread-10, num = 897
pool-1-thread-10, num = 898
pool-1-thread-18, num = 554
pool-1-thread-4, num = 553
pool-1-thread-44, num = 552
pool-1-thread-44, num = 900
pool-1-thread-44, num = 901
pool-1-thread-44, num = 902
pool-1-thread-44, num = 903
pool-1-thread-44, num = 904
pool-1-thread-44, num = 905
pool-1-thread-44, num = 906
pool-1-thread-44, num = 907
pool-1-thread-44, num = 908
pool-1-thread-43, num = 543
pool-1-thread-43, num = 909
pool-1-thread-43, num = 910
pool-1-thread-43, num = 911
pool-1-thread-43, num = 912
pool-1-thread-43, num = 913
pool-1-thread-43, num = 914
pool-1-thread-43, num = 915
pool-1-thread-13, num = 541
pool-1-thread-13, num = 917
pool-1-thread-13, num = 918
pool-1-thread-13, num = 919
pool-1-thread-13, num = 920
pool-1-thread-47, num = 540
pool-1-thread-47, num = 921
pool-1-thread-47, num = 922
pool-1-thread-47, num = 923
pool-1-thread-45, num = 535
pool-1-thread-45, num = 925
pool-1-thread-45, num = 926
pool-1-thread-45, num = 927
pool-1-thread-45, num = 928
pool-1-thread-45, num = 929
pool-1-thread-45, num = 930
pool-1-thread-45, num = 931
pool-1-thread-45, num = 932
pool-1-thread-45, num = 933
pool-1-thread-32, num = 532
pool-1-thread-32, num = 934
pool-1-thread-32, num = 935
pool-1-thread-2, num = 530
pool-1-thread-2, num = 937
pool-1-thread-2, num = 938
pool-1-thread-2, num = 939
pool-1-thread-2, num = 940
pool-1-thread-2, num = 941
pool-1-thread-2, num = 942
pool-1-thread-32, num = 936
pool-1-thread-32, num = 943
pool-1-thread-32, num = 944
pool-1-thread-47, num = 924
pool-1-thread-47, num = 945
pool-1-thread-47, num = 946
pool-1-thread-43, num = 916
pool-1-thread-43, num = 948
pool-1-thread-10, num = 899
pool-1-thread-10, num = 949
pool-1-thread-10, num = 950
pool-1-thread-48, num = 894
pool-1-thread-48, num = 952
pool-1-thread-48, num = 953
pool-1-thread-48, num = 954
pool-1-thread-8, num = 888
pool-1-thread-8, num = 955
pool-1-thread-8, num = 956
pool-1-thread-8, num = 957
pool-1-thread-8, num = 958
pool-1-thread-54, num = 833
pool-1-thread-9, num = 824
pool-1-thread-9, num = 959
pool-1-thread-9, num = 960
pool-1-thread-9, num = 961
pool-1-thread-9, num = 962
pool-1-thread-9, num = 963
pool-1-thread-55, num = 821
pool-1-thread-55, num = 964
pool-1-thread-55, num = 965
pool-1-thread-55, num = 966
pool-1-thread-42, num = 818
pool-1-thread-42, num = 968
pool-1-thread-42, num = 969
pool-1-thread-21, num = 815
pool-1-thread-21, num = 971
pool-1-thread-56, num = 812
pool-1-thread-56, num = 973
pool-1-thread-22, num = 806
pool-1-thread-22, num = 975
pool-1-thread-22, num = 976
pool-1-thread-22, num = 977
pool-1-thread-22, num = 978
pool-1-thread-22, num = 979
pool-1-thread-22, num = 980
pool-1-thread-58, num = 788
pool-1-thread-58, num = 981
pool-1-thread-57, num = 777
pool-1-thread-39, num = 775
pool-1-thread-39, num = 983
pool-1-thread-37, num = 765
pool-1-thread-37, num = 984
pool-1-thread-26, num = 762
pool-1-thread-26, num = 985
pool-1-thread-58, num = 982
pool-1-thread-58, num = 986
pool-1-thread-58, num = 987
pool-1-thread-58, num = 988
pool-1-thread-56, num = 974
pool-1-thread-56, num = 990
pool-1-thread-56, num = 991
pool-1-thread-56, num = 992
pool-1-thread-56, num = 993
pool-1-thread-21, num = 972
pool-1-thread-21, num = 994
pool-1-thread-42, num = 970
pool-1-thread-55, num = 967
pool-1-thread-55, num = 995
pool-1-thread-55, num = 996
pool-1-thread-10, num = 951
pool-1-thread-10, num = 997
pool-1-thread-47, num = 947
pool-1-thread-47, num = 998
pool-1-thread-58, num = 989
pool-1-thread-47, num = 999

 

 

이번 실행에서는 60개의쓰레드가 동작한 모습이다.

 

 

corePoolSize가 100일때는 100개의 쓰레드가 10번식 연산을 하였지만 이번에는 60개의 쓰레드가 N번 실행됐다. N은 10의 배수이다. run()의 포문이 10번만큼 돌기 때문에 10의 배수만큼 동작하는 것 같다.

 

 

각 쓰레드들의 동작 횟수를 세어보면 어떤 쓰레드는 10번, 어떤 쓰레드는 30번 이렇게 다 다르다. 이유는 무엇일까?

 

 

이 경우에서 corePoolSize가 1이므로 1개의 쓰레드로 시작하였다. 이 쓰레드의 연산이 끝나기 전에 새로운 task의 요청이 들어오면 쓰레드풀에선 새로운 쓰레드를 생성한다. 하지만 기존 쓰레드의 연산이 끝난 후에 새 task 요청이 들어오면 기존 쓰레드를 재사용하여 task를 수행하기에 몇번 재사용 됐느냐에 따라 각 쓰레드들의 연산 횟수가 결정되는 것이다.


이렇게 초기 corePoolSize를 1로하면 존재하는 쓰레드를 재사용하는 방식으로 최대한 효율적으로 동작하기에 불필요한 쓰레드가 줄어듬으로써 소모되는 메모리를 줄일 수 있다. 하지만 그렇다고 무조건 1로 하면 새로운 쓰레드의 생성에 드는 비용이 늘어날 것이므로 적절한 값을 찾아야 할 것 같다.

간단한 쓰레드 구현

자바에서 쓰레드를 구현하기 위해서는 두가지 방법이 있다. 

1. Runnable 인터페이스를 구현하여 Thread에 생성자로 넣어주기

2. Thread 클래스를 직접 상속받는 클래스 사용하기

 

public class Thread_Basic {
	public static void main(String[] args) {
		/* 쓰레드 구현은 두가지 방법이 있다 
		 * 1. Runnable 인터페이스를 구현 후 Thread 생성자에 넣어주기
		 * 2. Thread 클래스 직접 상속하기
		 * */
         
		//Runnable 구현 후 Thread생성자로 넣어주기 방법
		Runnable task = new Task();
		Thread t1 = new Thread(task);
		t1.start();
		
		//쓰레드 직접 상속하여 구현
		T2 t2 = new T2();
		t2.run();
	}
}

//인터페이스 구현 - 자바에서 다중 상속은 안되기에 
//인터페이스를 구현하는 방법이 조금 더 유연한 프로그래밍이 가능하다
class Task implements Runnable{
	
	int num = 0;
	@Override
	public void run() {
		for(int i=0;i<100;i++) {
			System.out.println("t1: "+num++);
		}
	}
}

//쓰레드를 직접 상속받는 클래스 사용
class T2 extends Thread{
	
	int num = 0;
	@Override
	public void run() {
		for(int i=0;i<100;i++) {
			System.out.println("t2: "+num++);
		}
	}
}

 

결과는 뭐 다들 아시다시피 t1과 t2가 막 섞여서 실행된다

 

그렇다면 쓰레드 100개를 쓰려면

Thread t1 = new Thread(task);

Thread t1 = new Thread(task);

Thread t1 = new Thread(task);

Thread t1 = new Thread(task);

Thread t1 = new Thread(task);

Thread t1 = new Thread(task);

Thread t1 = new Thread(task);

Thread t1 = new Thread(task);

...

하면 될까?

 

너무 비효율적이다. 이럴땐 자바 concurrent패키지의 쓰레드풀(ThreadPoolExecutor)를 사용하면 된다!

 

다음 포스팅에서 계속

자바의 쓰레드, 멀티쓰레드에 대한 공부이다. 이곳 저곳에서 본 것들을 짜집기 하여 내가 보기 좋게 정리한 글이므로 두서없고 정확한 정보인지는 보장할 수 없다! 피드백, 훈수, 아는척은 환영합니다!

 

쓰레드란?

하나의 프로세스 내부에서 독립적으로 실행되는 하나의 작업 단위, 세부적으로는 운영체제에 의해 관리되는 하나의 작업 혹은 테스크를 의미. 

프로세스에서 작업의 단위

그럼 멀티쓰레드는?

하나의 프로세스를 다수의 실행 단위로 구분하여 자원을 공유하고 자원의 생성과 관리의 중복성을 최소화하여 수행 능력을 향상시키는 것을 멀티쓰레딩이라고 한다.

 

그냥 쓰레드 여러개 쓰는 기법을 의미!

 

멀티쓰레드를 사용하는 이유

1. 프로세스를 이용하여 동시에 처리하던 일을 쓰레드로 구현할 경우 메모리 공간과 시스템 자원 소모가 줄어들게 된다.

 

2. 쓰레드 간의 통신이 필요한 경우에도 별도의 자원을 이용하는 것이 아니라 전역 변수의 공간 또는 동적으로 할당된 공간인 힙(Heap) 영역을 이용하여 데이터를 주고받을 수 있다.그렇기 때문에 프로세스 간 통신 방법에 비해 쓰레드 간의 통신 방법이 훨씬 간단하다.

 

3. 심지어 쓰레드의 문맥 교환은 프로세스 문맥 교환과는 달리 캐시 메모리를 비울 필요가 없기 때문에 더 빠르다.

 

4. 따라서 시스템의 처리량이 향상되고 자원 소모가 줄어들어 자연스럽게 프로그램의 응답 시간이 단축된다.

 

이러한 장점 때문에 여러 프로세스로 할 수 있는 작업들을 하나의 프로세스에서 여러 쓰레드로 나눠 수행하는 것이다.

 

 

"일종의 경량화된 프로세스 == 쓰레드"

 

스택영역은 공유X, 힙영역과 데이터영역은 공유O

 

멀티 쓰레딩의 문제점

1. 멀티 프로세스 기반으로 프로그래밍할 때는 프로세스 간 공유하는 자원이 없기 때문에 동일한 자원에 동시에 접근하는 일이 없었지만 멀티 쓰레딩을 기반으로 프로그래밍할 때는 이 부분을 신경써줘야 한다.

 

2. 서로 다른 쓰레드가 데이터와 힙 영역을 공유하기 때문에 어떤 쓰레드가 다른 쓰레드에서 사용중인 변수나 자료 구조에 접근하여 엉뚱한 값을 읽어오거나 수정할 수 있다.

 

3. 그렇기 때문에 멀티쓰레딩 환경에서는 동기화 작업이 필요하다.

 

4. 동기화를 통해 작업 처리 순서를 컨트롤 하고 공유 자원에 대한 접근을 컨트롤 하는 것이다.

 

5. 하지만 이로 인해 병목 현상이 발생하여 성능이 저하될 가능성이 높다.

 

6. 그러므로 과도한 락(lock)으로 인한 병목 현상을 줄여야 한다.

 

7. 공유 자원이 아닌 부분은 동기화 처리를 할 필요가 없다. 즉, 동기화 처리가 필요한 부분에만 synchronized 키워드를 통해 동기화하는 것이다.

 

8. 불필요한 부분까지 동기화를 할 경우 현재 쓰레드는 락(lock)을 획득한 쓰레드가 종료하기 전까지 대기해야한다. 그렇게 되면 전체 성능에 영향을 미치게 된다.

 

9. 즉 동기화를 하고자 할 때는 메소드 전체를 동기화 할 것인가 아니면 특정 부분만 동기화할 것인지 고민해야 한다.

 

 

 

참고: https://goodgid.github.io/What-is-Multi-Thread/

+ Recent posts