易截截图软件、单文件、免安装、纯绿色、仅160KB

Java中的时间精度

    在Java中可以通过System.currentTimeMillis()或者System.nanoTime() (JDK>=5.0) 方法获得当前的时间的精确值。但是通过阅读Javadoc,我们发现这两个方法并不一定保证得到你所期望的精度。先来看System.currentTimeMillis():
Returns the current time in milliseconds. Note that while the unit of time of
the return value is a millisecond, the granularity of the value depends on the
underlying operating system and may be larger. For example, many operating
systems measure time in units of tens of milliseconds.
诚如上面所说返回值的粒度依赖于底层操作系统,那么它在不同的平台上到底能提供是么样的精度,是否像函数名所写的那样真正

确到1毫秒呢?看下面一段测试程序:
public class ClockAccuracyTest {
    public static void main(String args[]) {
        SimpleDateFormat formatter = new SimpleDateFormat("dd-MMM-yyyy HH:mm:ss:SSS");
        int size = 4000000;
        // create an array to hold millisecond times
        // and loop to capture them
        long times[] = new long[size];
        for (int i = 0; i < size; i++) {
            times[i] = System.currentTimeMillis();
        }
        // now display the unique times
        long time = times[0];
        long previousTime = times[0];
        long count = 0;
        Set<Long> deltas = new HashSet<Long>();       
        long delta = 0;
        long minDelta = Long.MAX_VALUE;
        long maxDelta = Long.MIN_VALUE;
    &


相关文档:

《java语言程序设计(一)》2009年自学考试大纲第1章

《java语言程序设计(一)》2009年自学考试大纲第1章
www.wesiedu.com   2009-5-5   在线模拟考场
二、课程内容与考核目标
第1章 Java语言基础
(一)课程内容
1.1 Java语言的特点
1.2 Java应用程序和小应用程序
1.3 Java程序的开发过程
1.4标识符和关键字
l.5基本数据类型
1.5.1 逻辑类型
1 ......

《java语言程序设计(一)》2009年自学考试大纲第5章


第5章图形界面设计(一)
(一)课程内容
5.1 图形界面设计基础
5.1.1 AWI’和Swing
5.1.2组件和容器
5.1.3事件驱动程序设计基础
5.2框架窗口 .
5.3标签、按钮和按钮事件
5.3.1 标签
5.3.2按钮和按钮事件处理
5.4面板
5.4.1 JPanel
5.4.2 JScrollPane
5.5布局设计
5.5.1 FlowI.ayout布局
5.5.2 BorderI.a ......

《java语言程序设计(一)》2009年自学考试大纲第8章


第8章 多线程
(一)课程内容
8.1线程的基本概念
8.1.1线程的生命周期
8.1.2线程调度与优先级
8.2 Thread类和Runnable接13
8.2.1 Thread类
8.2.2 Runnable接口
8.3线程互斥和同步
8.3.1线程互斥
8.3.2线程同步
(二)学习目的与要求
本章介绍多线程的概念和编写多线程程序的方法,实现线程之间相互通信和同步的技 ......

Java每天学习一点点 09.10.14

                                                   ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号