This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
I made a program using Java threads for solving the fibonacci series (I have to use multiple threads as the part of the requirements). I have seen that as the series length increases. The need for more threads arises.
So my question is; Is there any relation between the size of the input for fibonacci series and no of threads currently i am using the formula
noOfThreads=(noOfCores)/(1-(Serial Part)/Parallel Part)) .
Most of the time a bigger number of threads doesn't mean greater performance. Most pc's have a dual/quad core processor so creating more then 2/4 thread may actually decrease your performance as the JVM will have to switch between the threads.
"Any fool can write code that a computer can understand. Good programmers write code that humans can understand." --- Martin Fowler
Please correct my English.
Joined: Feb 11, 2008
Hey that's true but as i increase the no of threads i get an increase in performance.I have an i3 processor which 4 cores.But i get a better performance for 18 threads if i want the 30th number in the Fibonacci series.
Thats why i am confused.
In your case I would rethink the algorithm. Because now you're doing most of the work twice (in fibon and Sequence).
I would also improve the code quality:
Method names should start with a lowercase letter.
I don't see why these methods are static.
Improper encapsulation in FibonacciThread.
Maybe a personal preference but I don't like the usage of an innerclass (especially static inner classes, of course there are exceptions).