System.currentTimeMillis() not accurate on Windows ?

Hi,
JVM : 1.4.2_03-b02
OS : Windows XP
processor : XEON 2.4 GHz
Following test fails with 62.5 error percentage.
Is it due to windows failing to give time on a millisecond level ?
Or is there another reason ?
  public void testSleep() throws Exception {
    int total = 1000;
    int errors = 0;
    for ( int j = 0; j < total; j++ ) {
      long start = System.currentTimeMillis();
      Thread.sleep(5);
      long end = System.currentTimeMillis();
      if ( end < start+5 ) {
        errors++;
    Float errorPercentage = new Float( errors*(float)100/total );
    assertEquals( new Float(0), errorPercentage );
  }Regards, Tom.

The millisecond level of precision is only a possibility provided by the API, the OS does not forcibly provide it.
But Thread.sleep will not be absolutely precise, it is the most likely culprit.

Similar Messages

  • ScheduleAtFixedRate in ScheduledThreadPoolExecutor  not accurate in windows

    I am using the scheduleAtFixedRate method in ScheduledThreadPoolExecutor class to run a task periodically,but I found it not run accurately,here's a sample code:
    import java.text.SimpleDateFormat;
    import java.util.Calendar;
    import java.util.Date;
    import java.util.concurrent.ScheduledThreadPoolExecutor;
    import java.util.concurrent.TimeUnit;
    public class TestThreadPool {
         private static SimpleDateFormat dateformat = new SimpleDateFormat("HH:mm:ss.SSS");
         * @param args
         public static void main(String[] args) {
              Calendar cal = Calendar.getInstance();
              cal.add(Calendar.MINUTE, 1);
              cal.set(Calendar.SECOND, 0);
              cal.set(Calendar.MILLISECOND, 0);
              System.out.println(cal.getTime());
              ScheduledThreadPoolExecutor threadpool = new ScheduledThreadPoolExecutor(1);
              threadpool.scheduleAtFixedRate(new Runnable(){
                   public void run() {
                        System.out.println(dateformat.format(new Date()));
              }, (cal.getTimeInMillis()-System.currentTimeMillis()),5000, TimeUnit.MILLISECONDS);
    I want to it to work at next minute,then every 5 sencods like 0,5,15,20 seconds and so on.but the actually run time is plus,and it will not run at 5 based time,
    is it the windows platoform problem,I use windows xp sp2,but when I test this code
    in redhat enterprise server 4,it works well after serveral hours,can anybody tell me why and how to solve this problem ? Need your help!
    Edited by: allenzhuyi on Jul 6, 2008 11:03 PM

    ejp,Thanks for you advice,I will recalc next run time after the task has finished,here's my code:
    public class TestRescheduleTask2 {
    private static ScheduledThreadPoolExecutor threadpool = new ScheduledThreadPoolExecutor(1);
    public static long nextRunTime;
    public static long interval = 20000;
         public static void main(String[] args) {
              Calendar cal= Calendar.getInstance();
              cal.add(Calendar.MINUTE, 1);
              cal.set(Calendar.SECOND, 0);
              cal.set(Calendar.MILLISECOND, 0);
              nextRunTime = cal.getTimeInMillis();
              resubmit();
         public static void resubmit() {
              threadpool.schedule(new Task12(),
                        (nextRunTime-System.currentTimeMillis()),TimeUnit.MILLISECONDS);
              nextRunTime = nextRunTime + interval;
    class Task12 implements Runnable{
         public void run() {
              System.out.println(new Date());
              TestRescheduleTask2.resubmit(); //afer finish the task,I reschedule the task
    }

  • System.currentTimeMillis() not respecting system clock

    How does System.currentTimeMillis() work? I thought it checked the system clock. But I have an application that monitors the clock and I try to catch changes in it (for instance if the user changes his/her clock during runtime). But the System.currentTimeMillis() seems to ignore the time changes of the sytem clock. Any ideas?

    I had already done that. That is why I posted. I
    could have sworn it worked from previous experience,
    but I am not seeing it work now...The following code:import java.io.*;
    import java.util.*;
    public class TimeDemo {
        public static void main(String[] args) {
            try {
                InputStreamReader isr = new InputStreamReader(System.in);
                BufferedReader br = new BufferedReader(isr);
                System.out.println(System.currentTimeMillis());
                br.readLine();
                System.out.println(System.currentTimeMillis());
            catch (Exception e) {
                System.out.println(e);
    }Produces the following output:
    $ java TimeDemo
    1120149951371
    1117644363468 You'll note that time appears to have gone backwards - but in fact I set the clock back during the readLine block. So I think it does respond to changing the clock (at least under Solaris on a SPARC with Java 1.5).

  • System.currentTimeMillis() more accurate

    Hi All,
    In my web application I've to picking up a unique value more accurate that System.currentTimeMillis() method.
    I need to get a unique identifier like "EjbRef_1072881243731" to my web application.
    Can anyone show me a way to reach this?
    Thanks,
    Flor.

    If generating unique ID is your concern, then take a look at this
    http://www.javapractices.com/Topic56.cjp

  • System Reserved Not Available in Windows 8.1 Pro

    Hi, everyone! I have a doubt here.
    I have done the installation of Windows 8.1 Pro in my free dos laptop. I did custom installation, followed by "Choosing Partition to install Windows" step. There were two types of partition shown which were "system" and "primary",
    and then I chose the "system " type partition to be installed Windows. ( What I am worried is that I did a different way compared to the tutorials in Internet)
    Hence, there has no System Reserved Partition in my pc.
    My doubt is that, is there any problems or errors that will occur when without the mentioned partition? As I searched in Google I have done another way when installing Windows.
    Thanks for your fast reply.

    Hello,
    The TechNet Wiki Forum is a place for the TechNet Wiki Community to engage, question, organize, debate, help, influence and foster the TechNet Wiki content, platform and Community.
    Please note that this forum exists to discuss TechNet Wiki as a technology/application.
    As it's off-topic here, I am moving the question to the
    Where is the forum for... forum.
    Karl
    When you see answers and helpful posts, please click Vote As Helpful, Propose As Answer, and/or Mark As Answer.
    My Blog: Unlock PowerShell
    My Book:
    Windows PowerShell 2.0 Bible
    My E-mail: -join ('6F6C646B61726C406F75746C6F6F6B2E636F6D'-split'(?<=\G.{2})'|%{if($_){[char][int]"0x$_"}})

  • System will not start login Window

    I have a 10.4.5 workstation that will not start the login window.
    It comes up very quickly with the box/progress bar that shows the starting services. Then it goes to the blue screen with the spinning wheel. It will the get a beachball that goes to a useable mouse, but there is only lots of blue real estate. Login window never comes up.
    I have done the following in the order listed:
    disk utility
    fsck
    repaired permissions
    renamed com.apple.loginwindow.plist
    replaced the netinfo DB
    each reboot only produces the same screen with a cursor and nothing else.

    I had a similar looking problem on not one but two laptops after upgrading to 10.4.7 (which incorporates several Security Updates) from various lower Tiger versions. In my case, booting to single user mode showed loginwindow continually falling over & being restarted.
    They wouldn't boot from CD or external firewire drives.
    I eventually got them back up by booting in firewire target mode & applying the 10.4.7 Combo updater.

  • Lumia 535 not detected in windows 8.1 latest updat...

    I just bought a lumia 535 and it will not install with any USB cable i have on my laptop , it has windows 8.1 up to latest update. Windows update doesnt show any updates available also not after reboot.
    I downloaded the winusb phone driver from microsoft site and tried to install that manually and still it wont work
    This is really a downer, since i expected a windows phone to easily connect to my win 8.1 computer
    Even the cheapest android phone does it in an instant!
    anyone know a way? else this phone goes back to shop because if i cant connact it i dont want it

    Did you get a USB cable with the phone?
    Use the USB cable that came with the phone.
    Connect the phone to the PC.  Turn it all the way off, hold power button and slide the screen down. The phone will turn back on and it will be detected, drivers should load.
    If your operating system did not come with Windows Media Player, install the Media Feature Pack for your version of the operating system.
    http://windows.microsoft.com/en-US/windows/download-windows-media-player

  • Can not install OEM Windows 7 64 bit on iMac 24"

    I have a late 2006 iMac 24" white. I have installed Lion with Boot camp 4.0. I am attempting to install Windows 7 64 bit OEM. At Step 3 "Install Windows" of the Installation and Setup Guide the system does not start the Windows 7 installer. Please Help!

    I found another thread about running Windows 7 64 Bit on systems other than in a list provided by Apple. I ran the suggested Terminal Command with the following result:
    george-halls-imac:~ georgehall$ ioreg -l -p IODeviceTree | grep firmware-abi
        | |   "firmware-abi" = <"EFI32">
    Does this mean that I can not run 64 Bit Windows 7 on my system? Do I need to upgrade the firmware? Can I change this parameter and get the system to boot the Windows 7 install disk?
    My System is an iMac 24" white (late 2006), 2.33 GHz Intel Core 2 Duo 4 GB mem. NVIVIA GeForce 7600 GT
    Boot ROM version IM61.0093.B07
    SMC Version (system) 1.10f2

  • Workflows Do Not Start - "Not Supported in Windows Authentication Mode"

    I have a publishing site that is using Kerbos authentication.  Everything on the site works fine.
    I created a simple workflow in SPD 2013 and published this to the site without any problems.  However when I try to start the workflow with the account of a user who is a member of the site it will not run.  In the browser an alert pop's up
    saying "Something went wrong.  To try again, reload the page and then start the workflow again".
    In the SharePoint log's I find the following:
    SharePoint Server              Workflow Services              aj5oh Exception  System.NotSupportedException: Not supported
    in Windows authentication mode.     at Microsoft.SharePoint.IdentityModel.SPIdentityContext.Create(SPUserToken token, Boolean isShareByLinkGuestUser)     at Microsoft.SharePoint.WorkflowServices.WorkflowServiceContextExtensions.GetApplicationUserCredentials(WorkflowServicesContext
    context) StackTrace:  at Microsoft.Office.Server.Native.dll: (sig=1f86b0bf-2440-4b16-9099-860a571153c2|2|microsoft.office.server.native.pdb, offset=131CE) at Microsoft.Office.Server.Native.dll: (offset=21C85) 799af29b-db87-0034-c938-8a35e4082ffc
    This is a dev environment where everthing is setup on a single box, and I registered the workflow service in HTTP mode (which I allowed during the installation of workflow manager).
    Any ideas on what the problem might be?
    Thanks,
    Richard

    You haven't changed it to Claims there, you have changed NTLM to Kerberos. I guess your web app was already claims based because in SP 2013 we have to use Powershell to convert classic to claims and not from GUI.
    When I click the workflow on a item to start in manually I get the error:
    "Something went wrong. To try again, reload the page and then start the workflow"
    In ULS I get the not supported exception.
    It seems 2013 platform workflows aren't supported in classic mode web applications:
    http://sharepointconnoisseur.blogspot.co.uk/2012/11/sharepoint-2013-upgrade-preparation-to.html
    But I am not able to publish 2010 mode workflows in the classic web application, SPD 2013 throws error while publishing:
    "Unexpected error on server, wf cannot be associated"
    So does Infopath while publishing on to a list in that web application:
    -- The opinions expressed here represent my own and not those of anybody else -- http://manojvnair.blogspot.com

  • HT1925 I am using windows XP and have iTunes version 11.0.5.5.  My iPhone 5 with current operating system will not link with my iTunes. It states I needed the newer version of iTunes. But I have been unable to update --automatic or manual. How do I update

    I am using an older windows computer with Windows XP and iTunes 11.0.5.5.  Since upgrading my iPhone and iPad my system will not allow me to connect the devices to my iTunes -- it notes I need to upgrade to iTunes 11.5.  However using automatic updates or manual update I can not update iTunes -- I get an error message the older windows iTunes could not be removed. I can not remove iTunes using control panel -- an older install/uninstall file is evidently missing. All of my music is contained on my PC -- more music is on my PC than I store on my other devices and I don't want to loose those music files nor permission to access those music files. Does anyone have a solution to uninstalling and upgrading windows iTunes without losing my music. I would like to be able to connect my iPhone and iPad to my PC again. RS

    I am haveing same problem canot find itunes.msi

  • Window server 2008 r2 error show "stop :- c00002e3 security account manager initialization failed because of the for A DIVICE ATTACHED to the system is not funcation"

    Hi All
    Please help
    my server not working showing display error window server 2008 r2  error show "stop :- c00002e3 security account manager initialization failed because of the for A DIVICE ATTACHED to the system is not funcation"
    Please help me how to resolve this issue ???
    thnaks !!!

    Hi,
    If there is any external device plug into your computer, please unplug it and restart the Server.
    You can also test the issue in Safe mode.
    If it can boot into Safe mode, please update any driver has yellow warning on it, also check if the dump file is existing under %SystemRoot%\, if so, please help to post back for our research.
    Kate Li
    TechNet Community Support

  • HT1222 I am trying like **** to download itunes 10.6.3 (64 bit - Windows 7) and I keep getting "the installer was interrupted before the requested operations for iTunes could be completed.  Your systems has not been modified."  I NEED HELP, PLEASE!

    I am trying like **** to download itunes 10.6.3 (64 bit - Windows 7) and I keep getting "the installer was interrupted before the requested operations for iTunes could be completed.  Your systems has not been modified."  I NEED HELP, PLEASE!

    I got it figured out myself... yaaaaay for me!

  • Help! my windows PC with Vista will not dowload itunes 10.7.  It gives me an error message: Your system has not been modified

    Help! my windows PC with Vista will not dowload itunes 10.7.  It gives me an error message: Your system has not been modified.I
    I have tried unistalling the current version I had which was 10.6.3, defragging and running a security scan. Now, the highest version I can get is 10.4.1. for some reason I cannot dowload itunes 10.5 or higher as it gives me the same message which is what I need to connect and update my iphone.  Anyone facing the same issue or can point me in the right direction?

    You may get better information on that error message by reposting in the iPhone forums:
    iPhone
    It's also possible that newer iPhone updates want an OS higher than Tiger. Post the specs of your computer and we can see if an OS upgrade is possible. There are a large number of G4 variants with different capabilities, so giving us something more than  just "G4" will get you help faster.

  • HP business inkjet 2800 Print black only option not showing in Windows 7 64 bit operating system

    HP business inkjet 2800 Print black only option not showing in Windows 7 64 bit operating system
    Please help, if any one knows any solution.

    Hi @Firoskhan,
    Welcome to the HP Forums!
    I am sorry, but to get your issue more exposure I would suggest posting it, in the commercial forums since this is a commercial product. You can do this at HP Enterprise Business Community.
    Hope this helps!  
    RnRMusicMan
    I work on behalf of HP
    Please click “Accept as Solution ” if you feel my post solved your issue, it will help others find the solution.
    Click the “Kudos Thumbs Up" to say “Thanks” for helping!

  • Just installed CC on my PC, Windows 7, 64 bit system. Not seeing any applications on the desktop or installation folder. However, all the resource files are present in the installation folder. What am I doing wrong?

    Just installed CC on my PC, Windows 7, 64 bit system. Not seeing any applications on the desktop or installation folder. However, all the resource files are present in the installation folder. What am I doing wrong?
    I've installed three times with no luck. I downloaded the Creative Cloud Packager off the licensing site: https://licensing.adobe.com. I unpacked and choose my applications. The install seemed to be successful, but I don't so any of the applications anywhere.

    Hi,
    Creating package doesn't mean it will install the product,
    You will need to install the package now. Please follow the instructions mentioned in the below articles
    Creative Cloud Help | Creating or editing packages
    Creative Cloud Help | Deploying packages
    Please let me know if it doesn't help.
    Regards,
    Devendra

Maybe you are looking for

  • Error occured while Saving The Project

    I have a project that is giving me a 'unknown error occurred while saving the project. Select 'Save As' from the file menu and save the project to a new location'. It would seem that maybe it's saying that it's out of room but I'm saving on a harddis

  • Lost files, music, iPhoto's since updating to Yosemite

    Hi Updated to Yosemite 2 weeks ago. iTunes, iPhoto, Pages, Numbers all working excellent etc... However, no U2 album (automatic download) was ever included with the iTunes update 12.0.1. Fired up Macbook this morning. It Froze. I restarted it. It too

  • Goods receipt is triggering an extra PO

    Can anyone please let me know how to handle the below case Goods receipt is triggering an extra PO to be zetafaxed to supplier.  This is after original PO has been successfully sent, so there is a potential for double supply.

  • Appleworks 6.2.9 Spreadsheet Sorting

    I am running Appleworks 6.2.9 on my PPC G4 Laptop. I have a one column list of data of approx 12,000 entries. Each one is not unique, rather they're duplicates in assorted quantities. Is there a sort function where the program can eliminate duplicate

  • MM Outline Agreement Screen Flow

    Our client has a requirement on contracts and scheduling agreements where they would like to see, displayed, the extended value of the line item and the total value of the outline agreement. I have located the fields needed and they seem to serve the