KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > compiere > Base


1 /******************************************************************************
2  * The contents of this file are subject to the Compiere License Version 1.1
3  * ("License"); You may not use this file except in compliance with the License
4  * You may obtain a copy of the License at http://www.compiere.org/license.html
5  * Software distributed under the License is distributed on an "AS IS" basis,
6  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
7  * the specific language governing rights and limitations under the License.
8  * The Original Code is Compiere ERP & CRM Business Solution
9  * The Initial Developer of the Original Code is Jorg Janke and ComPiere, Inc.
10  * Portions created by Jorg Janke are Copyright (C) 1999-2001 Jorg Janke, parts
11  * created by ComPiere are Copyright (C) ComPiere, Inc.; All Rights Reserved.
12  * Contributor(s): ______________________________________.
13  *****************************************************************************/

14 package org.compiere;
15
16 import java.util.*;
17 import java.math.*;
18
19 import org.compiere.util.*;
20 import org.compiere.model.*;
21
22 /**
23  * Base Library Test Classes mainly for Optimize it
24  *
25  * @author Jorg Janke
26  * @version $Id: Base.java,v 1.17 2003/10/03 04:06:08 jjanke Exp $
27  */

28 class Base
29 {
30     /**
31      * Base Test
32      */

33     public static void test()
34     {
35         System.out.println("** Before Init **"); //$NON-NLS-1$
36
getMemoryUsed();
37         Properties ctx = Env.initTest(1, false);
38     // Log.printProperties(System.getProperties(), "System", false);
39
//
40
System.gc(); // cleanup Init
41
//
42
System.out.println("** Before Creation **");
43         long start = getMemoryUsed();
44
45         // *******************************************************************
46

47         // Table=100, Shipper=142, Window=102, Reference=101
48
int AD_Window_ID = 102;
49         long startTime = System.currentTimeMillis();
50         MWindowVO vo = MWindowVO.create(Env.getCtx(), 1, AD_Window_ID);
51         MWindow w = new MWindow(vo);
52         long endDef = System.currentTimeMillis();
53         System.out.println("Load Definition Time in ms = " + String.valueOf(endDef-startTime));
54         if (1==2) // optional step
55
{
56             w.loadCompete();
57             long endDefComplete = System.currentTimeMillis();
58             System.out.println("Load Definition Complete Time in ms = " + String.valueOf(endDefComplete-startTime));
59         }
60         w.query();
61         long endData = System.currentTimeMillis();
62         System.out.println("Load Data Time in ms = " + String.valueOf(endData-startTime));
63         w.loadCompete();
64         long endDataComplete = System.currentTimeMillis();
65         System.out.println("Load Data Complete Time in ms = " + String.valueOf(endDataComplete-startTime));
66         w.getTab(0).navigate(0);
67
68         // *******************************************************************
69
// sleep();
70

71         System.out.println("** Before Dispose **");
72         getMemoryUsed();
73         w.dispose();
74 // sleep();
75
//
76
System.out.println("** Before GC **");
77         getMemoryUsed();
78         w = null;
79         System.gc();
80         System.out.println("** After GC **");
81         getMemoryUsed();
82         System.gc();
83
84         System.out.println("** Final **");
85         long complete = System.currentTimeMillis();
86         System.out.println("Complete Time in ms = " + String.valueOf(complete-startTime));
87         long end = getMemoryUsed();
88         System.out.println("Memory increase in kB = End-Start=" + String.valueOf((end-start)/1024));
89         listThreads();
90         //
91
System.out.println("API Test");
92         System.out.println("64.72=" + DB.getConvertedAmt(new BigDecimal(100.0), 116, 100,0,0));
93         System.out.println("0.647169=" + DB.getConvesionRate(116, 100, null, null,0,0));
94         System.out.println("12.5=" + UOMConversion.getConvertedQty(new BigDecimal(100.0), 101, 102, true));
95
96     } // Base
97

98     /**
99      * Get Used Memory in bytes
100      */

101     private static long getMemoryUsed()
102     {
103         long free = Runtime.getRuntime().freeMemory();
104         long total = Runtime.getRuntime().totalMemory();
105         long used = total - free;
106         //
107
System.out.println("Memory used in kB = Total("
108             + String.valueOf(total/1024) + ")-Free("
109             + String.valueOf(free/1024) + ") = " + String.valueOf(used/1024));
110         System.out.println("Active Threads=" + Thread.activeCount());
111         return used;
112     } // getMemoryUsed
113

114     /**
115      * Sleep for a second
116      */

117     private static void sleep()
118     {
119         System.out.println(".. sleeping-ini .. -> " + Thread.activeCount());
120         Thread.yield();
121         try
122         {
123             Thread.sleep(1000);
124         }
125         catch (InterruptedException JavaDoc ie)
126         {}
127         System.out.println(".. sleeping-end .. -> " + Thread.activeCount());
128     } // sleep
129

130     /**
131      * List Threads
132      */

133     private static void listThreads()
134     {
135         Thread JavaDoc[] list = new Thread JavaDoc[Thread.activeCount()];
136     // int no = Thread.currentThread().enumerate(list);
137
for (int i = 0; i < list.length; i++)
138         {
139             if (list[i] != null)
140                 System.out.println("Thread " + i + " - " + list[i].toString());
141         }
142     } // listThreads
143

144     /**
145      * Start
146      */

147     public static void main(String JavaDoc[] args)
148     {
149         Base.test();
150         Env.exitEnv(0);
151     } // main
152
} // Base
153
Popular Tags