Greg Pata

Ranch Hand
+ Follow
since Apr 17, 2015
Greg likes ...
Eclipse IDE Java
Cows and Likes
Total received
In last 30 days
Total given
Total received
Received in last 30 days
Total given
Given in last 30 days
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Greg Pata

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...

Thank you for your reply and your ideas, Tim.
Issues are present when requests arrive around the same time: hence, the slightly delayed processing to properly manage requests.

I do not fully control results of the processed requests so doing a callback on the requester might lead to inconsistency due to unreliable information.

Here is a modified producer consumer example from
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:

What do you see?

1 year ago
The corrected code follows. The interface version will appear as soon as PropertyChangeSupport becomes deprecated. :-)
1 year ago
Thank you very much Stephan! Brilliant!
I appreciate. It is not as simple as I thought.
1 year ago
Thank you Tim for your suggestion.

Tim Moores wrote:Why an interface?

This is what is suggested here by Stephan.
It could be simple in my test code but I don't know how to do it.
1 year ago
Thank you Stephan for your time.

You are right. I will improve the code as you suggest.

The main question is: how to use an interface to replace the deprecated Observer/Observable or propertyChangeSupport/PropertyChangeListener?
1 year ago

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?

Thank you for your help,

1 year ago
Great example! In the above code, RADIUS should have been named DIAMETER.
6 years ago

Tony Docherty wrote:The ZRow class needs to have a public no args constructor.

Indeed, thank you Tony.
6 years ago
It seems I am not able to serialize an ArrayList<NonTrivialObject>() to xml...
Here is the debug code:

The output is:

I do not know how to correct this.

Thank you for your help.
6 years ago

Sresh Rangi wrote:This can be done with the newer CompletableFuture class.

Good to know. Thank you.
Thank you, Chris, for your help!
1) Ok you are right.
2) I have tried and failed. But now, thanks to you it works . The code follows:
(slightly different from what you described)
Here is the code of a kind of client/server communication. It works.
However I am sure there is a better way to notify the client as soon as the message arrives.
Thank you for your help.