In this example, we have two producers (type 0 and 1) and one consumer. Again, the consumer waits for 50 ms and processes requests from the same type.
I thought it would be easier. The code does not end properly...
Here is a modified producer consumer example from docs.oracle.com.
The production is going to wait for consumers. Consumers will wait 50ms in the hope to get a bigger production at once. This is a working example which seems to do the job.
Question: Is there a more straightforward way to get production after a waiting time (here 50ms)?
(My solution consists of using two BlockingQueue with different behaviors.)
I tried to help you but I have never used the Scanner class. I need an answer and fast. So I google "Java Scanner how to use it".
Now I get the idea (on a side note, where is the line where the scanner is closed?) and I am confused.
What do you expect from the input? A string made of integers separated by space i.e. "1 -3 5" or directly a list of integers i.e. 1 then -3 then 5?
This expectation has to be clarified in your code.
From your code it seems you expect the user to enter integers one at a time. You tell us it does not work as expected.
Either you use a debugger in a Java IDE or you carefully read your code to imagine what the hell it is doing or you add after line 16:
Long story short: the upgrade of my computer has meant the swap from Oracle JDK to OpenJDk version 15 and Observer/Observable have been declared deprecated!
In the following code (inspired from the last version found in this thread) I just want the rows of the table to be updated.
So, I replace Observer/Observable with PropertyChangeListener/PropertyChangeSupport. It runs as expected.
By curiosity I would like to know how to do it with the use of an interface. Any hint?
On a side note, in class MyRow, m_rank tracks the rank of the row in the ArrayList to avoid looking for it in a loop (see the previous code above). Is there a straightforward way to do it without the use of the explicit member m_rank?