Ron McLeod

+ Follow
since Feb 12, 2013
Ron likes ...
VSCode Eclipse IDE TypeScript Redhat MicroProfile Quarkus Java Linux
Merit badge: grant badges
For More
Richmond, BC, Canada
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 Rancher Scavenger Hunt
expand Ranch Hand Scavenger Hunt Green check
expand Greenhorn Scavenger Hunt

Recent posts by Ron McLeod

If you mean inside an operation, then no.
4 days ago
You should be able to peek into a Map and Map.Entry.  I'm running Java 21; maybe it is different in other versions.

4 days ago
Thanks for the example - it helped me realize that accept could be called more than once - that lets me avoid needing to collect downstream elements in a temporary collection when using flatMap.

For example - I have an annotation which defines what types of content a class can process:
In order to work-around some issues using Graalvm to create a native executable, I need to extract and transform to the information in annotations at Graalvm's build time.  For each annotation in, there could be multiple elements out.  In the example below, I collected the elements to a List, returned it as a stream, and then flattened it using flatMap:
Using mapMulti, I can eliminate the List:
6 days ago
Java 16 added Stream#mapMulti.

It seems like one advantage of using this method over flatMap or a combination of filter and map is the reduction in the number of streams created; which probably translates into better performance.  Are there any other benefits?
6 days ago
This article looks like it might provide the answers you are looking for: HowToDoInJava: Spring Boot Log4j2.xml.  The config file looks quite similar to what I just posted.
1 week ago
I've never worked with Spring or SpringBoot, but here's what I did for the last project which used log4j2 logging with file rotation:
I'm not sure how that would translate in to SpringBoot configuration, but maybe it can provide some clues.
1 week ago

Lou Hamers wrote:I thought I agreed at first, but actually I don't think that produces an NPE (if the error really is a NullPointerException). That'd be a NumberFormatException right?

You're right, a blank or non-number value would throw a NumberFormatException, but if a reference to null was provided, it would result in a NullPointerException.  

This could easily happen with browser did not provide the expected value, or it was looked-up improperly in the Servlet (request.getParameter("loanamount") instead of request.getParameter("loanAmount")).
1 week ago
It seems like you must be providing some non-numeric data.
1 week ago

Lou Hamers wrote:You should post a more complete example ...

Agreed - in particular, what does your test data look like.
1 week ago

Sam Muller wrote:

LinkedList#offerFirst is only applicable for instances of LinkedList (it is not inherited from List).  In your code, l1 is declared as an instance of List, not LinkedList.
1 week ago

Paul Houle wrote:What do you call something that calls a Consumer?

Generically I would just call something that calls a Consumer,  a Consumer-invoker, but a more specific name would depend on the particular usage in the code.
1 week ago
I am building a CLI which displays information aquired from a data broker using MQTT protocol.  MQTT is a PUB/SUB style asynchronous interface where a client subscribes to a particular topic, and sometime later, the broker publishes information for that topic when/if available.

When the user runs the CLI, it blocks until it is able to display the information, and then terminates.  I need a way to block the main thread of the CLI until the information has asynchronously received from the broker.

I've tried using CountDownLatch, Semaphore, CyclicBarrier (pretty much the same pattern), and SynchronousQueue, and they all are workable solutions when there are only two threads.

I am thinking of using CountdownLatch, but I wondering if there is a better solution which I have missed.

Anil Philip wrote:Shouldn't the method signatures match exactly?

The signature is the combination of method name and parameters; it does not include any specified exceptions thrown or return type.
I want to be able to submit a message to be published, but I also want that if the message is updated within a certain period, that only the updated message will be published.

My proof-of-concept code is using a Runnable which performs the publishing, and a ScheduledExecutorService which schedules the Runnable to execute after a fixed delay.  Each time a message is submitted for publication, the currently scheduled task (if it exists) is cancelled, and the Runnable is scheduled again.

It does seems to work as expected, but I'm wondering if there are alternate ways to solve this problem that I should consider.  

Here's what I have now: