Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

multithreaded Java program to compute the generalized Fibonacci number specified by the parameters  RSS feed

 
Alex Kozitski
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A monitor class containing the F array. The monitor class must have the following public methods, and no other public methods.
Constructor (int n). This constructor initializes the monitor to calculate the generalized Fibonacci number for argument n.
void putValue (int i, BigInteger value). This method puts the given value into array element i. It is an error if a value has already been put into array element i.
BigInteger getValue (int i). This method returns the value stored in array element i. This method does not return until array element i has been put.
A thread that prints the output.
A thread that computes one and only one array element and stores it in the monitor. There is a separate instance of this thread for each array element, including array elements 0 and 1.
A main program. The main program must create the above objects. The main program must start the threads in this order: first the output printing thread, then the thread that computes the last array element, then the thread that computes the next-to-last array element, and so on backwards through the array elements. The main program must not wait for the threads to terminat
 
Paul Clapham
Sheriff
Posts: 22374
42
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Alex, welcome to the Ranch!

Ummm... did you have a question about that code?
 
Alex Kozitski
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yes, I do not understand why new element is never calculated
 
praveen kumaar
Ranch Hand
Posts: 456
22
Android Chrome Eclipse IDE Google App Engine Java Notepad Oracle Ubuntu Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello alex,a warm welcome to Ranch!

i have noticed some things in your code -


1. you have synchronized the putValue and getValue of supercalss and implement this method in the different sublasses which are runnable also.but in actual         whenever the 2 methods are implemented in subclass each time they create a new superclass instance and use them as lock.i.e.,you are not using the same lock
for doing your stuff each time you are calling the two methods they are using the lock associated with new super instance.

2. you have used wait,notifyAll in your class actually whenever you use the 2 methods make it sure that condition queue related with them is a same object along  with the lock,they are using for checking condition predicate and for blocking wait and notify,should be the same.in your case the condition queue you are using for the wait and notify are different objects along with different lock being used their for the 3 things just mentioned.

try to nest the classes as static private member inside the "Fib" which you have extended prior and their inside instantiate the one variable of enclosing class(Fib) and use that instead of the super keyword.

if still you don't understand any part hit the reply button.
hope it will help!

kind regards,
praveen.


 
Norm Radder
Ranch Foreman
Posts: 2212
28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Topic added to the Threads section
 
praveen kumaar
Ranch Hand
Posts: 456
22
Android Chrome Eclipse IDE Google App Engine Java Notepad Oracle Ubuntu Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
One more thing Alex if you will use the same key for
 
praveen kumaar
Ranch Hand
Posts: 456
22
Android Chrome Eclipse IDE Google App Engine Java Notepad Oracle Ubuntu Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
praveen kumaar wrote:One more thing Alex if you will use the same key for


sorry for the above post actually i am cancelling it but by mistake hits the submit button.
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!