View Javadoc

1   /*
2    * $Id: World.java,v 1.2 2011/01/02 15:04:11 oboehm Exp $
3    *
4    * Copyright (c) 2008 by Oliver Boehm
5    *
6    * Licensed under the Apache License, Version 2.0 (the "License");
7    * you may not use this file except in compliance with the License.
8    * You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express orimplied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
17   *
18   * (c)reated 03.01.2009 by oliver (ob@oasd.de)
19   */
20  package patterntesting.sample;
21  
22  import patterntesting.annotation.check.ct.SuppressSystemOutWarning;
23  import patterntesting.runtime.annotation.ProfileMe;
24  import patterntesting.runtime.monitor.ProfileStatistic;
25  
26  /**
27   * This is an example where it makes sense to use System.out or System.err.
28   * And it is an example how to find method which are never used (e.g. the
29   * printBye()-method).
30   *
31   * @author <a href="boehm@javatux.de">oliver</a>
32   * @since 03.01.2009
33   * @version $Revision: 1.2 $
34   */
35  @ProfileMe
36  public class World {
37  
38      /** Utility class - no need to instantiate it. */
39      private World() {}
40      
41      /**
42       * The main method must not be marked with @SuppressSystemOutWarning.
43       * <br/>
44       * Look at the log if main has finished. You should see the values of
45       * the ProfileStatic class. The methods with hits = 0 are the methods
46       * which are never called.
47       *
48       * @param args arguments (will be ignored)
49       */
50      public static void main(final String[] args) {
51          System.out.println("Hello World!");
52          printHelloAgain();
53          ProfileStatistic.addAsShutdownHook();
54          // Let's wait for 5 Minute to have the chance to start 'jconsole'
55          //ThreadUtil.sleep(5, TimeUnit.MINUTES);
56      }
57  
58      @SuppressSystemOutWarning
59      private static void printHelloAgain() {
60          System.out.println("Hello again!");
61      }
62  
63      /**
64       * This is an example of a methode which is never called. Start main
65       * with the VM options (Java 5 only)
66       * -Dcom.sun.management.jmxremote.local.only=false
67       * -Dcom.sun.management.jmxremote
68       * and set a breakpoint at the end of main(). Then start the 'jconsole',
69       * open the patterntesting-MBean "ProfileStatistic" and press
70       * "logStatistic" or "dumpStatistic" as MBean operation.
71       */
72      @SuppressSystemOutWarning
73      public static void printBye() {
74          System.out.println("Bye!");
75      }
76  
77  }