JEUS - 8fix1 - Concurrency Utilities For JavaEE Guide

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 28

JEUS

Concurrency Utilities 안내서

JEUS 8 Fix#1

Copyright © 2019 TmaxSoft Co., Ltd. All Rights Reserved.


Copyright Notice

Copyright © 2019 TmaxSoft Co., Ltd. All Rights Reserved.

대한민국 경기도 성남시 분당구 황새울로258번길 29, BS 타워 9층 우)13595

Website

http://www.tmaxsoft.co.kr

기술서비스센터

Tel : +82-1544-8629

E-Mail : info@tmax.co.kr

Restricted Rights Legend

All TmaxSoft Software(JEUS®) and documents are protected by copyright laws and international convention.
TmaxSoft software and documents are made available under the terms of the TmaxSoft License Agreement and
this document may only be distributed or copied in accordance with the terms of this agreement. No part of this
document may be transmitted, copied, deployed, or reproduced in any form or by any means, electronic, mechan
ical, or optical, without the prior written consent of TmaxSoft Co., Ltd. Nothing in this software document and
agreement constitutes a transfer of intellectual property rights regardless of whether or not such rights are registered)
or any rights to TmaxSoft trademarks, logos, or any other brand features.

This document is for information purposes only. The company assumes no direct or indirect responsibilities for
the contents of this document, and does not guarantee that the information contained in this document satisfies
certain legal or commercial conditions. The information contained in this document is subject to change without
prior notice due to product upgrades or updates. The company assumes no liability for any errors in this document.

이 소프트웨어(JEUS®) 사용설명서의 내용과 프로그램은 저작권법과 국제 조약에 의해서 보호받고 있습니다. 사


용설명서의 내용과 여기에 설명된 프로그램은 TmaxSoft Co., Ltd.와의 사용권 계약 하에서만 사용이 가능하며, 사
용설명서는 사용권 계약의 범위 내에서만 배포 또는 복제할 수 있습니다. 이 사용설명서의 전부 또는 일부분을
TmaxSoft의 사전 서면 동의 없이 전자, 기계, 녹음 등의 수단을 사용하여 전송, 복제, 배포, 2차적 저작물작성 등의
행위를 하여서는 안 됩니다.

이 소프트웨어 사용설명서와 프로그램의 사용권 계약은 어떠한 경우에도 사용설명서 및 프로그램과 관련된 지적
재산권(등록 여부를 불문)을 양도하는 것으로 해석되지 아니하며, 브랜드나 로고, 상표 등을 사용할 권한을 부여하
지 않습니다. 사용설명서는 오로지 정보의 제공만을 목적으로 하고, 이로 인한 계약상의 직접적 또는 간접적 책임
을 지지 아니하며, 사용설명서 상의 내용은 법적 또는 상업적인 특정한 조건을 만족시키는 것을 보장하지는 않습
니다. 사용설명서의 내용은 제품의 업그레이드나 수정에 따라 그 내용이 예고 없이 변경될 수 있으며, 내용상의 오
류가 없음을 보장하지 아니합니다.

Trademarks

JEUS® is registered trademark of TmaxSoft Co., Ltd.

JEUS®는 TmaxSoft Co., Ltd.의 등록 상표입니다.


Java and Solaris are registered trademarks of Oracle Corporation and its subsidiaries and affiliates.

Java, Solaris는 Oracle Corporation 및 그 자회사, 관계회사의 등록 상표입니다.

Microsoft, Windows, and Windows NT are registered trademarks or trademarks of Microsoft Corporation.

Microsoft, Windows, Windows NT는 Microsoft Corporation의 등록 상표 또는 상표입니다.

HP-UX is a registered trademark of Hewlett Packard Enterprise Company.

HP-UX는 Hewlett Packard Enterprise Company의 등록 상표입니다.

AIX is a registered trademark of International Business Machines Corporation.

AIX는 International Business Machines Corporation의 등록 상표입니다.

UNIX is a registered trademark of X/Open Company, Ltd.

UNIX는 X/Open Company, Ltd.의 등록 상표입니다.

Linux is a registered trademark of Linus Torvalds.

Linux는 Linus Torvalds의 등록 상표입니다.

Noto is a trademark of Google Inc. Noto fonts are open source. All Noto fonts are published under the SIL Open
Font License, Version 1.1. (https://www.google.com/get/noto/)

Noto는 Google Inc.의 상표입니다. Noto 글꼴은 오픈 소스입니다. 모든 Noto 글꼴은 SIL Open Font License, 버전
1.1에 따라 게시됩니다. (https://www.google.com/get/noto/)

Other products and company names are trademarks or registered trademarks of their respective owners.

기타 모든 제품들과 회사 이름은 각각 해당 소유주의 상호, 상표, 또는 등록 상표입니다.

The names of companies, systems, and products mentioned in this manual may not necessarily be indicated with
a trademark symbol (TM, ®).

본 사용설명서에 기재된 회사, 시스템, 제품 이름 등에 반드시 상표 표시 (TM, ®)를 하지는 않습니다.

Open Source Software Notice

Some modules or files of this product are subject to the terms of the following licenses. : APACHE2.0, CDDL1.0,
EDL1.0, OPEN SYMPHONY SOFTWARE1.1, TRILEAD-SSH2, Bouncy Castle, BSD, MIT, SIL OPEN FONT1.1

Detailed Information related to the license can be found in the following directory : ${INSTALL_PATH}/lib/licenses

본 제품의 일부 파일 또는 모듈은 다음의 라이선스를 준수합니다. : APACHE2.0, CDDL1.0, EDL1.0, OPEN SYM
PHONY SOFTWARE1.1, TRILEAD-SSH2, Bouncy Castle, BSD, MIT, SIL OPEN FONT1.1

관련 상세한 정보는 제품의 다음의 디렉터리에 기재된 사항을 참고해 주십시오. : ${INSTALL_PATH}/lib/licenses

안내서 정보

안내서 제목: JEUS Concurrency Utilities 안내서

발행일: 2019-05-31

소프트웨어 버전: JEUS 8 Fix#1

안내서 버전: v2.1.2


내용 목차
안내서에 대하여 ........................................................................................................................... xi

제1장 Concurrency Utilities for Java EE 표준 ............................................................................ 1


1.1. 개요 ............................................................................................................................ 1
1.2. Managed Task ............................................................................................................. 1
1.3. 컨테이너 스레드 컨텍스트 ............................................................................................. 1

제2장 Managed Objects ............................................................................................................. 3


2.1. ManagedExecutorService ............................................................................................. 3
2.2. ManagedScheduledExecutorService ............................................................................. 5
2.3. ContextService ............................................................................................................ 8
2.4. ManagedThreadFactory .............................................................................................. 10

JEUS v
그림 목차
[그림 2.1] WebAdmin에서 ManagedExecutorService 설정 ............................................................. 5
[그림 2.2] WebAdmin에서 ManagedScheduledExecutorService 설정 ............................................. 7
[그림 2.3] WebAdmin에서 ContextService 설정 ............................................................................. 9
[그림 2.4] WebAdmin에서 ManagedThreadFactory 설정 .............................................................. 11

JEUS vii
예 목차
[예 2.1] ManagedExecutorService를 리소스로 정의한 예제 : <<domain.xml>> ................................ 3
[예 2.2] ManagedExecutorService를 활용한 애플리케이션 예제 ..................................................... 4
[예 2.3] ManagedScheduledExecutorService를 리소스로 정의한 예제 : <<domain.xml>> ................ 6
[예 2.4] ManagedScheduledExecutorService를 활용한 애플리케이션 예제 ..................................... 6
[예 2.5] ContextService를 리소스로 정의한 예제 : <<domain.xml>> ................................................ 8
[예 2.6] ContextService를 활용한 애플리케이션 예제 ..................................................................... 8
[예 2.7] ManagedThreadFactory를 리소스로 정의 예제 : <<domain.xml>> .................................... 10
[예 2.8] ManagedThreadFactory를 활용한 애플리케이션 예제 ...................................................... 10

JEUS ix
안내서에 대하여

안내서의 대상
Concurrency Utilities for Java EE(JSR-236)는 병렬적으로 처리하기 위한 비동기적 작업들을 애플리케이
션 서버가 컨텍스트를 유지하여 실행/관리해주는 표준 기술이다.
®
본 안내서는 JEUS (이하 JEUS)에서 Concurrency Utilities for Java EE 이용하여 개발하고자 하는 개발자
를 대상으로 하고 있다.

안내서의 전제 조건
JEUS의 기본적인 사용법과 제품을 이해하기 위해서는 다음의 안내서를 미리 숙지할 것을 권장한다.

● JEUS 소개

● JEUS 설치 및 시작하기

본 안내서의 모든 예제와 환경 구성은 UNIX의 스타일에 준하여 작성되어 Microsoft Windows™(이하


Windows)와 같이 다른 환경에서 작업하는 경우 몇 가지 사항을 고려해야 한다.

예를 들어 경로 구분자의 경우 UNIX 스타일인 “/”를 Windows 스타일인 “\”로 바꿔서 사용한다. 또한 환경


변수도 Windows 스타일(%%)로 변경해서 사용한다. 본 안내서에 명시된 JEUS_HOME은 JEUS가 설치된
디렉터리이다.

안내서의 제한 조건
본 안내서의 내용은 Java 표준에 준해서 작성되었으나 제품 특성상 언급되는 Java EE나 Java 스펙에 대
해서 자세히 다루지 않는다. 따라서 해당 내용은 Java 관련 문서를 참고한다.

안내서에 대하여 xi
안내서 구성
본 안내서는 총 2개의 장으로 구성되어 있다.

● “제1장 Concurrency Utilities for Java EE 표준”

Concurrency Utilities for Java EE와 JEUS에 대해 설명한다.

● “제2장 Managed Objects”

Managed Objects에 대한 설명과 함께 JEUS에서 ManagedObjects를 활용한 비동기 작업을 수행하는


예제를 설명한다.

xii JEUS Concurrency Utilities 안내서


안내서 규약
표기 의미

<<AaBbCc123>> 프로그램 소스 코드의 파일명

<Ctrl>+C Ctrl과 C를 동시에 누름

[Button] GUI의 버튼 또는 메뉴 이름

진하게 강조

" "(따옴표) 다른 관련 안내서 또는 안내서 내의 다른 장 및 절 언급

'입력항목' 화면 UI에서 입력 항목에 대한 설명

하이퍼링크 메일 계정, 웹 사이트

> 메뉴의 진행 순서

+---- 하위 디렉터리 또는 파일 있음

|---- 하위 디렉터리 또는 파일 없음

참고 또는 주의사항
참고

주의할 사항
주의

[그림 1.1] 그림 이름

[예 1.1] 예제 이름

AaBbCc123 Java 코드, XML 문서

[command argument] 옵션 파라미터

< xyz > ‘<’와 ‘>’ 사이의 내용이 실제 값으로 변경됨

| 선택 사항. 예) A|B: A나 B 중 하나

… 파라미터 등이 반복되어서 나옴

${ } 환경변수

안내서에 대하여 xiii


시스템 사용환경
요구 사항

Platform Solaris 9, 10, 11

HP-UX 11.x, 11i, 11iV2

IBM AIX 5L, 6L, AIX 7L

MS Windows 2008, 2012, Vista, 7, 8

Hardware 최소 2GB 이상 20GB 하드디스크 여유 공간 권장

1GB 이상 메모리 공간 권장

JDK JDK 7, JDK 8

xiv JEUS Concurrency Utilities 안내서


관련 안내서
안내서 설명

JEUS 소개 JEUS 서버에 대한 전반적인 소개와 JEUS의 아키텍처를 포함하여 각


구성 요소들에 대해 설명한 안내서이다.

JEUS 설치 및 시작하기 JEUS에 대한 소개와 설치 및 시작 방법에 대해 기술한 안내서이다.

JEUS Server 안내서 JEUS 시스템과 서버의 개요와 시스템 관리를 위한 안내서이다.

JEUS WebAdmin 안내서 JEUS의 웹 관리 툴인 WebAdmin을 사용한 JEUS의 설정 및 제어, 모니


터링, 클러스터링, 리소스 설정 및 관리에 대해 기술한 안내서이다.

참고 자료
● Concurrency Utilities for Java EE(JSR-236) Specification

안내서에 대하여 xv
제1장 Concurrency Utilities for Java EE 표준

본 장에서는 Concurrency Utilities for Java EE의 등장 배경 및 기술에 대해서 간략하게 설명한다.

1.1. 개요
애플리케이션 서버에서는 EJB나 웹 컴포넌트에서 Java SE에서 제공하는 Concurrency API (Thread,
Timer, ExecutorService, ...)를 이용하는 것을 권하지 않는다. Java EE 애플리케이션 컴포넌트 (Servlet,
EJB 등)는 애플리케이션 서버가 관리하는 스레드에서 실행되고, 같은 스레드에서 컨테이너가 제공하는
기능들이 동작하는 것을 가정한다.

이러한 이유로 APP components는 컨테이너가 관리하지 않는 스레드에서는 Java EE 서비스들을 안전하
게 사용할 수 없다. 또한, 컨테이너가 관리하지 않는 스레드에서 리소스를 이용하게 되면 EE에서 사용성,
보안, 신뢰성, 확장성에 잠재적으로 문제를 일으킬 수 있다.

이와 같은 관리되지 않는(unmanaged) 스레드에 의해 발생하는 문제를 해결하기 위해서 기존 Java SE의


Concurrency Utilities를 확장한 표준화된 Concurrency Utilities for Java EE(JSR-236) 스펙이 제공된다.

이 표준화된 기술을 통해 애플리케이션이 Java EE 환경에서 컨테이너의 integrity를 해치지 않고 동작하


는 것을 보장할 수 있다.

1.2. Managed Task


컨테이너는 필요없는 리소스의 소모를 줄이기 위해 리소스를 풀링(pooling)하고 생명주기를 관리한다. 그
런데 컴포넌트 내에서 Java SE에서 제공되는 Concurrency API를 이용하여 비동기 작업을 수행하면, 컨
테이너가 해당 리소스에 대해서 인지할 수 없기 때문에 관리할 수가 없다.

따라서 본 스펙에서는 기존 Java SE의 java.util.concurrent에 정의된 Task를 확장하여 Managed Task를
정의하였다. 이를 통해 컨테이너가 해당 일반 task를 Managed Task로 관리할 수 있게 되고, 비동기로 작
업이 실행될 때 Execution Context를 유지하여 실행될 수 있도록 한다.

1.3. 컨테이너 스레드 컨텍스트


Java EE 환경에서는 서비스를 실행할 때 각 서비스의 컨텍스트 정보를 가지고 있다. 예를 들면 JDBC에서
의 data sources, JMS에서의 프로바이더와 EJB 등이 있다.

컴포넌트 내에서 Java SE의 Concurrency API를 이용하게 되면, 컨테이너가 새롭게 생성된 스레드에서
서비스의 컨텍스트 정보를 유지하기 위해 애플리케이션 개발자는 다음과 같은 방식으로 컨텍스트를 전파
해야 한다.

1. 애플리케이션 컴포넌트 스레드의 컨테이너 컨텍스트를 저장한다.

제1장 Concurrency Utilities for Java EE 표준 1


2. 어떤 컨테이너 컨텍스트를 저장하고 전파할지 판단한다.

3. 새롭게 생성된 스레드에 컨테이너 컨텍스트를 적용한다.

4. 원래 컴포넌트 스레드의 컨텍스트를 복구한다.

이와 같은 방식으로 작업이 Java SE의 Concurrency API에서 컨텍스트를 유지하면서 동작할 수 있지만,
Concurrency Utilities for Java EE 서비스를 이용하면 간단하게 사용자가 정의한 Task를 Managed Objects
로 전달하여 내부에서 컨텍스트를 알아서 유지/복구하기 때문에 편리하고 안전하다.

컨텍스트를 유지하여 작업을 수행하는 지점


● java.util.concurrent.Callable

– call()

● java.lang.Runnable

– run()

● javax.enterprise.concurrent.ManagedTaskListener

– taskAborted

– taskSubmitted

– taskStarting

● javax.enterprise.concurrent.ManagedTaskListener

– taskAborted

– taskSubmitted

– taskStarting

● javax.enterprise.concurrent.Trigger

– getNextRuntime()

– skipRun()

2 JEUS Concurrency Utilities 안내서


제2장 Managed Objects

본 장에서는 Concurrency Utilities for Java EE에서 제공하는 Managed Objects에 대해서 간략하게 설명
하고 사용 예제를 기술한다.

2.1. ManagedExecutorService
javax.enterprise.concurrent.ManagedExecutorService 인터페이스는 Java SE의 java.util.concurrent.Ex
ecutorService 인터페이스를 상속한다. ExecutorService와 동일하게 비동기 작업을 수행하기 위해 이용되
고, 애플리케이션 서버는 비동기로 실행되는 작업의 컨텍스트 정보를 유지시켜준다.

리소스 정의 예제
다음은 ManagedExecutorService를 리소스로 정의한 예제이다.

[예 2.1] ManagedExecutorService를 리소스로 정의한 예제 : <<domain.xml>>

<domain>
...
<server>
<data-sources>
<data-source>testdb</data-source>
</data-sources>
<managed-executor-service>mes1</managed-executor-service>
</server>

<resources>
<managed-executor-service>
<export-name>mes1</export-name>
<long-running-task>true</long-running-task>
<thread-pool>
<min>10</min>
<max>20</max>
<keep-alive-time>60000</keep-alive-time>
<queue-size>4096</queue-size>
</thread-pool>
</managed-executor-service>
</resources>
...
</domain>

제2장 Managed Objects 3


애플리케이션 예제
다음은 ManagedExecutorService를 활용한 애플리케이션 예제이다.

[예 2.2] ManagedExecutorService를 활용한 애플리케이션 예제

public class AppServlet extends HTTPServlet implements Servlet {


// Retrieve our executor instance.
@Resource(name=mes1”)
ManagedExecutorService mes;

protected void doPost(HttpServletRequest req, HttpServletResponse resp)


throws ServletException, IOException {
ArrayList<Callable> builderTasks = new ArrayList<Callable>();
builderTasks.add(new AccountTask(reqID, accountID));
builderTasks.add(new InsuranceTask(reqID, accountID));

// Submit the tasks and wait.


List<Future<Object>> results = mes.invokeAll(builderTasks);

AccountInfo accountInfo = (AccountInfo) results.get(0).get();


InsuranceInfo insInfo = (InsuranceInfo) results.get(1).get();
// Process the results
}
}

WebAdmin 예제
WebAdmin에서는 왼쪽 메뉴에서 [Resources] > [Concurrency Utilities Resource]를 선택해서 Man
agedExecutorService 설정을 할 수 있다.

4 JEUS Concurrency Utilities 안내서


[그림 2.1] WebAdmin에서 ManagedExecutorService 설정

2.2. ManagedScheduledExecutorService
javax.enterprise.concurrent.ManagedExecutorService 인터페이스는 ManagedExecutorService의 모든
기능을 상속받는 동시에 Java SE의 java.util.concurrent.ScheduledExecutorService의 기능을 상속받아
작업의 지연 실행이나 주기적 실행이 가능하도록 기능을 제공한다. 추가적으로 Trigger와 ManagedTaskLis
tener 인터페이스를 통해 작업의 실행을 제어할 수 있도록 한다.

리소스 정의 예제
다음은 ManagedScheduledExecutorService를 리소스로 정의한 예제이다.

제2장 Managed Objects 5


[예 2.3] ManagedScheduledExecutorService를 리소스로 정의한 예제 : <<domain.xml>>

<domain>
...
<server>
<data-sources>
<data-source>testdb</data-source>
</data-sources>
<managed-scheduled-executor-service>mses1</managed-scheduled-executor-service>

</server>
<resources>
<managed-scheduled-executor-service>
<export-name>mses1</export-name>
<long-running-task>true</long-running-task>
<thread-pool>
<min>10</min>
<max>20</max>
<keep-alive-time>60000</keep-alive-time>
<queue-size>4096</queue-size>
</thread-pool>
</managed-scheduled-executor-service>
</resources>
...
</domain>

애플리케이션 예제
다음은 ManagedScheduledExecutorService를 활용한 애플리케이션 예제이다.

[예 2.4] ManagedScheduledExecutorService를 활용한 애플리케이션 예제

public class AppServlet extends HTTPServlet implements Servlet {


@Resource(name=mses1”)
ManagedScheduledExecutorService mses;

protected void doPost(HttpServletRequest req, HttpServletResponse resp)


throws ServletException, IOException {
Runnable printTask = new Runnable() {
@Override
public void run() {
System.out.println(System.currentTimeMillis());
}
};
// printTask가 5초마다 주기적으로 실행됨
mses.schedule(printTask, 5, TimeUnit.SECONDS);

6 JEUS Concurrency Utilities 안내서


}
}

WebAdmin 예제
WebAdmin 왼쪽 메뉴의 [Resources] > [Concurrency Utilities Resource]에서 ManagedScheduledEx
ecutorService 설정을 할 수 있다.

[그림 2.2] WebAdmin에서 ManagedScheduledExecutorService 설정

제2장 Managed Objects 7


2.3. ContextService
ExecutorService를 이용하지 않고 ContextService를 통해 Managed Task를 생성하는 방식을 제공한다.
본 기능을 이용하여 사용자는 태스크를 만들 때 컨텍스트에 대해서 신경쓰지 않아도 애플리케이션 서버
내부적으로 작업이 실행될 때 컨텍스트를 유지시켜준다. 좀더 상세하게는 Dynamic Proxy를 이용해서 현
재 작업을 실행하기 전에 해당 스레드에 컨텍스트를 설정하고 작업을 수행한다. 모든 작업이 완료되면 컨
텍스트를 복귀하는 작업을 대신 수행한다.

리소스 정의 예제
다음은 ContextService를 리소스로 정의한 예제이다.

[예 2.5] ContextService를 리소스로 정의한 예제 : <<domain.xml>>

<domain>
...
<server>
<data-sources>
<data-source>testdb</data-source>
</data-sources>
<context-service>cs1</context-service>
</server>

<resources>
<context-service>
<export-name>cs1</export-name>
</context-service>
</resources>
...
</domain>

애플리케이션 예제
다음은 ContextService를 활용한 애플리케이션 예제이다.

[예 2.6] ContextService를 활용한 애플리케이션 예제

public class AppServlet extends HTTPServlet implements Servlet {


@Resource(name=cs1”)
ContextService cs;

protected void doPost(HttpServletRequest req, HttpServletResponse resp)


throws ServletException, IOException {
// 일반적인 Runnable task
Runnable simpleTask = new Runnable() {

8 JEUS Concurrency Utilities 안내서


@Override
public void run() {
int sum = 0;
for (int i = 0; i < 10; i++) { sum += i; }
System.out.println(sum);
}
};

// 일반 task를 ContextService를 통해서 Contextual task로 만듦


cs.createContextualProxy(simpleTask, Runnable.class);

// SE에서 제공하는 Executor에 Contextual task를 넘김


ExecutorService es = Executors.newFixedThreadPool(1);
es.submit(simpleTask);
}
}

WebAdmin 예제
WebAdmin 왼쪽 메뉴의 [Resources] > [Concurrency Utilities Resource]에서 ContextService 설정을
할 수 있다.

[그림 2.3] WebAdmin에서 ContextService 설정

제2장 Managed Objects 9


2.4. ManagedThreadFactory
javax.enterprise.concurrent.ManagedThreadFactory 인터페이스는 Java SE의 java.util.concurrent.Thread
Factory 기능을 상속받아 스레드를 생성하는 기능을 제공한다. 일반적으로 ThreadFactory는 ThreadPoolEx
ecutor를 생성할 때 생성자의 파라미터로 넘기는 곳에 사용한다. 따라서, Java SE의 Concurrency API 상
에서도 worker 스레드가 작업을 실행할 때 Task에 대한 컨텍스트를 유지해줄 수 있다.

리소스 정의 예제
다음은 ManagedThreadFactory를 리소스로 정의한 예제이다.

[예 2.7] ManagedThreadFactory를 리소스로 정의 예제 : <<domain.xml>>

<domain>
...
<server>
<data-sources>
<data-source>testdb</data-source>
</data-sources>
<managed-thread-factory>mtf1</managed-thread-factory>
</server>

<resources>
<managed-thread-factory>
<export-name>mtf1</export-name>
<thread-priority>5</thread-priority>
</managed-thread-factory>
</resources>
...
</domain>

애플리케이션 예제
다음은 ManagedThreadFactory를 활용한 애플리케이션 예제이다.

[예 2.8] ManagedThreadFactory를 활용한 애플리케이션 예제

public class AppServlet extends HTTPServlet implements Servlet {


// Retrieve our executor instance.
@Resource(name=mtf1”)
ManagedThreadFactory mtf;

protected void doPost(HttpServletRequest req, HttpServletResponse resp)


throws ServletException, IOException {
// 일반적인 Runnable task

10 JEUS Concurrency Utilities 안내서


Runnable simpleTask = new Runnable() {
@Override
public void run() {
int sum = 0;
for (int i = 0; i < 10; i++) { sum += i; }
System.out.println(sum);
}
};

// simpleTask를 ManagedThreadFactory에서 제공되는 thread에서 실행


mtf.newThread(simpleTask).start();

// 혹은 ThreadPoolExecutor의 매개변수로 ThreadFactory를 전달


Executor e = new ThreadPoolExecutor(5, 10, 6L, TimeUnit.MINUTES, new
ArrayBlockingQueue<Runnable>(4096), mtf);
e.execute(new SimpleTask());
}
}

WebAdmin 예제
WebAdmin에서는 왼쪽 메뉴의 [Resources] > [Concurrency Utilities Resource]에서 ManagedThread
Factory 설정을 할 수 있다.

[그림 2.4] WebAdmin에서 ManagedThreadFactory 설정

제2장 Managed Objects 11

You might also like