001/* 002 * Copyright (c) 2009 The openGion Project. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 013 * either express or implied. See the License for the specific language 014 * governing permissions and limitations under the License. 015 */ 016package org.opengion.fukurou.util; 017 018import java.util.Date ; 019 020/** 021 * StopTimer は、指定の一定時間の間、実行を停止します。 022 * 引数に、停止時間を秒単位で指定します。 023 * 初期値は、5(秒)です。 024 * 025 * Usage: java org.opengion.fukurou.fukurou.util.StopTimer 停止時間(秒) [-T] 026 * 027 * @og.group ユーティリティ 028 * 029 * @version 4.0 030 * @author Kazuhiko Hasegawa 031 * @since JDK5.0, 032 */ 033public final class StopTimer { 034 035 /** 036 * すべてが staticメソッドなので、コンストラクタを呼び出さなくしておきます。 037 * 038 */ 039 private StopTimer() {} 040 041 /** 042 * 処理を実行する main メソッドです。 043 * 044 * 引数には、処理を停止する 秒数 を入力します。 045 * -T を入力した場合は、処理開始時刻を表示します。 046 * 047 * Usage: java org.opengion.fukurou.fukurou.util.StopTimer 停止時間(秒) [-T] 048 * 049 * @param args コマンド引数配列 050 */ 051 public static void main( final String[] args ) { 052 long stopTime ; 053 054 if( args.length >= 1 ) { stopTime = 1000L * Long.parseLong( args[0] ) ; } 055 else { 056 LogWriter.log("Usage: java org.opengion.fukurou.fukurou.util.StopTimer 停止時間(秒) [-T]"); 057 return; 058 } 059 060 if( args.length ==2 && "-T".equals( args[1] ) ) { 061 System.out.println( new Date() ); 062 } 063 064 try { 065 Thread.sleep( stopTime ); 066 } 067 catch( InterruptedException ex ) { 068 LogWriter.log( "InterruptedException:" + ex.getMessage() ); 069 } 070 } 071}