Quantcast

Maximum PC

It is currently Fri Nov 28, 2014 2:00 am

All times are UTC - 8 hours




Post new topic Reply to topic  [ 13 posts ] 
Author Message
 Post subject: Java Question Repost
PostPosted: Tue Jul 27, 2004 1:59 pm 
Thunderbird
Thunderbird
User avatar

Joined: Wed Jul 07, 2004 1:13 pm
Posts: 817
Location: Missouri
Here is a repost of the information and last post done by Gadget from the Free Clinic Forum. Now that this new forum is open this question has a perfect place to start discussions and ideas.

baldeagle wrote:
I am trying to rebuild a program I origianlly created in VB 6 in Java. I am trying to obtain the tick count contained within Windows. I know there is a a currentSecondMills() method but it is for current time on the system.

The tick count stores how long the pc has been running during a session (i.e. how long since it was last booted). I have heard that it can be used with Java like any other method but I cannot find any information on its use in the Java forum from sun.com.

If anyone can provide any information it would be greatly appreciated.

Sorry this took so long - having a crappy day today.

Anyways, post the section of VB code that you used to obtain the tick count. I'm no windows internals guru, and I don't know diddly about the windows libraries (except that everyone seems to hate them), so that might help point things in the right direction. Java lets you gather quite a bit of system information easily with Properties and Runtime (see the code below), but I don't think there is a way to get at the 'tick count' directly from the Java API.

Possible solutions are calling GetTickCount() using JNI, execute a native command like systeminfo (and get rid of the extra info - easier, but slower), or if windows stores this info in a file, just read it in from there (again, easier and slower). You might be able to read it in directly from the registry - never tried it. Additionally, COBRA might offer something here, but I know diddly-squat about COBRA.

edit: OK - brain is working again. Amazing what a little pizza and beer can do to help you forgot a bad day. This version gathers system information from three places: first, it gets system properties using the System.getProperties() method in the Java API; second, it gets runtime information using the Runtime instance; finally, it makes executes the systeminfo windows command as a seperate process and acquires additional system info, including the uptime. Since it is a seperate process, it could be threaded and ran concerrently with the other two - might save a few miliseconds.

Yeah, looks like I need to change my host name from amd700 to amd2600 now. Do you get some kind of brownie prize for the longest post ever? I even tried to make the font smaller, but it doesn't work seem to work inside of a code or quote block - sorry about teh length.

Code:
import java.io.*;
import java.util.*;

public class SysInfo {
public static void main(String[] args) {

System.out.println("System Properties");
System.out.println("-----------------");
System.getProperties().list(System.out);

Runtime r = Runtime.getRuntime();
System.out.println();
System.out.println("Runtime Information");
System.out.println("-------------------");
System.out.println("num processors: " + r.availableProcessors());
System.out.println("Total jvm memory: " + r.totalMemory()/1024 + " KB");
System.out.println("Free jvm memory: " + r.freeMemory()/1024 + " KB");
if (r.maxMemory() == Long.MAX_VALUE)
System.out.println("No maximum memory limit set");
else
System.out.println("Max.jvm memory: " + r.maxMemory()/1024 + " KB");

try {
DataInputStream in = new DataInputStream(r.exec("systeminfo").getInputStream());
String s = in.readLine();
StringBuffer sb = new StringBuffer();
while (s != null) {
sb.append(s);
sb.append("\n");
s = in.readLine();
}

System.out.println();
System.out.println("Systeminfo Command");
System.out.println("-------------------");
System.out.println(sb.toString());
}
catch (IOException e) {
e.printStackTrace();
}

System.out.println("finsihed SysInfo");
System.exit(0);
}
}



Output wrote:
System Properties
-----------------
-- listing properties --
java.runtime.name=Java(TM) 2 Runtime Environment, Stand...
sun.boot.library.path=C:\Program Files\Java\j2re1.4.2\bin
java.vm.version=1.4.2-b28
java.vm.vendor=Sun Microsystems Inc.
java.vendor.url=http://java.sun.com/
path.separator=;
java.vm.name=Java HotSpot(TM) Client VM
file.encoding.pkg=sun.io
user.country=US
sun.os.patch.level=Service Pack 1
java.vm.specification.name=Java Virtual Machine Specification
user.dir=C:\Documents and Settings\Larry\Deskt...
java.runtime.version=1.4.2-b28
java.awt.graphicsenv=sun.awt.Win32GraphicsEnvironment
java.endorsed.dirs=C:\Program Files\Java\j2re1.4.2\lib\e...
os.arch=x86
java.io.tmpdir=C:\DOCUME~1\Larry\LOCALS~1\Temp\
line.separator=

java.vm.specification.vendor=Sun Microsystems Inc.
user.variant=
os.name=Windows XP
sun.java2d.fontpath=
java.library.path=C:\WINDOWS\system32;.;C:\WINDOWS\Syst...
java.specification.name=Java Platform API Specification
java.class.version=48.0
java.util.prefs.PreferencesFactory=java.util.prefs.WindowsPreferencesFac...
os.version=5.1
user.home=C:\Documents and Settings\Larry
user.timezone=
java.awt.printerjob=sun.awt.windows.WPrinterJob
file.encoding=Cp1252
java.specification.version=1.4
user.name=Larry
java.class.path=C:\Documents and Settings\Larry\Deskt...
java.vm.specification.version=1.0
sun.arch.data.model=32
java.home=C:\Program Files\Java\j2re1.4.2
java.specification.vendor=Sun Microsystems Inc.
user.language=en
awt.toolkit=sun.awt.windows.WToolkit
java.vm.info=mixed mode
java.version=1.4.2
java.ext.dirs=C:\Program Files\Java\j2re1.4.2\lib\ext
sun.boot.class.path=C:\Program Files\Java\j2re1.4.2\lib\r...
java.vendor=Sun Microsystems Inc.
file.separator=\
java.vendor.url.bug=http://java.sun.com/cgi-bin/bugreport...

sun.cpu.endian=little
sun.io.unicode.encoding=UnicodeLittle
sun.cpu.isalist=pentium i486 i386

Runtime Information
-------------------
num processors: 1
Total jvm memory: 1984 KB
Free jvm memory: 1844 KB
Max.jvm memory: 65088 KB

Systeminfo Command
------------------

Host Name: AMD700
OS Name: Microsoft Windows XP Professional
OS Version: 5.1.2600 Service Pack 1 Build 2600
OS Manufacturer: Microsoft Corporation
OS Configuration: Standalone Workstation
OS Build Type: Uniprocessor Free
Registered Owner: AMD700
Registered Organization: CSUF
Product ID: xxx
Original Install Date: 6/29/2004, 4:01:09 AM
System Up Time: 1 Days, 11 Hours, 28 Minutes, 3 Seconds
System Manufacturer: Ssystem manufacturer
System Model: System product name
System type: X86-based PC
Processor(s): 1 Processor(s) Installed.
[01]: x86 Family 6 Model 8 Stepping 1 AuthenticAMD ~2079 Mhz
BIOS Version: A M I - 11000325
Windows Directory: C:\WINDOWS
System Directory: C:\WINDOWS\System32
Boot Device: \Device\HarddiskVolume1
System Locale: en-us;English (United States)
Input Locale: en-us;English (United States)
Time Zone: (GMT-08:00) Pacific Time (US & Canada); Tijuana
Total Physical Memory: 447 MB
Available Physical Memory: 85 MB
Virtual Memory: Max Size: 1,602 MB
Virtual Memory: Available: 881 MB
Virtual Memory: In Use: 721 MB
Page File Location(s): c:\pagefile.sys
Domain: xxx
Logon Server: xxx
NetWork Card(s): 1 NIC(s) Installed.
[01]: NVIDIA nForce Networking Controller
Connection Name: Local Area Connection 3
DHCP Enabled: Yes
DHCP Server: 192.168.1.1
IP address(es)
[01]: 192.168.1.xxx

Finsihed SysInfo


Top
  Profile  
 
 Post subject: Re: Java Question Repost
PostPosted: Tue Jul 27, 2004 2:01 pm 
Thunderbird
Thunderbird
User avatar

Joined: Wed Jul 07, 2004 1:13 pm
Posts: 817
Location: Missouri
baldeagle wrote:
Here is a repost of the information and last post done by Gadget from the Free Clinic Forum. Now that this new forum is open this question has a perfect place to start discussions and ideas.

baldeagle wrote:
I am trying to rebuild a program I origianlly created in VB 6 in Java. I am trying to obtain the tick count contained within Windows. I know there is a a currentSecondMills() method but it is for current time on the system.

The tick count stores how long the pc has been running during a session (i.e. how long since it was last booted). I have heard that it can be used with Java like any other method but I cannot find any information on its use in the Java forum from sun.com.

If anyone can provide any information it would be greatly appreciated.

Sorry this took so long - having a crappy day today.

Anyways, post the section of VB code that you used to obtain the tick count. I'm no windows internals guru, and I don't know diddly about the windows libraries (except that everyone seems to hate them), so that might help point things in the right direction. Java lets you gather quite a bit of system information easily with Properties and Runtime (see the code below), but I don't think there is a way to get at the 'tick count' directly from the Java API.

Possible solutions are calling GetTickCount() using JNI, execute a native command like systeminfo (and get rid of the extra info - easier, but slower), or if windows stores this info in a file, just read it in from there (again, easier and slower). You might be able to read it in directly from the registry - never tried it. Additionally, COBRA might offer something here, but I know diddly-squat about COBRA.

edit: OK - brain is working again. Amazing what a little pizza and beer can do to help you forgot a bad day. This version gathers system information from three places: first, it gets system properties using the System.getProperties() method in the Java API; second, it gets runtime information using the Runtime instance; finally, it makes executes the systeminfo windows command as a seperate process and acquires additional system info, including the uptime. Since it is a seperate process, it could be threaded and ran concerrently with the other two - might save a few miliseconds.

Yeah, looks like I need to change my host name from amd700 to amd2600 now. Do you get some kind of brownie prize for the longest post ever? I even tried to make the font smaller, but it doesn't work seem to work inside of a code or quote block - sorry about teh length.

Code:
import java.io.*;
import java.util.*;

public class SysInfo {
public static void main(String[] args) {

System.out.println("System Properties");
System.out.println("-----------------");
System.getProperties().list(System.out);

Runtime r = Runtime.getRuntime();
System.out.println();
System.out.println("Runtime Information");
System.out.println("-------------------");
System.out.println("num processors: " + r.availableProcessors());
System.out.println("Total jvm memory: " + r.totalMemory()/1024 + " KB");
System.out.println("Free jvm memory: " + r.freeMemory()/1024 + " KB");
if (r.maxMemory() == Long.MAX_VALUE)
System.out.println("No maximum memory limit set");
else
System.out.println("Max.jvm memory: " + r.maxMemory()/1024 + " KB");

try {
DataInputStream in = new DataInputStream(r.exec("systeminfo").getInputStream());
String s = in.readLine();
StringBuffer sb = new StringBuffer();
while (s != null) {
sb.append(s);
sb.append("\n");
s = in.readLine();
}

System.out.println();
System.out.println("Systeminfo Command");
System.out.println("-------------------");
System.out.println(sb.toString());
}
catch (IOException e) {
e.printStackTrace();
}

System.out.println("finsihed SysInfo");
System.exit(0);
}
}



Output wrote:
System Properties
-----------------
-- listing properties --
java.runtime.name=Java(TM) 2 Runtime Environment, Stand...
sun.boot.library.path=C:\Program Files\Java\j2re1.4.2\bin
java.vm.version=1.4.2-b28
java.vm.vendor=Sun Microsystems Inc.
java.vendor.url=http://java.sun.com/
path.separator=;
java.vm.name=Java HotSpot(TM) Client VM
file.encoding.pkg=sun.io
user.country=US
sun.os.patch.level=Service Pack 1
java.vm.specification.name=Java Virtual Machine Specification
user.dir=C:\Documents and Settings\Larry\Deskt...
java.runtime.version=1.4.2-b28
java.awt.graphicsenv=sun.awt.Win32GraphicsEnvironment
java.endorsed.dirs=C:\Program Files\Java\j2re1.4.2\lib\e...
os.arch=x86
java.io.tmpdir=C:\DOCUME~1\Larry\LOCALS~1\Temp\
line.separator=

java.vm.specification.vendor=Sun Microsystems Inc.
user.variant=
os.name=Windows XP
sun.java2d.fontpath=
java.library.path=C:\WINDOWS\system32;.;C:\WINDOWS\Syst...
java.specification.name=Java Platform API Specification
java.class.version=48.0
java.util.prefs.PreferencesFactory=java.util.prefs.WindowsPreferencesFac...
os.version=5.1
user.home=C:\Documents and Settings\Larry
user.timezone=
java.awt.printerjob=sun.awt.windows.WPrinterJob
file.encoding=Cp1252
java.specification.version=1.4
user.name=Larry
java.class.path=C:\Documents and Settings\Larry\Deskt...
java.vm.specification.version=1.0
sun.arch.data.model=32
java.home=C:\Program Files\Java\j2re1.4.2
java.specification.vendor=Sun Microsystems Inc.
user.language=en
awt.toolkit=sun.awt.windows.WToolkit
java.vm.info=mixed mode
java.version=1.4.2
java.ext.dirs=C:\Program Files\Java\j2re1.4.2\lib\ext
sun.boot.class.path=C:\Program Files\Java\j2re1.4.2\lib\r...
java.vendor=Sun Microsystems Inc.
file.separator=\
java.vendor.url.bug=http://java.sun.com/cgi-bin/bugreport...

sun.cpu.endian=little
sun.io.unicode.encoding=UnicodeLittle
sun.cpu.isalist=pentium i486 i386

Runtime Information
-------------------
num processors: 1
Total jvm memory: 1984 KB
Free jvm memory: 1844 KB
Max.jvm memory: 65088 KB

Systeminfo Command
------------------

Host Name: AMD700
OS Name: Microsoft Windows XP Professional
OS Version: 5.1.2600 Service Pack 1 Build 2600
OS Manufacturer: Microsoft Corporation
OS Configuration: Standalone Workstation
OS Build Type: Uniprocessor Free
Registered Owner: AMD700
Registered Organization: CSUF
Product ID: xxx
Original Install Date: 6/29/2004, 4:01:09 AM
System Up Time: 1 Days, 11 Hours, 28 Minutes, 3 Seconds
System Manufacturer: Ssystem manufacturer
System Model: System product name
System type: X86-based PC
Processor(s): 1 Processor(s) Installed.
[01]: x86 Family 6 Model 8 Stepping 1 AuthenticAMD ~2079 Mhz
BIOS Version: A M I - 11000325
Windows Directory: C:\WINDOWS
System Directory: C:\WINDOWS\System32
Boot Device: \Device\HarddiskVolume1
System Locale: en-us;English (United States)
Input Locale: en-us;English (United States)
Time Zone: (GMT-08:00) Pacific Time (US & Canada); Tijuana
Total Physical Memory: 447 MB
Available Physical Memory: 85 MB
Virtual Memory: Max Size: 1,602 MB
Virtual Memory: Available: 881 MB
Virtual Memory: In Use: 721 MB
Page File Location(s): c:\pagefile.sys
Domain: xxx
Logon Server: xxx
NetWork Card(s): 1 NIC(s) Installed.
[01]: NVIDIA nForce Networking Controller
Connection Name: Local Area Connection 3
DHCP Enabled: Yes
DHCP Server: 192.168.1.1
IP address(es)
[01]: 192.168.1.xxx

Finsihed SysInfo


Ah Ha. It does have the data I need. I need System Up Time: 1 Days, 11 Hours, 28 Minutes, 3 Seconds obtained so I can use it in the program. This is originally stored in milliseconds. Now I just need to find where and how to access it with java.


Top
  Profile  
 
 Post subject:
PostPosted: Tue Jul 27, 2004 3:52 pm 
8086
8086
User avatar

Joined: Wed Jul 14, 2004 9:08 pm
Posts: 80
I'd say that JNI or that command line exec is your best bet. I do not know of any methods to access current ticks.


BTW, Java is not realtime and System.currentTimeMillis() is nowhere near to practically useful for keeping fine measurements. (why they have the method Thread.sleep(millis,nanos) makes no sense to me!).

I've written a Java application to tap-out the bpm of my mp3 tunes, and I noticed the max resolution was 10ms and if I were to guess off-hand the precision was +/- 20ms.

So really... don't worry about the amount of cycles it takes or the loss in precision when reading from the output of systeminfo.


Top
  Profile  
 
 Post subject:
PostPosted: Tue Jul 27, 2004 11:10 pm 
Bitchin' Fast 3D Z8000*
Bitchin' Fast 3D Z8000*
User avatar

Joined: Tue Jun 29, 2004 11:32 pm
Posts: 2555
Location: Somewhere between compilation and linking
Karl the Pagan wrote:
BTW, Java is not realtime and System.currentTimeMillis() is nowhere near to practically useful for keeping fine measurements. (why they have the method Thread.sleep(millis,nanos) makes no sense to me!).

IIRC, the 'resolution' depends on the underlying operating system. On Windows, this is pretty course - something like 20 to 40 ms, but on many other os'es, it is much finer. I imagine there are embedded devices and realtime os'es with high enough resolutions and time constraints to utilize the ns component.

Or maybe Gosling was thinking ahead a few years. :)


Top
  Profile  
 
 Post subject:
PostPosted: Wed Jul 28, 2004 1:58 am 
Bitchin' Fast 3D Z8000
Bitchin' Fast 3D Z8000
User avatar

Joined: Sat Jun 26, 2004 3:44 pm
Posts: 513
Location: Vancouver Island
Code in C#... :-p


Top
  Profile  
 
 Post subject:
PostPosted: Wed Jul 28, 2004 3:48 am 
Bitchin' Fast 3D Z8000*
Bitchin' Fast 3D Z8000*
User avatar

Joined: Tue Jun 29, 2004 11:32 pm
Posts: 2555
Location: Somewhere between compilation and linking
Wolfmann wrote:
Code in C#... :-p

Oh, did you find a difference between them? :)

Since you're here, how the hell would I include the GetTickCount method in C++. Is windows.h the appropriate header file or win32 or kernel32 or what? And using a G, instead of g, irritates the hell out of me. The class is probably 'time', right?


Top
  Profile  
 
 Post subject:
PostPosted: Fri Aug 06, 2004 2:08 pm 
8086
8086
User avatar

Joined: Wed Jul 14, 2004 9:08 pm
Posts: 80
Gadget wrote:
IIRC, the 'resolution' depends on the underlying operating system. On Windows, this is pretty course - something like 20 to 40 ms, but on many other os'es, it is much finer.


I haven't observed one much better on Linux 2.4, 2.6... we've used Sun, IBM, blackdown, and jrockit (BEA) JVM's.

Of course you might be right with regard to the the Thread sleep nanos accuracy... I haven't really tested it thoroughly.

There is a RT Java project out there.


Top
  Profile  
 
 Post subject:
PostPosted: Sun Aug 08, 2004 12:47 pm 
Thunderbird
Thunderbird
User avatar

Joined: Wed Jul 07, 2004 1:13 pm
Posts: 817
Location: Missouri
Wolfmann wrote:
Code in C#... :-p


I do not know C#. I know it is suppose to be the .NET version of C++ or that is what I have heard from a few people.

How different is it from C++?


Top
  Profile  
 
 Post subject:
PostPosted: Sun Aug 08, 2004 1:01 pm 
Bitchin' Fast 3D Z8000*
Bitchin' Fast 3D Z8000*
User avatar

Joined: Tue Jun 29, 2004 11:32 pm
Posts: 2555
Location: Somewhere between compilation and linking
baldeagle wrote:
Wolfmann wrote:
Code in C#... :-p


I do not know C#. I know it is suppose to be the .NET version of C++ or that is what I have heard from a few people.

How different is it from C++?

C# is basically the same thing as Java. For the most part, MS copied everything and just changed the names of key components.....

Java Platform --> .NET platform
Java bytecode --> intermediate language code
JVM --> CRM
JSP --> ASP

Of course, .NET brings with it the added benefit of multiple languages. And the drawbacks. Translation: if you know C#, you better damn well know VB because the number of VB programmers that have switched to C# is depressingly small (seems like < 2%), so you now get to maintain a bunch of fugly VB code written in an OOP language by people who don't understand OOP at all. Fun stuff.


Top
  Profile  
 
 Post subject:
PostPosted: Sun Aug 08, 2004 2:33 pm 
8086
8086
User avatar

Joined: Wed Jul 14, 2004 9:08 pm
Posts: 80
C# is similar to Java since it is VM based, pure objects, and has automatic garbage collection.

Where they differ is slightly in the syntax, libraries (including the base security infrastructure, java's is quite mature), and bytecode.

I'm personally ignorant about C#'s native code interface (for Java -> C#... JNI -> ???). Does it have one?


Top
  Profile  
 
 Post subject:
PostPosted: Tue Aug 10, 2004 2:12 pm 
Bitchin' Fast 3D Z8000*
Bitchin' Fast 3D Z8000*
User avatar

Joined: Tue Jun 29, 2004 11:32 pm
Posts: 2555
Location: Somewhere between compilation and linking
Karl the Pagan wrote:
C# is similar to Java since it is VM based, pure objects, and has automatic garbage collection.

Where they differ is slightly in the syntax, libraries (including the base security infrastructure, java's is quite mature), and bytecode.

I'm personally ignorant about C#'s native code interface (for Java -> C#... JNI -> ???). Does it have one?

Yeah, it makes a distinction between managed and unmanaged code - I'm just not sure of the paticulars.


Top
  Profile  
 
 Post subject:
PostPosted: Tue Aug 10, 2004 2:42 pm 
8086
8086
User avatar

Joined: Wed Jul 14, 2004 9:08 pm
Posts: 80
Weak... in java you can set a custom security policy for any code depending on the source (url, jar, etc...). Stuff like java.* has all priviledges, but other packages, jars, etc can have specific policies.


Top
  Profile  
 
 Post subject:
PostPosted: Tue Aug 10, 2004 4:00 pm 
Bitchin' Fast 3D Z8000*
Bitchin' Fast 3D Z8000*
User avatar

Joined: Tue Jun 29, 2004 11:32 pm
Posts: 2555
Location: Somewhere between compilation and linking
Karl the Pagan wrote:
Weak... in java you can set a custom security policy for any code depending on the source (url, jar, etc...). Stuff like java.* has all priviledges, but other packages, jars, etc can have specific policies.

Glad to see we have another Java fan aboard ship... :)


Top
  Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 13 posts ] 

All times are UTC - 8 hours


Who is online

Users browsing this forum: No registered users and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group

© 2014 Future US, Inc. All rights reserved.