-
May 29th, 2012, 01:22 AM
#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?
-
June 1st, 2012, 04:32 PM
#2
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
-
June 3rd, 2012, 03:41 PM
#3
Re: Java Multithreading Interesting Query
Originally Posted by forumuser11@gmail.com
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|