Kbase P154169: How to check Java time and system time consistency
Autor |
  Progress Software Corporation - Progress |
Acesso |
  Público |
Publicação |
  10/9/2009 |
|
Status: Unverified
GOAL:
How to check Java time and system time consistency
GOAL:
Test program to check Java and system time possible differences.
FACT(s) (Environment):
All Supported Operating Systems
Progress 9.x
OpenEdge 10.x
FIX:
This is a Java test program to display the Java time and the System time.
Run the executable SysTime.java as follows:
$proenv
proenv> . slib_env
proenv> . java_env
proenv> javac SysTime.java
proenv> java SysTime
Java SysTime source code:
import java.util.*;
import java.text.DateFormat;
import java.io.*;
public class SysTime implements Runnable
{
private InputStream in = null;
private InputStreamReader reader = null;
private Thread t = null;
private DateFormat dFormat =
DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG);
private Date dTime = null;
private String sTime = null;
private String shellTime = null;
public static void main(String args[])
{
SysTime st = new SysTime();
try
{
st.execute();
}
catch(Exception e)
{
System.out.println(e.getMessage());
}
}
public SysTime()
{
}
public void execute() throws Exception
{
try
{
Runtime rt = Runtime.getRuntime();
while(true)
{
t = new Thread(this);
Process p = rt.exec("date");
in = p.getInputStream();
dTime = new Date(System.currentTimeMillis());
sTime = dFormat.format(dTime);
System.out.println("System time: " + sTime);
t.start();
p.waitFor();
Thread.sleep(60000);
}
} catch (InterruptedException e){}
}
public void run()
{
try
{
reader = new InputStreamReader(in);
int c = 0;
StringBuffer sb = new StringBuffer("");
while ((c = reader.read()) != -1)
{
sb.append((char)c);
}
System.out.println("Shell time:\t" + sb);
}
catch (Exception e)
{
}
}
}