• 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
  • Tim Cooke
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Jeanne Boyarsky
Saloon Keepers:
  • Stephan van Hulst
  • Carey Brown
  • Tim Holloway
  • Piet Souris
Bartenders:

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

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Marshal
Posts: 27589
88
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
yes, I do not understand why new element is never calculated
 
Ranch Hand
Posts: 491
23
Eclipse IDE Firefox Browser Spring VI Editor AngularJS Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.


 
Rancher
Posts: 4936
38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Topic added to the Threads section
 
praveen kumaar
Ranch Hand
Posts: 491
23
Eclipse IDE Firefox Browser Spring VI Editor AngularJS Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
One more thing Alex if you will use the same key for
 
praveen kumaar
Ranch Hand
Posts: 491
23
Eclipse IDE Firefox Browser Spring VI Editor AngularJS Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Don't count your weasels before they've popped. And now for a mulberry bush related tiny ad:
The Low Tech Laboratory Movie Kickstarter is LIVE NOW!
https://www.kickstarter.com/projects/paulwheaton/low-tech
reply
    Bookmark Topic Watch Topic
  • New Topic