• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

Java program for fibanocci using Java threads

 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Bartender
Posts: 2700
IntelliJ IDE Opera
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Bartender
Posts: 2700
IntelliJ IDE Opera
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks a lot for your feedback.It really helps.
 
reply
    Bookmark Topic Watch Topic
  • New Topic