FragmentAtClassScope 예

이 예는 FragmentAtClassScope 프로브 단편의 사용 방법에 대해 설명합니다.

이 예에서 프로브는 "com.sample*" 와일드 카드 패턴에 일치하는 패키지에서 모든 클래스의 작성된 인스턴스 수를 계산하고 백 번째 인스턴스 작성마다 보고합니다.

"클래스 범위의 단편"은 entry 단편이 컴파일되는 클래스에서 정수 유형 정적 필드로 나타나는 계수를 선언합니다. 또한 단편은 프로브 로드를 보고하는 단편 클래스에 대한 정적 초기화 프로그램을 선언합니다. fragmentAtClassScope 섹션에 있는 항목은 프로브를 적용하는 클래스가 아닌, 생성된 프로브 클래스에 빌드됩니다. 프로브를 적용하는 클래스에 정적 필드 또는 정적 초기화 프로그램 논리를 삽입하려면 staticFieldstaticInitializer 객체를 사용하십시오.

이 예 코드를 사용하려면 대상 객체에서 package="com.sample*"가 실제 패키지 이름을 참조하도록 변경하십시오.

XML에서 &< 문자를 사용하려면 &amp;&lt; 문자 엔티티를 예에 표시된 대로 지정해야 합니다.

<?xml version="1.0" encoding="ASCII"?>
<probekit>
   <probe>
      <fragmentAtClassScope>
         static public int entry_counter = 0;
         static int counter = 0;
         static { System.out.println("[fragmentAtClassScope sample probe has loaded.]"); }
      </fragmentAtClassScope>
      <target type="include" package="com.sample*" method="&lt;init>" />
      <target type="exclude" package="*" />
      <fragment type="entry">
         <code>
            ++counter;
            if (counter % 100 == 0)
              System.out.println("[" + counter + " instances of classes in com.sample package so far]");
         </code>
      </fragment>
   </probe>
</probekit>

상위 주제: Probekit 예

관련 참조
FragmentAtClassScope 프로브 객체

이용약관 | 피드백
(C) Copyright IBM Corporation 2000, 2004. All Rights Reserved.