Connection Pool

Let's Just Go·2022년 5월 26일
0

JSP

목록 보기
6/12

Connection Pool

JSP

JSP Connection Pool

  • JSP Connection Pool
    • Connection Pool
      • DB 연결 Connectino Pool은 데이터에 대한 요청이 발생하면 재사용 되는 것으로 DB의 수행 능력을 향상시키기 위해 사용

      • 이전에 공부했던 DB Connection은 필요할 때마다 생성해서 사용했는데 Connection Pool은 미리 만들어서 필요할 때 대여 해주고 연산이 끝나면 다시 반환하는 과정 진행

      • Connection Pool에서 하나의 연결이 생성되어 Pool에 배치되면 새로운 Connection이 만들어지지 않도록 재사용하지만, 만약 모든 연결이 사용 중이면 새로운 연결이 만들어져 Pool에 추가

      • Connection pool을 통해 DB연결을 위해 기다리는 시간을 축소해줌

    • Connection Pooling
      - 미리 정해진 개수만큼 DB Connection을 풀에 준비해두고 Application이 요청할 때 마다 Pool에서 꺼내서 할당하고 할당이 끝나면 다시 돌려 받아서 Pool에 넣는 방식
      • DataSource
        • DB에 이용되는 URL, ID, PW, DriverClass를 미리 정의해 놓고 사용하는 객체

Connection Pool 등록

  • Connection Pool 등록
    • Servers → context.xml에 작성
    • Connection pool 정보 등록
       <?xml version="1.0" encoding="UTF-8"?>
       <!--
         Licensed to the Apache Software Foundation (ASF) under one or more
         contributor license agreements.  See the NOTICE file distributed with
         this work for additional information regarding copyright ownership.
         The ASF licenses this file to You under the Apache License, Version 2.0
         (the "License"); you may not use this file except in compliance with
         the License.  You may obtain a copy of the License at
       
             http://www.apache.org/licenses/LICENSE-2.0
       
         Unless required by applicable law or agreed to in writing, software
         distributed under the License is distributed on an "AS IS" BASIS,
         WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
         See the License for the specific language governing permissions and
         limitations under the License.
       --><!-- The contents of this file will be loaded for each web application --><Context>
       
           <!-- Default set of monitored resources. If one of these changes, the    -->
           <!-- web application will be reloaded.                                   -->
           <WatchedResource>WEB-INF/web.xml</WatchedResource>
           <WatchedResource>WEB-INF/tomcat-web.xml</WatchedResource>
           <WatchedResource>${catalina.base}/conf/web.xml</WatchedResource>
       
           <!-- Uncomment this to disable session persistence across Tomcat restarts -->
           <!--
           <Manager pathname="" />
           -->
           
           <Resource 
           	auth = "Container"
           	driverClassName = "oracel.jdbc.driver.OracleDriver"
           	url = "jdbc:oracle:thin:@localhost:1521:xe"
           	username = "아이디"
           	password = "비밀번호"
           	name = "jdbc/myOracle"
           	type = "javax.sql.DataSource"
           	maxActive = "8"
           	maxWait = "1000"
           />
       
       </Context>

    • Connection pool과 DataSource를 통해서 DB연결을 수동으로 하지 않고 context.xml에서 정보를 저장해서 DataSource객체로 더 편리하게 DB연결을 수행할 수 있음

profile
안녕하세요! 공부한 내용을 기록하는 공간입니다.

0개의 댓글