aspose file tools*
The moose likes Threads and Synchronization and the fly likes Java program for fibanocci using Java threads Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Threads and Synchronization
Bookmark "Java program for fibanocci using Java threads" Watch "Java program for fibanocci using Java threads" New topic
Author

Java program for fibanocci using Java threads

sriram vemaraju
Greenhorn

Joined: Feb 11, 2008
Posts: 16
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

Joined: Oct 25, 2008
Posts: 2700

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.
sriram vemaraju
Greenhorn

Joined: Feb 11, 2008
Posts: 16
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

Joined: Oct 25, 2008
Posts: 2700

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

Joined: Feb 11, 2008
Posts: 16
Thanks a lot for your feedback.It really helps.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Java program for fibanocci using Java threads