CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: Java Multithreading Interesting Query

  1. #1

    Java Multithreading Interesting Query

    Suppose, I want to print numbers in following format starting from 1 to 1,00,00,000.. with a step of 0.001

    1
    1.001
    1.002
    1.003
    1.004
    ......
    ......
    ....
    9999999.999
    10000000

    This is time consuming operation. How one can use multithreading?

  2. #2
    Join Date
    Feb 2002
    Posts
    4,640

    Re: Java Multithreading Interesting Query

    I doubt multithreading will help, as your real bottleneck is most likely the writing to the screen. On top of that, you'd have to synchronize the threads to print the numbers in the proper order, which would serialize the threads anyhow.

    Viggy

  3. #3
    Join Date
    Apr 1999
    Posts
    27,449

    Re: Java Multithreading Interesting Query

    Quote Originally Posted by forumuser11@gmail.com View Post
    Suppose, I want to print numbers in following format starting from 1 to 1,00,00,000.. with a step of 0.001
    To add what MrViggy stated, it will be difficult to generate that sequence if your loop counting relies on floating point, since floating point is not accurate. You will get skips in the generated sequence (0.001 cannot be represented as an exact binary floating point value).

    Write a simple loop without any threads -- don't be surprised if you discover that numbers are missing from your output, all due to floating point inaccuracies.

    Regards,

    Paul McKenzie

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)