1 package org.webdocwf.util.loader;
2
3 /***
4 * <p>Title: TimeWatch.java</p>
5 * <p>Description: Time measuring of importDefinitions </p>
6 * <p>Copyright: Copyright (c) 2003</p>
7 * <p>Company: Together</p>
8 * @author Sinisa Milosevic sinisa@prozone.co.yu
9 * @version 1.0
10 */
11
12 /***
13 Copyright (C) 2002-2003 Together
14
15 This library is free software; you can redistribute it and/or
16 modify it under the terms of the GNU Lesser General Public
17 License as published by the Free Software Foundation; either
18 version 2.1 of the License, or (at your option) any later version.
19
20 This library is distributed in the hope that it will be useful,
21 but WITHOUT ANY WARRANTY; without even the implied warranty of
22 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
23 Lesser General Public License for more details.
24
25 You should have received a copy of the GNU Lesser General Public
26 License along with this library; if not, write to the Free Software
27 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
28
29 */
30 import java.text.SimpleDateFormat;
31 import java.text.DateFormat;
32 import java.util.Date;
33
34
35 public class TimeWatch {
36
37 private long startTime = 0;
38 private long startJobTime = 0;
39
40 /***
41 * Constructor
42 */
43 public TimeWatch() {
44 this.startJobTime=0;
45 this.startTime=System.currentTimeMillis();
46 }
47
48
49 /***
50 * Method getTotalTime - return all jobs duration as a String (min:sec,milsec)
51 * @return String (min:sec,milsec)
52 */
53 public String getTotalTime() {
54 long currentTime = System.currentTimeMillis();
55 long difference = currentTime-this.startTime;
56
57 if(difference>60000){
58 long minutes = difference/60000;
59 long remainder = difference%60000;
60 return new String((new Long(minutes)).toString()+" minutes "+
61 (new Long(remainder/1000)).toString()+","+(new Long(remainder%1000)).toString()+" seconds");
62 }
63 else if(currentTime>1000)
64 return new String((new Long(difference/1000)).toString()+","+(new Long(difference%1000)).toString()+" seconds");
65 else
66 return new String((new Long(difference)).toString() +" miliseconds"); }
67
68 /***
69 * Method setStartJobTime - set time counter for new loader job
70 */
71 public void setStartJobTime() {
72 this.startJobTime = System.currentTimeMillis();
73 }
74
75 /***
76 *Method setStartTime - set time counter for all loader jobs
77 */
78 public void setStartTime() {
79 this.startTime = System.currentTimeMillis();
80 }
81 /***
82 * Method getJobTime - return duration of loader job (importDefinition or sql) as a String (min:sec,milsec)
83 * @return (min:sec,milsec)
84 */
85 public String getJobTime() {
86 // DateFormat df = new SimpleDateFormat("mm:ss");
87 long currentTime = System.currentTimeMillis();
88 long difference = currentTime-this.startJobTime;
89 if(difference>60000){
90 long minutes = difference/60000;
91 long remainder = difference%60000;
92 return new String((new Long(minutes)).toString()+" minutes "+
93 (new Long(remainder/1000)).toString()+","+(new Long(remainder%1000)).toString()+" seconds");
94 }
95 else if(currentTime>1000)
96 return new String((new Long(difference/1000)).toString()+","+(new Long(difference%1000)).toString()+" seconds");
97 else
98 return new String((new Long(difference)).toString() +" miliseconds");
99 }
100
101 /***
102 * set jop time to 0.
103 */
104 public void reset() {
105 this.startJobTime=0;
106 }
107
108 }
This page automatically generated by Maven