0320 ~ 0402


# 0320 ~ 0402

# 0322 - ํ…Œ์ŠคํŠธ ์ปค๋ฒ„๋ฆฌ์ง€(Test Coverage)

# ํ™”์ดํŠธ ๋ฐ•์Šค ํ…Œ์ŠคํŠธ

  • ํ…Œ์ŠคํŠธ ์ปค๋ฒ„๋ฆฌ์ง€๋Š” ํ™”์ดํŠธ ๋ฐ•์Šค ํ…Œ์ŠคํŠธ์—์„œ ์‚ฌ์šฉ๋˜๋Š” ๊ฐœ๋…
  • ์‘์šฉ ํ”„๋กœ๊ทธ๋žจ์˜ ๋‚ด๋ถ€ ๊ตฌ์กฐ์™€ ๋™์ž‘์„ ๊ฒ€์‚ฌํ•˜๋Š” ์†Œํ”„ํŠธ์›จ์–ด ํ…Œ์ŠคํŠธ ๋ฐฉ์‹, ๊ฐœ๋ฐœ์ž ๊ด€์ ์˜ ๋‹จ์œ„ํ…Œ์ŠคํŒ… ๊ธฐ๋ฒ•
  • ์†Œํ”„ํŠธ์›จ์–ด์˜ ๋™์ž‘์„ ๊ฒ€์‚ฌํ•˜๋Š” ๋ธ”๋ž™๋ฐ•์Šค ํ…Œ์ŠคํŠธ์™€๋Š” ๋ฐ˜๋Œ€๋˜๋Š” ๊ฐœ๋…

# ํ…Œ์ŠคํŠธ ์ปค๋ฒ„๋ฆฌ์ง€๋ž€

  • ๊ฒ€์ฆ ์ค‘์— ์†Œํ”„ํŠธ์›จ์–ด ์ฝ”๋“œ๋ฅผ ์–ผ๋งˆ๋งŒํผ ์‹คํ–‰์‹œ์ผœ ๋ดค๋Š”์ง€์— ๋Œ€ํ•œ ์ฒ™๋„ = ์†Œ์Šค์ฝ”๋“œ ์ˆ˜ํ–‰๋ฅ 
  • ์ „์ฒด ์ฝ”๋“œ ์ค‘์— ํ…Œ์ŠคํŠธ๋กœ ์‹คํ–‰๋œ ์ฝ”๋“œ์˜ ๋น„์œจ๋กœ ํ‘œํ˜„
    • 0%๋ฉด ์‹คํ–‰๋œ ์ฝ”๋“œ๊ฐ€ ์—†๋Š”๊ฒƒ์ด๊ณ  100%๋ฉด ์ „์ฒด ์ฝ”๋“œ๋ฅผ ๋ชจ๋‘ ์‹คํ–‰์‹œ์ผœ ๋ดค๋‹ค๋Š” ๊ฒƒ์„ ์˜๋ฏธ

# ํ…Œ์ŠคํŠธ ์ปค๋ฒ„๋ฆฌ์ง€๋ฅผ ์ธก์ •ํ•ด์•ผํ•˜๋Š” ์ด์œ 

  • ํ…Œ์ŠคํŠธ ์ž‘์—… ์ž์ฒด์˜ ํ’ˆ์งˆ์„ ๊ฐ๊ด€์ /์ •๋Ÿ‰์ ์œผ๋กœ ํ™•์ธ์ด ๊ฐ€๋Šฅ
  • ์ธก์ •๋œ ํ…Œ์ŠคํŠธ ์ปค๋ฒ„๋ฆฌ์ง€๋Š” ํ…Œ์ŠคํŠธ ์ข…๋ฃŒ ์กฐ๊ฑด์œผ๋กœ ํ™œ์šฉ ๊ฐ€๋Šฅ
    • ๊ฐ€์ด๋“œ๋ผ์ธ์ด ๋  ์ˆ˜ ์žˆ์Œ
    • (ex. ์ปค๋ฒ„๋ฆฌ์ง€ 80% ์ด์ƒ์ด๋ฉด ํ…Œ์ŠคํŠธ ์ข…๋ฃŒ)
  • ํ…Œ์ŠคํŠธ ์ปค๋ฒ„๋ฆฌ์ง€ ํšจ๊ณผ
    • ํ…Œ์ŠคํŠธ ์ปค๋ฒ„๋ฆฌ์ง€๊ฐ€ 50%์ผ ๋•Œ 25%์— ๋ถˆ๊ณผํ•˜๋˜ ์˜ค๋ฅ˜ ๊ฒ€์ถœ๋ฅ ์ด ์ปค๋ฒ„๋ฆฌ์ง€ 90%์ผ ๋•Œ๋Š” 79%๊นŒ์ง€ ์ƒ์Šน

# ํ…Œ์ŠคํŠธ ์ปค๋ฒ„๋ฆฌ์ง€์˜ ์ข…๋ฅ˜

  • ๊ตฌ๋ฌธ ์ปค๋ฒ„๋ฆฌ์ง€(Statement Coverage)
    • ์‹คํ–‰๋œ ๋ผ์ธ ์ˆ˜ / ์‹คํ–‰๊ฐ€๋Šฅํ•œ ์ „์ฒด ๋ผ์ธ ์ˆ˜
  • ๊ฒฐ์ • ์ปค๋ฒ„๋ฆฌ์ง€(Branch or Decision Coverage)
    • ๋ถ„๊ธฐ๋งˆ๋‹ค True/False ๊ฐ€๋Šฅํ•œ ๋ชจ๋“  ๊ฒฝ๋กœ๊ฐ€ ์‹คํ–‰๋˜๋Š”์ง€
  • ๋ณ€ํ˜• ์กฐ๊ฑด/ ๊ฒฐ์ • ์ปค๋ฒ„๋ฆฌ์ง€(MC/DC)
    • Multiple condition Coverage์˜ ๋‹จ์ ์„ ๋ณด์™„
    • ๊ฐ ์กฐ๊ฑด์ด ๋…๋ฆฝ์ ์œผ๋กœ ๋ถ„๊ธฐ์˜ ๊ฒฐ๊ณผ์— ์˜ํ–ฅ์„ ๋ฏธ์น˜๋Š” ๊ฒฝ์šฐ๋ฅผ ํ™•์ธ

# ๋†’์€ ํ…Œ์ŠคํŠธ ์ปค๋ฒ„๋ฆฌ์ง€์˜ ์ด์ 

  • ๋ฐฐํฌ ์•ˆ์ •์„ฑ
  • ๋ฆฌํŒฉํ† ๋ง
  • ๋ถˆํ•„์š”ํ•œ ํ”„๋กœ๋•์…˜ ์ฝ”๋“œ ์‚ญ์ œ
  • ํ”„๋กœ๋•์…˜ ์ฝ”๋“œ์— ๋Œ€ํ•œ ์ดํ•ด๋„ ์ƒ์Šน

# 0323 - JVM์˜ default Heap Size

JVM(Java Virutal Machine)์˜ ๊ธฐ๋ณธ ๋ฉ”๋ชจ๋ฆฌ ๊ฐ’์€ ์‚ฌ์šฉ ์ค‘์ธ Java ๋ฒ„์ „์— ๋”ฐ๋ผ ๋‹ค๋ฅด์ง€๋งŒ ๋‹ค์Œ์€ Java 8์„ ๊ธฐ๋ณธ์œผ๋กœ ํ•œ๋‹ค.

# ๋Ÿฐํƒ€์ž„์‹œ ํ™•์ธ

Runtime.getRuntime().maxMemory()
1

# Java Default Heap/Perm Size ํ™•์ธ

  • Linux
java -XX:+PrintFlagsFinal -version 2>&1 | grep -i -E 'heapsize|permsize|version'
1
# java -XX:+PrintFlagsFinal -version 2>&1 | grep -i -E 'heapsize|permsize|version'

    uintx AdaptivePermSizeWeight                    = 20              {product}
    uintx ErgoHeapSizeLimit                         = 0               {product}
    uintx HeapSizePerGCThread                       = 87241520        {product}
    uintx InitialHeapSize                          := 128983616       {product}
    uintx LargePageHeapSizeThreshold                = 134217728       {product}
    uintx MaxHeapSize                              := 2065694720      {product}
    uintx MaxPermSize                               = 174063616       {pd product}
    uintx PermSize                                  = 21757952        {pd product}

java version "1.7.0_79"
1
2
3
4
5
6
7
8
9
10
11
12
  • Windows
java -XX:+PrintFlagsFinal -version 2>&1 | findstr /I "heapsize permsize version"
1
D:\>java -XX:+PrintFlagsFinal -version 2>&1 | findstr /I "heapsize metaspacesize version"

    uintx ErgoHeapSizeLimit                         = 0                                   {product}
    uintx HeapSizePerGCThread                       = 87241520                            {product}
    uintx InitialBootClassLoaderMetaspaceSize       = 4194304                             {product}
    uintx InitialHeapSize                          := 134217728                           {product}
    uintx LargePageHeapSizeThreshold                = 134217728                           {product}
    uintx MaxHeapSize                              := 2147483648                          {product}
    uintx MaxMetaspaceSize                          = 4294901760                          {product}
    uintx MetaspaceSize                             = 21807104                            {pd product}

java version "1.8.0_111"
1
2
3
4
5
6
7
8
9
10
11
12

# ์ดˆ๊ธฐ ๊ฐ’ ๊ธฐ์ค€

jvm์„ server class๋กœ ์‹คํ–‰ํ•˜๋ฉด ์ดˆ๊ธฐ heap size๋Š” ๋ฉ”๋ชจ๋ฆฌ์˜ 1/64 ์ด๊ณ , ์ตœ๋Œ€ heap size๋Š” 1/4๊นŒ์ง€ ๋Š˜์–ด๋‚œ๋‹ค.


# 0329 - Heap ์˜์—ญ์˜ TLAB, PLAB

TLAB ๋ฐ PLAB๋Š” ํž™ ๋ฉ”๋ชจ๋ฆฌ ํ• ๋‹น ์„ฑ๋Šฅ์„ ํ–ฅ์ƒ์‹œํ‚ค๊ธฐ ์œ„ํ•ด JVM์—์„œ ์‚ฌ์šฉ๋˜๋Š” ๋‘ ๊ฐ€์ง€ ๋ฉ”๋ชจ๋ฆฌ ํ• ๋‹น ๊ธฐ์ˆ ์ด๋‹ค.

# TLAB(Thread Local Allocation Buffers)๋ž€ ๋ฌด์—‡์ธ๊ฐ€?

TLAB๋Š” ๊ฐ ์Šค๋ ˆ๋“œ์—์„œ ์ž‘์€ ๊ฐœ์ฒด์— ๋Œ€ํ•œ ๋ฉ”๋ชจ๋ฆฌ๋ฅผ ํ• ๋‹นํ•˜๋Š” ๋ฐ ์‚ฌ์šฉ๋œ๋‹ค. ๊ฐ ์Šค๋ ˆ๋“œ์—๋Š” ์ž์ฒด TLAB๊ฐ€ ์žˆ์–ด ์Šค๋ ˆ๋“œ ๊ฐ„์˜ ๋ฉ”๋ชจ๋ฆฌ ํ• ๋‹น ๊ฒฝํ•ฉ์„ ์ค„์ด๋Š” ๋ฐ ๋„์›€์ด ๋œ๋‹ค. ์Šค๋ ˆ๋“œ๊ฐ€ ๋ฉ”๋ชจ๋ฆฌ๋ฅผ ์š”์ฒญํ•˜๋ฉด JVM์€ ์Šค๋ ˆ๋“œ์˜ TLAB ๋ถ€๋ถ„์„ ์š”์ฒญ์— ํ• ๋‹นํ•œ๋‹ค. TLAB๊ฐ€ ๊ฐ€๋“ ์ฐจ๋ฉด ์Šค๋ ˆ๋“œ๋Š” ํž™์—์„œ ๋ฉ”๋ชจ๋ฆฌ๋ฅผ ์š”์ฒญํ•œ๋‹ค. TLAB๋Š” ์ž‘์€ ๊ฐ์ฒด์— ๋Œ€ํ•œ ๋ฉ”๋ชจ๋ฆฌ ํ• ๋‹น ์„ฑ๋Šฅ์„ ํ–ฅ์ƒ์‹œํ‚ฌ ์ˆ˜ ์žˆ์ง€๋งŒ ํž™ ์กฐ๊ฐํ™”๋ฅผ ์œ ๋ฐœํ•  ์ˆ˜๋„ ์žˆ๋‹ค.

  • Heap ๋ฉ”๋ชจ๋ฆฌ์— ์ƒˆ๋กœ์šด ๊ฐ์ฒด๊ฐ€ ์ƒ์„ฑ๋  ๋•Œ, ๋งŒ์•ฝ TLAB์ด ํ™œ์„ฑํ™”๋˜์–ด ์žˆ๋‹ค๋ฉด ๊ฐ์ฒด๋Š” ์šฐ์„  TLAB์— ์œ„์น˜ํ•˜๊ฒŒ ๋œ๋‹ค.
  • TLAB์€ Eden ์˜์—ญ์—๋งŒ ์กด์žฌํ•œ๋‹ค. ๋”ฐ๋ผ์„œ TLAB์„ ์‚ฌ์šฉํ•˜๋ฉด ์—๋ด ์˜์—ญ์„ ์ข€ ๋” ๋งŽ์ด ์‚ฌ์šฉํ•˜๊ฒŒ ๋˜์ง€๋งŒ ๊ฐ์ฒด ์ƒ์„ฑ์‹œ ์„ฑ๋Šฅ ํšจ๊ณผ๋ฅผ ๋ณผ ์ˆ˜ ์žˆ๋‹ค.
  • ๊ฐ ์Šค๋ ˆ๋“œ๋Š” ๋น ๋ฅธ ๋ฉ”๋ชจ๋ฆฌ ํ• ๋‹น์„ ์œ„ํ•ด ์ž์‹ ๋งŒ์˜ TLAB์„ ๊ฐ€์ง€๊ณ  ์žˆ๋‹ค.
  • ๋”ฐ๋ผ์„œ TLAB์˜ ์ด ํฌ๊ธฐ๋Š” ์Šค๋ ˆ๋“œ ์ˆ˜์— ๋น„๋ก€ํ•œ๋‹ค.
  • TLAB๋ฅผ ์‚ฌ์šฉํ•˜๋ ค๋ฉด -XX:+UseTLAB ์˜ต์…˜์„ ์‚ฌ์šฉํ•œ๋‹ค.
  • TLAB์˜ ํฌ๊ธฐ๋ฅผ ์กฐ์ ˆํ•˜๋ ค๋ฉด -XX:+UseTLAB ์˜ต์…˜์„ ์‚ฌ์šฉํ•œ๋‹ค. ๋””ํดํŠธ๋Š” 0์ธ๋ฐ ์ด๋•Œ๋Š” ์‹œ์Šคํ…œ์ด ์•Œ์•„์„œ ์กฐ์ ˆํ•˜๊ฒŒ ๋œ๋‹ค.

# PLAB(Promotion Local Allocation BUffers)๋ž€ ๋ฌด์—‡์ธ๊ฐ€?

  • GC์—์„œ Generation์„ ์ฒญ์†Œํ•˜๋Š” ๋™์•ˆ ์‚ฌ์šฉ๋œ๋‹ค.
  • ๊ฐ ์Šค๋ ˆ๋“œ์— ์กด์žฌํ•œ๋‹ค.

# 0331 - Java Comparable and Comparator

# ๋ฐฐ์—ด ์ •๋ ฌ

String[] fruits = new String[] {"Pineapple","Apple", "Orange", "Banana"}; 
    
Arrays.sort(fruits);
    
int i=0;
for(String temp: fruits){
    System.out.println("fruits " + ++i + " : " + temp);
}
1
2
3
4
5
6
7
8
fruits 1 : Apple
fruits 2 : Banana
fruits 3 : Orange
fruits 4 : Pineapple
1
2
3
4

# ArrayList ์ •๋ ฌ

List<String> fruits = new ArrayList<String>();
        
fruits.add("Pineapple");
fruits.add("Apple");
fruits.add("Orange");
fruits.add("Banana");

Collections.sort(fruits);
    
int i=0;
for(String temp: fruits){
    System.out.println("fruits " + ++i + " : " + temp);
}
1
2
3
4
5
6
7
8
9
10
11
12
13
fruits 1 : Apple
fruits 2 : Banana
fruits 3 : Orange
fruits 4 : Pineapple
1
2
3
4

# Comparable ์ •๋ ฌ

public class Fruit implements Comparable<Fruit>{
	
	private String fruitName;
	private String fruitDesc;
	private int quantity;

	public int compareTo(Fruit compareFruit) {
			
		//ascending order
		return this.quantity - compareFruit.getQuantity();
		
		//descending order
		//return compareFruit.getQuantity() - this.quantity;
		
	}	
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
public class SortFruitObject{
	
	public static void main(String args[]){

		List<Fruit> fruits = new ArrayList<>();
		
		fruits.add(new Fruit("Pineapple", "Pineapple description",70)); 
		fruits.add(new Fruit("Apple", "Apple description",100)); 
		fruits.add(new Fruit("Orange", "Orange description",80)); 
		fruits.add(new Fruit("Banana", "Banana description",90)); 
		
        Collections.sort(fruits);
	}	
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
fruits 1 : Pineapple, Quantity : 70
fruits 2 : Orange, Quantity : 80
fruits 3 : Banana, Quantity : 90
fruits 4 : Apple, Quantity : 100
1
2
3
4

# Comparator

public class Fruit {
	
	private String fruitName;
	private String fruitDesc;
	private int quantity;

    public static Comparator<Fruit> fruitNameComparator = new Comparator<Fruit>() {

	    public int compare(Fruit fruit1, Fruit fruit2) {
	    	
	      String fruitName1 = fruit1.getFruitName().toUpperCase();
	      String fruitName2 = fruit2.getFruitName().toUpperCase();
	      
	      //ascending order
	      return fruitName1.compareTo(fruitName2);
	      
	      //descending order
	      //return fruitName2.compareTo(fruitName1);
	    }

	};
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
Collections.sort(fruits, Fruit.fruitNameComparator);
1
fruits 1 : Apple, Quantity : 100
fruits 2 : Banana, Quantity : 90
fruits 3 : Orange, Quantity : 80
fruits 4 : Pineapple, Quantity : 70
1
2
3
4

# 0402 - Servlet(์„œ๋ธ”๋ฆฟ)

# Servlet

์„œ๋ธ”๋ฆฟ์„ ํ•œ ์ค„๋กœ ์ •์˜ํ•˜๋ฉด ์•„๋ž˜์™€ ๊ฐ™๋‹ค

ํด๋ผ์ด์–ธํŠธ์˜ ์š”์ฒญ์„ ์ฒ˜๋ฆฌํ•˜๊ณ , ๊ทธ ๊ฒฐ๊ณผ๋ฅผ ๋ฐ˜ํ™˜ํ•˜๋Š” Servlet ํด๋ž˜์Šค์˜ ๊ตฌํ˜„ ๊ทœ์น™์„ ์ง€ํ‚จ ์ž๋ฐ” ์›น ํ”„๋กœ๊ทธ๋ž˜๋ฐ ๊ธฐ์ˆ 

๊ฐ„๋‹จํžˆ ๋งํ•ด์„œ, ์„œ๋ธ”๋ฆฟ์ด๋ž€ ์ž๋ฐ”๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์›น์„ ๋งŒ๋“ค๊ธฐ ์œ„ํ•ด ํ•„์š”ํ•œ ๊ธฐ์ˆ ์ด๋‹ค. ์ข€๋” ์„ค๋ช…ํ•˜๋ฉด ํด๋ผ์ด์–ธํŠธ๊ฐ€ ์–ด๋– ํ•œ ์š”์ฒญ์„ ํ•˜๋ฉด ๊ทธ์— ๋Œ€ํ•œ ๊ฒฐ๊ณผ๋ฅผ ๋‹ค์‹œ ์ „์†กํ•ด์ฃผ์–ด์•ผ ํ•˜๋Š”๋ฐ, ์ด๋Ÿฌํ•œ ์—ญํ• ์„ ํ•˜๋Š” ์ž๋ฐ” ํ”„๋กœ๊ทธ๋žจ์ด๋‹ค.

# ์„œ๋ธ”๋ฆฟ ํŠน์ง•

  • ํด๋ผ์ด์–ธํŠธ์˜ ์š”์ฒญ์— ๋Œ€ํ•ด ๋™์ ์œผ๋กœ ์ž‘๋™ํ•˜๋Š” ์›น ์–ดํ”Œ๋ฆฌ์ผ€์ด์…˜ ์ปดํฌ๋„ŒํŠธ
  • html์„ ์‚ฌ์šฉํ•˜์—ฌ ์š”์ฒญ์— ์‘๋‹ตํ•œ๋‹ค
  • Java Thread๋ฅผ ์ด์šฉํ•˜์—ฌ ๋™์ž‘ํ•œ๋‹ค
  • MVC ํŒจํ„ด์—์„œ Controller๋กœ ์ด์šฉ๋œ๋‹ค
  • HTTP ํ”„๋กœํ† ์ฝœ ์„œ๋น„์Šค๋ฅผ ์ง€์›ํ•˜๋Š” javax.servlet.http.HttpServlet ํด๋ž˜์Šค๋ฅผ ์ƒ์†๋ฐ›๋Š”๋‹ค
  • UDP๋ณด๋‹ค ์ฒ˜๋ฆฌ ์†๋„๊ฐ€ ๋Š๋ฆฌ๋‹ค
  • HTML ๋ณ€๊ฒฝ ์‹œ Servlet์„ ์žฌ์ปดํŒŒ์ผํ•ด์•ผ ํ•˜๋Š” ๋‹จ์ ์ด ์žˆ๋‹ค.

# Servlet ๋™์ž‘ ๋ฐฉ์‹

  1. ์‚ฌ์šฉ์ž(ํด๋ผ์ด์–ธํŠธ)๊ฐ€ URL์„ ์ž…๋ ฅํ•˜๋ฉด HTTP Request๊ฐ€ Servlet Container๋กœ ์ „์†กํ•œ๋‹ค.
  2. ์š”์ฒญ์„ ์ „์†ก๋ฐ›์€ Servlet Container๋Š” HttpServletRequest, HttpServletResponse ๊ฐ์ฒด๋ฅผ ์ƒ์„ฑํ•œ๋‹ค.
  3. web.xml์„ ๊ธฐ๋ฐ˜์œผ๋กœ ์‚ฌ์šฉ์ž๊ฐ€ ์š”์ฒญํ•œ URL์ด ์–ด๋Š ์„œ๋ธ”๋ฆฟ์— ๋Œ€ํ•œ ์š”์ฒญ์ธ์ง€ ์ฐพ๋Š”๋‹ค.
  4. ํ•ด๋‹น ์„œ๋ธ”๋ฆฟ์—์„œ service๋ฉ”์†Œ๋“œ๋ฅผ ํ˜ธ์ถœํ•œ ํ›„ ํด๋ผ์ด์–ธํŠธ์˜ GET, POST์—ฌ๋ถ€์— ๋”ฐ๋ผ doGet() ๋˜๋Š” doPost()๋ฅผ ํ˜ธ์ถœํ•œ๋‹ค.
  5. doGet() or doPost() ๋ฉ”์†Œ๋“œ๋Š” ๋™์  ํŽ˜์ด์ง€๋ฅผ ์ƒ์„ฑํ•œ ํ›„ HttpServletResponse ๊ฐ์ฒด์— ์‘๋‹ต์„ ๋ณด๋‚ธ๋‹ค.
  6. ์‘๋‹ต์ด ๋๋‚˜๋ฉด HttpServletRequest, HttpServletResponse ๋‘ ๊ฐ์ฒด๋ฅผ ์†Œ๋ฉธ์‹œํ‚จ๋‹ค.

# Servlet Container(์„œ๋ธ”๋ฆฟ ์ปจํ…Œ์ด๋„ˆ)

์„œ๋ธ”๋ฆฟ์„ ๊ด€๋ฆฌํ•ด์ฃผ๋Š” ์ปจํ…Œ์ด๋„ˆ

์„œ๋ธ”๋ฆฟ ์ปจํ…Œ์ด๋„ˆ๋Š” ํด๋ผ์ด์–ธํŠธ์˜ ์š”์ฒญ์„ ๋ฐ›์•„์ฃผ๊ณ  ์‘๋‹ตํ•  ์ˆ˜ ์žˆ๊ฒŒ, ์›น์„œ๋ฒ„์™€ ์†Œ์ผ“์œผ๋กœ ํ†ต์‹ ํ•˜๋ฉฐ ๋Œ€ํ‘œ์ ์ธ ์˜ˆ๋กœ ํ†ฐ์บฃ(Tomcat)์ด ์žˆ๋‹ค. ํ†ฐ์บฃ์€ ์‹ค์ œ๋กœ ์›น ์„œ๋ฒ„์™€ ํ†ต์‹ ํ•˜์—ฌ JSP(์ž๋ฐ” ์„œ๋ฒ„ ํŽ˜์ด์ง€)์™€ Servlet์ด ์ž‘๋™ํ•˜๋Š” ํ™˜๊ฒฝ์„ ์ œ๊ณตํ•œ๋‹ค.

# Servlet Container ์—ญํ• 

  • ์›น์„œ๋ฒ„์™€์˜ ํ†ต์‹  ์ง€์›

    • ์„œ๋ธ”๋ฆฟ ์ปจํ…Œ์ด๋„ˆ๋Š” ์„œ๋ธ”๋ฆฟ๊ณผ ์›น์„œ๋ฒ„๊ฐ€ ์†์‰ฝ๊ฒŒ ํ†ต์‹ ํ•  ์ˆ˜ ์žˆ๊ฒŒ ํ•ด์ค€๋‹ค. ์ผ๋ฐ˜์ ์œผ๋กœ ์šฐ๋ฆฌ๋Š” ์†Œ์ผ“์„ ๋งŒ๋“ค๊ณ  listen, accept ๋“ฑ์„ ํ•ด์•ผํ•˜์ง€๋งŒ ์„œ๋ธ”๋ฆฟ ์ปจํ…Œ์ด๋„ˆ๋Š” ์ด๋Ÿฌํ•œ ๊ธฐ๋Šฅ์„ API๋กœ ์ œ๊ณตํ•˜์—ฌ ๋ณต์žกํ•œ ๊ณผ์ •์„ ์ƒ๋žตํ•  ์ˆ˜ ์žˆ๊ฒŒ ํ•ด์ค€๋‹ค. ๊ฐœ๋ฐœ์ž๊ฐ€ ๊ทธ๋ž˜์„œ ๋น„์ง€๋‹ˆ์Šค ๋กœ์ง์— ๋Œ€ํ•ด์„œ๋งŒ ์ดˆ์ ์„ ๋‘๊ฒŒ๋” ๋„์™€์ค€๋‹ค.
  • ์„œ๋ธ”๋ฆฟ ์ƒ๋ช…์ฃผ๊ธฐ(Life Cycle)๊ด€๋ฆฌ

    • ์„œ๋ธ”๋ฆฟ ์ปจํ…Œ์ด๋„ˆ๋Š” ์„œ๋ธ”๋ฆฟ ํƒ„์ƒ๊ณผ ์ฃฝ์Œ์„ ๊ด€๋ฆฌํ•œ๋‹ค. ์„œ๋ธ”๋ฆฟ ํด๋ž˜์Šค๋ฅผ ๋กœ๋”ฉํ•˜์—ฌ ์ธ์Šคํ„ด์Šคํ™”ํ•˜๊ณ , ์ดˆ๊ธฐํ™” ๋ฉ”์†Œ๋“œ๋ฅผ ํ˜ธ์ถœํ•˜๊ณ , ์š”์ฒญ์ด ๋“ค์–ด์˜ค๋ฉด ์ ์ ˆํ•œ ์„œ๋ธ”๋ฆฟ ๋ฉ”์†Œ๋“œ๋ฅผ ํ˜ธ์ถœํ•œ๋‹ค. ๋˜ํ•œ ์„œ๋ธ”๋ฆฟ์ด ์ƒ๋ช…์„ ๋‹ค ํ•œ ์ˆœ๊ฐ„์—๋Š” ์ ์ ˆํ•˜๊ฒŒ ๊ฐ€๋น„์ง€ ์ปฌ๋ ‰์…˜์„ ์ง„ํ–‰์‚ฌ์—ฌ ํŽธ์˜๋ฅผ ์ œ๊ณตํ•œ๋‹ค.
  • ๋ฉ€ํ‹ฐ์“ฐ๋ ˆ๋“œ ์ง€์› ๋ฐ ๊ด€๋ฆฌ

    • ์„œ๋ธ”๋ฆฟ ์ปจํ…Œ์ด๋„ˆ๋Š” ์š”์ฒญ์ด ์˜ฌ ๋•Œ ๋งˆ๋‹ค ์ƒˆ๋กœ์šด ์ž๋ฐ” ์“ฐ๋ ˆ๋“œ๋ฅผ ํ•˜๋‚˜ ์ƒ์„ฑํ•˜๋Š”๋ฐ, HTTP ์„œ๋น„์Šค ๋ฉ”์†Œ๋“œ๋ฅผ ์‹คํ–‰ํ•˜๊ณ  ๋‚˜๋ฉด, ์“ฐ๋ ˆ๋“œ๋Š” ์ž๋™์œผ๋กœ ์ฃฝ๊ฒŒ๋œ๋‹ค. ์›๋ž˜๋Š” ์“ฐ๋ ˆ๋“œ๋ฅผ ๊ด€๋ฆฌํ•ด์•ผ ํ•˜์ง€๋งŒ ์„œ๋ฒ„๊ฐ€ ๋‹ค์ค‘ ์“ฐ๋ ˆ๋“œ๋ฅผ ์ƒ์„ฑ ๋ฐ ์šด์˜ํ•ด์ฃผ๋‹ˆ ์“ฐ๋ ˆ๋“œ์˜ ์•ˆ์ •์„ฑ์— ๋Œ€ํ•ด์„œ ๊ฑฑ์ •ํ•˜์ง€ ์•Š์•„๋„ ๋œ๋‹ค.
  • ์„ ์–ธ์ ์ธ ๋ณด์•ˆ ๊ด€๋ฆฌ

    • ์„œ๋ธ”๋ฆฟ ์ปจํ…Œ์ด๋„ˆ๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด ๊ฐœ๋ฐœ์ž๋Š” ๋ณด์•ˆ์— ๊ด€๋ จ๋œ ๋‚ด์šฉ์„ ์„œ๋ธ”๋ฆฟ ๋˜๋Š” ์ž๋ฐ” ํด๋ž˜์Šค์— ๊ตฌํ˜„ํ•ด ๋†“์ง€ ์•Š์•„๋„ ๋œ๋‹ค. ์ผ๋ฐ˜์ ์œผ๋กœ๋Š” ๋ณด์•ˆ๊ด€๋ฆฌ XML ๋ฐฐํฌ ์„œ์ˆ ์ž์—๋‹ค๊ฐ€ ๊ธฐ๋กํ•˜๋ฏ€๋กœ, ๋ณด์•ˆ์— ๋Œ€ํ•ด ์ˆ˜์ •ํ•  ์ผ์ด ์ƒ๊ฒจ๋„ ์ž๋ฐ” ์ฝ”๋“œ๋ฅผ ์ˆ˜์ •ํ•˜์—ฌ ๋‹ค์‹œ ์ปดํŒŒ์ผ ํ•˜์ง€ ์•Š์•„๋„ ๋ณด์•ˆ๊ด€๋ฆฌ๊ฐ€ ๊ฐ€๋Šฅํ•˜๋‹ค.

# Servlet ์ƒ๋ช…์ฃผ๊ธฐ

image

  1. ํด๋ผ์ด์–ธํŠธ์˜ ์š”์ฒญ์ด ๋“ค์–ด์˜ค๋ฉด ์ปจํ…Œ์ด๋„ˆ๋Š” ํ•ด๋‹น ์„œ๋ธ”๋ฆฟ์ด ๋ฉ”๋ชจ๋ฆฌ์— ์žˆ๋Š”์ง€ ํ™•์ธํ•˜๊ณ  ์—†์„ ๊ฒฝ์šฐ init()๋ฉ”์†Œ๋“œ๋ฅผ ํ˜ธ์ถœํ•˜์—ฌ ์ ์žฌํ•œ๋‹ค. init()๋ฉ”์†Œ๋“œ๋Š” ์ฒ˜์Œ ํ•œ๋ฒˆ๋งŒ ์‹คํ–‰๋˜๊ธฐ ๋•Œ๋ฌธ์—, ์„œ๋ธ”๋ฆฟ์˜ ์“ฐ๋ ˆ๋“œ์—์„œ ๊ณตํ†ต์ ์œผ๋กœ ์‚ฌ์šฉํ•ด์•ผํ•˜๋Š” ๊ฒƒ์ด ์žˆ๋‹ค๋ฉด ์˜ค๋ฒ„๋ผ์ด๋”ฉํ•˜์—ฌ ๊ตฌํ˜„ํ•˜๋ฉด ๋œ๋‹ค. ์‹คํ–‰ ์ค‘ ์„œ๋ธ”๋ฆฟ์ด ๋ณ€๊ฒฝ๋  ๊ฒฝ์šฐ, ๊ธฐ์กด ์„œ๋ธ”๋ฆฟ์„ ํŒŒ๊ดดํ•˜๊ณ  init()์„ ํ†ตํ•ด ์ƒˆ๋กœ์šด ๋‚ด์šฉ์„ ๋‹ค์‹œ ๋ฉ”๋ชจ๋ฆฌ์— ์ ์žฌํ•œ๋‹ค.
  2. init()์ด ํ˜ธ์ถœ๋œ ํ›„ ํด๋ผ์ด์–ธํŠธ์˜ ์š”์ฒญ์— ๋”ฐ๋ผ์„œ service()๋ฉ”์†Œ๋“œ๋ฅผ ํ†ตํ•ด ์š”์ฒญ์— ๋Œ€ํ•œ ์‘๋‹ต์ด doGet()๊ณผ doPost()๋กœ ๋ถ„๊ธฐ๋œ๋‹ค. ์ด๋•Œ ์„œ๋ธ”๋ฆฟ ์ปจํ…Œ์ด๋„ˆ๊ฐ€ ํด๋ผ์ด์–ธํŠธ์˜ ์š”์ฒญ์ด ์˜ค๋ฉด ๊ฐ€์žฅ ๋จผ์ € ์ฒ˜๋ฆฌํ•˜๋Š” ๊ณผ์ •์œผ๋กœ ์ƒ์„ฑ๋œ HttpServletRequest, HttpServletResponse์— ์˜ํ•ด request์™€ response๊ฐ์ฒด๊ฐ€ ์ œ๊ณต๋œ๋‹ค.
  3. ์ปจํ…Œ์ด๋„ˆ๊ฐ€ ์„œ๋ธ”๋ฆฟ์— ์ข…๋ฃŒ ์š”์ฒญ์„ ํ•˜๋ฉด destroy()๋ฉ”์†Œ๋“œ๊ฐ€ ํ˜ธ์ถœ๋˜๋Š”๋ฐ ๋งˆ์ฐฌ๊ฐ€์ง€๋กœ ํ•œ๋ฒˆ๋งŒ ์‹คํ–‰๋˜๋ฉฐ, ์ข…๋ฃŒ์‹œ์— ์ฒ˜๋ฆฌํ•ด์•ผํ•˜๋Š” ์ž‘์—…๋“ค์€ destroy()๋ฉ”์†Œ๋“œ๋ฅผ ์˜ค๋ฒ„๋ผ์ด๋”ฉํ•˜์—ฌ ๊ตฌํ˜„ํ•˜๋ฉด ๋œ๋‹ค.
Last update: April 2, 2023 23:47
Contributors: jaesungahn91