KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > test > performance > standard > OptimizedThroughputTEST


1 /*
2 * JBoss, Home of Professional Open Source
3 * Copyright 2005, JBoss Inc., and individual contributors as indicated
4 * by the @authors tag. See the copyright.txt in the distribution for a
5 * full listing of individual contributors.
6 *
7 * This is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU Lesser General Public License as
9 * published by the Free Software Foundation; either version 2.1 of
10 * the License, or (at your option) any later version.
11 *
12 * This software is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this software; if not, write to the Free
19 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21 */

22 package test.performance.standard;
23
24 import junit.framework.TestCase;
25 import test.performance.PerformanceSUITE;
26 import test.performance.standard.support.Standard;
27
28 import javax.management.*;
29
30 import org.jboss.mx.server.ServerConstants;
31
32
33 public class OptimizedThroughputTEST extends TestCase
34     implements ServerConstants
35 {
36
37    public OptimizedThroughputTEST(String JavaDoc s)
38    {
39       super(s);
40    }
41
42    public void testThroughput() throws Exception JavaDoc
43    {
44    
45       class MyThread implements Runnable JavaDoc
46       {
47
48          private boolean keepRunning = true;
49          
50          public void run()
51          {
52             try
53             {
54                Thread.sleep(PerformanceSUITE.THROUGHPUT_TIME);
55             }
56             catch (InterruptedException JavaDoc e)
57             {
58                
59             }
60             
61             keepRunning = false;
62          }
63          
64          public boolean isKeepRunning()
65          {
66             return keepRunning;
67          }
68       }
69    
70       MyThread myThread = new MyThread();
71       Thread JavaDoc t = new Thread JavaDoc(myThread);
72       Standard std = new Standard();
73
74       String JavaDoc method = "mixedArguments";
75       String JavaDoc[] signature = new String JavaDoc[] {
76                               Integer JavaDoc.class.getName(),
77                               int.class.getName(),
78                               Object JavaDoc[][][].class.getName(),
79                               Attribute.class.getName()
80                            };
81                            
82       Object JavaDoc[] args = new Object JavaDoc[] {
83                               new Integer JavaDoc(1234),
84                               new Integer JavaDoc(455617),
85                               new Object JavaDoc[][][] {
86                                  {
87                                     { "1x1x1", "1x1x2", "1x1x3" },
88                                     { "1x2x1", "1x2x2", "1x2x3" },
89                                     { "1x3x1", "1x3x2", "1x3x3" }
90                                  },
91                                  
92                                  {
93                                     { "2x1x1", "2x1x2", "2x1x3" },
94                                     { "2x2x1", "2x2x2", "2x2x3" },
95                                     { "2x3x1", "2x3x2", "2x3x3" }
96                                  },
97                                  
98                                  {
99                                     { "3x1x1", "3x1x2", "3x1x3" },
100                                     { "3x2x1", "3x2x2", "3x2x3" },
101                                     { "3x3x1", "3x3x2", "3x3x3" }
102                                  }
103                               },
104                               new Attribute("attribute", "value")
105                            };
106    
107       System.setProperty(OPTIMIZE_REFLECTED_DISPATCHER, "true");
108
109       try
110       {
111          MBeanServer server = MBeanServerFactory.createMBeanServer();
112          ObjectName name = new ObjectName("test:test=test");
113       
114          server.registerMBean(std, name);
115          
116          t.start();
117          while(myThread.isKeepRunning())
118          {
119             server.invoke(name, method, args, signature);
120          }
121
122          System.out.println("\nStandard MBean Throughput (OPTIMIZED): " +
123                              std.getCount() / (PerformanceSUITE.THROUGHPUT_TIME / PerformanceSUITE.SECOND) +
124                             " invocations per second.");
125          System.out.println("(Total: " + std.getCount() + ")\n");
126       }
127       finally
128       {
129          System.setProperty(OPTIMIZE_REFLECTED_DISPATCHER, "false");
130       }
131    }
132
133    
134 }
135
Popular Tags