Source Code Cross Referenced for SystemUtil.java in  » Development » jodd » jodd » util » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Development » jodd » jodd.util 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        // Copyright (c) 2003-2007, Jodd Team (jodd.sf.net). All Rights Reserved.
002:
003:        package jodd.util;
004:
005:        /**
006:         * Various system utilities.
007:         */
008:        public class SystemUtil {
009:            /**
010:             * Calculates and returns java system timer resolution in miliseconds.
011:             * Resolution of a timer depends on platform and java version.
012:             */
013:            public static double systemTimerResolution() {
014:                long t1, t2;
015:                int sumres = 0;
016:                //noinspection CallToSystemGC
017:                System.gc();
018:                int loops = 20;
019:                for (int i = 0; i < loops; ++i) {
020:                    t1 = System.currentTimeMillis();
021:                    while (true) {
022:                        t2 = System.currentTimeMillis();
023:                        if (t2 != t1) {
024:                            sumres += (int) (t2 - t1);
025:                            break;
026:                        }
027:                    }
028:                }
029:                return (sumres / (double) loops);
030:            }
031:
032:            // ---------------------------------------------------------------- properties
033:
034:            public static final String SYS_USER_DIR = "user.dir";
035:            public static final String SYS_JAVA_HOME = "java.home";
036:            public static final String SYS_TEMP_DIR = "java.io.tmpdir";
037:            public static final String SYS_OS_NAME = "os.name";
038:            public static final String SYS_OS_VERSION = "os.version";
039:            public static final String SYS_JAVA_VERSION = "java.version";
040:            public static final String SYS_JAVA_VENDOR = "java.vendor";
041:            public static final String SYS_JAVA_CLASSPATH = "java.class.path";
042:            public static final String SYS_PATH_SEPARATOR = "path.separator";
043:
044:            /**
045:             * Returns current working folder.
046:             */
047:            public static String getUserDir() {
048:                return System.getProperty(SYS_USER_DIR);
049:            }
050:
051:            public static String getJavaJreHome() {
052:                return System.getProperty(SYS_JAVA_HOME);
053:            }
054:
055:            /**
056:             * Returns JAVA_HOME which is not equals to "java.home" property
057:             * since it points to JAVA_HOME/jre folder.
058:             */
059:            public static String getJavaHome() {
060:                String home = System.getProperty(SYS_JAVA_HOME);
061:                if (home == null) {
062:                    return null;
063:                }
064:                int i = home.lastIndexOf('\\');
065:                int j = home.lastIndexOf('/');
066:                if (j > i) {
067:                    i = j;
068:                }
069:                return home.substring(0, i);
070:            }
071:
072:            public static String getTempDir() {
073:                return System.getProperty(SYS_TEMP_DIR);
074:            }
075:
076:            public static String getOsName() {
077:                return System.getProperty(SYS_OS_NAME);
078:            }
079:
080:            public static String getOsVersion() {
081:                return System.getProperty(SYS_OS_VERSION);
082:            }
083:
084:            public static String getJavaVersion() {
085:                return System.getProperty(SYS_JAVA_VERSION);
086:            }
087:
088:            public static String getJavaVendor() {
089:                return System.getProperty(SYS_JAVA_VENDOR);
090:            }
091:
092:            public static String getClassPath() {
093:                return System.getProperty(SYS_JAVA_CLASSPATH);
094:            }
095:
096:            public static String getPathSeparator() {
097:                return System.getProperty(SYS_PATH_SEPARATOR);
098:            }
099:
100:            // ---------------------------------------------------------------- memory
101:
102:            /**
103:             * Returns amount of total memory in bytes.
104:             */
105:            public static long totalMemory() {
106:                return Runtime.getRuntime().totalMemory();
107:            }
108:
109:            /**
110:             * Returns amount of free memory in bytes.
111:             */
112:            public static long freeMemory() {
113:                return Runtime.getRuntime().freeMemory();
114:            }
115:
116:            /**
117:             * Returns percents of free memory.
118:             */
119:            public static double freeMemoryPercents() {
120:                Runtime runtime = Runtime.getRuntime();
121:                return ((double) runtime.freeMemory() / runtime.totalMemory()) * 100.0;
122:            }
123:
124:            /**
125:             * Returns amount of used memory in bytes.
126:             */
127:            public static long usedMemory() {
128:                return Runtime.getRuntime().totalMemory()
129:                        - Runtime.getRuntime().freeMemory();
130:            }
131:
132:            /**
133:             * Returns percents of used memory.
134:             */
135:            public static double usedMemoryPercents() {
136:                Runtime runtime = Runtime.getRuntime();
137:                long totalMemory = runtime.totalMemory();
138:                return ((double) (totalMemory - runtime.freeMemory()) / totalMemory) * 100.0;
139:            }
140:
141:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.