This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Agile forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Java program for fibanocci using Java threads

 
sriram vemaraju
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi ,
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)) .

Below is the code
 
Wouter Oet
Saloon Keeper
Posts: 2700
IntelliJ IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
sriram vemaraju
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Wouter Oet
Saloon Keeper
Posts: 2700
IntelliJ IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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).
 
sriram vemaraju
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot for your feedback.It really helps.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic