WEB开发网
开发学院软件开发Java Eclipse Test and Performance Tools Platform 简... 阅读

Eclipse Test and Performance Tools Platform 简介

 2009-12-19 00:00:00 来源:WEB开发网   
核心提示: 现在完成了!重新启动 Eclipse,在 Eclipse 工具栏上应该会看到一个新按钮,Eclipse Test and Performance Tools Platform 简介(9),如图 1 所示,这是 TPTP Profile 按钮,图 1. TPTP Profile 按钮对 Java

现在完成了!重新启动 Eclipse。在 Eclipse 工具栏上应该会看到一个新按钮,如图 1 所示。这是 TPTP Profile 按钮。TPTP 已经安装了,您可以继续学习本教程了。


图 1. TPTP Profile 按钮
Eclipse Test and Performance Tools Platform 简介

对 Java 应用程序进行分析

既然已经安装了 TPTP 和底层软件,现在就运行 Eclipse。

示例应用程序

要分析的 Java 应用程序见清单 5。



清单 5. 由少量对象组成的简单 Java 应用程序
 
import java.io.BufferedReader; 
import java.io.IOException; 
import java.io.InputStreamReader; 
 
public class SpaceShipToy { 
  /* 
   * To build a spaceship, you need a capsule, a booster, 
   * three stages, and two monkeys (borrowed 
   * from a Barrel of Monkeys). 
   */ 
  public Capsule capsule = new Capsule(); 
  public Booster booster = new Booster(); 
  public Stage[] stage = new Stage[3]; 
   
  public SpaceShipToy() 
  { 
    for (int i = 0; i < 3; i++) 
    stage[i] = new Stage(); 
  } 
 
  private void _killTime(int seconds) 
  { 
    if (seconds <= 0) 
     return; 
     
    for (int i = 0; i < seconds; i++); 
  } 
   
 static final int MINUTE = 60; 
  static final int CAPSULE = 2 * MINUTE; 
  static final int BOOSTER = 5 * MINUTE; 
  static final int STAGE = 3 * MINUTE; 
  static final int MONKEY = 10 * MINUTE; 
   
  class Capsule {  
    public Monkey chimp1 = new Monkey(), chimp2 = new Monkey(); 
 
    public Capsule() { 
     System.out.println("Start building the capsule..."); 
     _killTime(CAPSULE); 
     chimp1.build(); 
     chimp2.build(); 
     System.out.println("Capsule complete."); 
    } 
  } 
   
  class Booster  { 
   public Booster() { 
    System.out.println("Start booster..."); 
    _killTime(BOOSTER); 
    System.out.println("Blast off."); 
   }  
  } 
   
  class Stage { 
   public Stage() { 
    System.out.println("start stage..."); 
    _killTime(STAGE); 
    System.out.println("Stage complete."); 
   }  
  } 
   
  class Monkey { 
   public void start() { 
    System.out.println("Start the monkey business..."); 
   } 
    
   public void build() { 
    start(); 
    _killTime(MONKEY); 
    finish(); 
   } 
    
   public void finish() { 
    System.out.println("Monkey business complete."); 
   } 
  } 
  
  
  public static void main(String[] args) throws java.io.IOException 
  { 
    final int NUMBERTOYS = 9; 
    
    BufferedReader in = new 
     BufferedReader(new InputStreamReader(System.in)); 
    SpaceShipToy[] toys = new SpaceShipToy[NUMBERTOYS]; 
    String input = in.readLine().trim(); 
    
    System.out.println("Toy factory is up and running..."); 
    System.out.flush(); 
 
    for (int i = 0; i < NUMBERTOYS; i++) 
     toys[i] = null; 
     
    while (!input.equalsIgnoreCase("q")) { 
    if (input == null || input.length() != 1 
     || !Character.isDigit(input.charAt(0))) { 
     System.err.println ("Unknown option. Try 0-9, q"); 
     input = in.readLine().trim(); 
     continue; 
    } 
     
    int number = Integer.valueOf(input).intValue(); 
    if (number == 9) { 
     new SpaceShipToy(); 
     System.out.println("Whoops... Lost one..."); 
    } 
    else { 
     if (toys[number] != null) { 
      System.out.println("Shipping toy # " + number); 
      toys[number] = null; 
     } 
     else { 
      System.out.println("Building toy # " + number); 
      toys[number] = new SpaceShipToy(); 
     } 
    } 
     
    input = in.readLine().trim(); 
   } 
 } 
} 

上一页  4 5 6 7 8 9 10  下一页

Tags:Eclipse Test and

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接