KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > log4j > varia > test > Loop


1 /*
2  * Copyright 1999-2005 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17 package org.apache.log4j.varia.test;
18
19 import org.apache.log4j.Logger;
20 import org.apache.log4j.PropertyConfigurator;
21
22 /**
23    This test program reads a config file and attempts to log to the
24    appenders specified as many times as specified by the second
25    loopLength parameter.
26    
27    @author Ceki Gülcü */

28 public class Loop {
29
30   static Logger cat = Logger.getLogger(Loop.class);
31   static int loopLength;
32
33   public
34   static
35   void main(String JavaDoc argv[]) {
36
37     if(argv.length == 2)
38       init(argv[0], argv[1]);
39     else
40       usage("Wrong number of arguments.");
41     test();
42   }
43
44
45   static
46   void usage(String JavaDoc msg) {
47     System.err.println(msg);
48     System.err.println( "Usage: java " + Loop.class.getName() +
49             "configFile loopLength");
50     System.exit(1);
51   }
52
53   
54   static
55   void init(String JavaDoc configFile, String JavaDoc loopStr) {
56     PropertyConfigurator.configure(configFile);
57     try {
58       loopLength = Integer.parseInt(loopStr);
59     }
60     catch(java.lang.NumberFormatException JavaDoc e) {
61       e.printStackTrace();
62       usage("Could not interpret loopLength ["+ loopStr +"].");
63     }
64   }
65
66   static
67   void test() {
68     for(int i=0; i < loopLength; i++) {
69       Thread.yield();
70       cat.debug("MSG "+i);
71     }
72   }
73 }
74
Popular Tags