1 // $Header: /home/cvs/jakarta-jmeter/src/jorphan/org/apache/jorphan/timer/TimerFactory.java,v 1.3 2004/02/11 23:57:23 sebb Exp $ 2 /* 3 * Copyright 2002-2004 The Apache Software Foundation. 4 * 5 * Licensed under the Apache License, Version 2.0 (the "License"); 6 * you may not use this file except in compliance with the License. 7 * You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 * 17 */ 18 19 package org.apache.jorphan.timer; 20 21 /** 22 * This non-instantiable non-extendible class acts as a Factory for 23 * {@link ITimer} implementations. 24 * 25 * @author <a HREF="mailto:vroubtsov@illinoisalumni.org">Vlad Roubtsov</a> 26 * @author Originally published in <a HREF="http://www.javaworld.com/javaworld/javaqa/2003-01/01-qa-0110-timing.html">JavaWorld</a> 27 * @version $Revision: 1.3 $ 28 */ 29 public final class TimerFactory 30 { 31 /** 32 * Creates a new instance of {@link ITimer} which is returned in 'ready' 33 * state. If the JNI-based/high-resolution implementation is not available 34 * this will return an instance of <code>JavaSystemTimer</code>, so this 35 * method is guaranteed not to fail. 36 * 37 * @return ITimer a new timer instance in 'ready' state [never null] 38 */ 39 public static ITimer newTimer () 40 { 41 try 42 { 43 return new HRTimer (); 44 } 45 catch (Throwable t) 46 { 47 return new JavaSystemTimer (); 48 } 49 } 50 51 /** 52 * Private default constructor to prevent instantiation. 53 */ 54 private TimerFactory () {} 55 }