방법: 풀링된 개체의 생성과 크기 및 시간 제한 설정

System.EnterpriseServices.ServicedComponent 클래스에서 파생되는 클래스에 대해서는 COM+ 개체 풀링을 사용하여 개체를 처음부터 인스턴트화하는 오버헤드를 피할 수 있습니다. 대신 개체가 활성화되면 개체를 풀에서 가져오게 됩니다. 자세한 내용은 개체 풀링을 참조하십시오.

풀링된 개체를 만들고 크기와 시간 제한을 설정하려면

  1. System.EnterpriseServices.ServicedComponent 클래스에서 파생되는 클래스를 정의하고 클래스에 ObjectPoolingAttribute 특성을 적용합니다. 예를 들어, 다음 코드에서는 TestObjectPooling이라는 클래스를 정의하고 클래스에 대해 MinPoolSize, MaxPoolSizeCreationTimeout 속성을 설정합니다.

    <ObjectPooling(MinPoolSize := 2, MaxPoolSize := 5, _
    CreationTimeout := 20000)> _
    Public Class TestObjectPooling 
    Inherits ServicedComponent
    End Class 
    
    [ObjectPooling(Enabled=true, MinPoolSize=2, MaxPoolSize=5, CreationTimeout=20000)]
    public class TestObjectPooling : ServicedComponent
    {
    }
    
  2. System.EnterpriseServices.ServicedComponent 클래스의 Activate, DeactivateCanBePooled 메서드를 재정의합니다.

  3. 클라이언트 응용 프로그램에서 풀링된 개체를 테스트합니다.

    1. 풀링된 개체 클래스의 인스턴스를 만들고 풀링된 개체에 있는 메서드를 호출합니다. 예를 들어, 다음 코드에서는 TestObjectPooling 클래스의 인스턴스를 만들고 Perform 메서드를 호출합니다.

      Public Class App
          Overloads Public Shared Sub Main(args() As String)
             Dim order As New TestObjectPooling()
                  order.Perform()
      
      
      public class App
      {
          public static int Main(string[] args)
          {
             TestObjectPooling order = new TestObjectPooling();
             order.Perform();
      
      
    2. DisposeObject 메서드를 호출하여 개체를 풀로 반환합니다.

      ServicedComponent.DisposeObject (order)
      
      ServicedComponent.DisposeObject (order);
      

예제

<ObjectPooling(MinPoolSize := 2, MaxPoolSize := 5, _
CreationTimeout := 20000)> _
Public Class TestObjectPooling 
Inherits ServicedComponent
      Public Sub Perform ()
            ' Method contents go here.
      End Sub 
      Protected Overrides Sub Activate()
            ' Called when removed from the pool.
      End Sub 
      Protected Overrides Sub Deactivate()
            ' Called before deactivating or placing back in pool.
      End Sub 
      Protected Overrides Function CanBePooled() As Boolean
            ' Called after Deactivate. Indicate your vote here.
            Return True
      End Function 
End Class 
[ObjectPooling(Enabled=true, MinPoolSize=2, MaxPoolSize=5, CreationTimeout=20000)]
public class TestObjectPooling : ServicedComponent
{
      public void Perform ()
      {
         // Method contents go here.
      }
      protected override void Activate()
      {
         // Called when removed from the pool.
      }
      protected override void Deactivate()
      {
         // Called before deactivating or placing back in pool.
      }
      protected override bool CanBePooled()
      {
         // Called after Deactivate. Indicate your vote here.
         return true;
      }
}
 

참고 항목

참조

ObjectPoolingAttribute
System.EnterpriseServices Namespace

개념

사용 가능한 COM+ 서비스 요약
개체 풀링

Footer image

Copyright © 2007 by Microsoft Corporation. All rights reserved.