This week's book giveaway is in the Web Services forum.
We're giving away four copies of Microservices in Action and have Morgan Bruce & Paulo A. Pereira on-line!
See this thread for details.
Win a copy of Microservices in Action this week in the Web Services forum!

Siegfried Heintze

Ranch Hand
+ Follow
since Aug 11, 2000
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 Siegfried Heintze

There is a great example of Gradle/Hibernate/hbm2/SpringBoot Spring5 & Angular Video Tutorial with Free Accompanying Source code From in chapter two except it does not work!

Doing "./gradlew hbm2java" after having configured mysql gave this error:

When I tried bumping the spring boot version from 2.0.0.RC1 to 2.1.0.RELEASE I got a slightly different error:

Can someone show me a working example? Preferably with gradle using the hibernate plugin, but maven will do.

2 weeks ago

Gary W. Lucas wrote:
So,  the JVM  uses the following per object
8 bytes management (including object-synchronization overhead)

Wow! 8 bytes seems like a lot to me -- especially when it is rarely used. I often see this

So java programmers often create a separate object just for locking. So why does this synchronization feature require 64 bits? Can anyone elaborate on the memory layout of these 64 bits (assuming 32 bit java).
Why must all descendants of Object consume this extra 64 bits of memory when it is so common to create a dedicated lock object (as in my example)? This seems extremely inefficient to require all objects to have this locking capability.
There is probably something I don't understand about locking... Perhaps someone can help me.

So could we save memory with this code?

Is this any better or worse?

1 year ago

According to this video YouTube video on Java Memory Mgt from IBM the statement consumes 128 bits (assuming you are running 32 bit java) or 224 bits for 64 bit java.

Is this really true? Are there not some additional data structures required so the garbage collector can find all these bits of memory and de-fragment them? So what does x actually contain? Does it contain a pointer to the Integer object and that pointer needs to change after the garbage collector de-fragments the heap? If so, how does the garbage collector know where the variable x is? X must be on a linked list of active variables so the garbage collector can update "x" to the new location of the Integer object after the heap has been de-fragmented ... correct?

If that is true, then storing an integer object in java is much worse than 128 bits or 224 bits for 64 bit java. How bad is it?

Alternatively, the JVM could implement x as an integer index into a large fixed array of pointers. That array cell would contain the address of the actual integer object containing 10. If so, then the garbage collector would just update this large fixed array (which requires more memory too!). In either case, we need more memory. How much more?

Does anyone know how the Oracle (and other popular JVMs) implement this?

1 year ago
Thank you everyone. That was very helpful.

1 year ago
I'm confused about declaring function arguments as List<Integer> versus List<? extends Integer> verses  List<? super Number>. Aside from it being a bit cumbersome to initialize a List<Number>, they all seem to work fine.

(1) Is not List<Integer> completely redundant with List<? extends Integer> because whenever we specify a (non-primitive) type, we are liberty to use that type or a descendant of that type?
I think this is the Liskov substitution principle. So what is the advantage of List<? extends Integer>?

(2) And what about the difference between function parameters of List verses List<Object> verses List<?>? Are these all redundant too?

(3a) And lastly, is it possible to efficiently modify the elements of an existing list instead of creating and returning a new list? While I suppose you could call get and set for a function parameter of type List, I'm worried these would be very inefficient for large linked lists. C++, for example, has a special for-each-loop syntax so you receive a reference to the linked list element instead of a copy.

In other words:
(3b) What is Java doing when I type "for (Integer n: nums){ n = n + 1; }" and nums is a List<Integer>? Apparently it is making a deep copy because when I print out the original List in the main program (or in this case, test function), the original list is not modified. Is there a way to make this do a shallow copy so I modify the original and avoid creating a new list as the function value?

Here is my code that passes all 6 tests:
1 year ago
I'm going nuts trying to find a working example of using Cassandra with a java ORM like I've tried over a half dozen examples and none work
This makes me wonder if there is something wrong with the Cassandra server I am using.

However, this example works in java and groovy. Here is the abbreviated groovy version:

This makes me think that I have the v3.9 cassandra server working correctly.

So here is one of the many examples that I found from google searching that I cannot make work:

I've tried this with Cassandra  (versions 3.7 and 3.9 and 2.0.8) and java 1.8 on Windows 10.

As far as I can tell, everytime I run cassandra 2.0.8, or 3.7 or 3.9, the server is listening on and the default port 9042 and all my clients are also trying to connect to port 9042 (the default).

I've also tried these examples and cannot make them work either:

And some others I cannot remember where I downloaded them from.

Can someone help me fix or find an example that works (preferable an example that uses JUnit to demonstrate that it works)?


1 year ago
I tried those hamcrest matchers and they seem to work for contianers (like sets) of strings.

However, I'm confused about how hamcrest compares containers of containers like Set<Collection<? extends String>>;

In other languages like C++, I can specify the lambda function or to be used for comparing elements of a Set container (for example). I assume in java, that function is Comparable::CompareTo. However, when I look at the documentation, I don't see that classes like List, or Set or ArrayList implement such a function. So how does class Set determine if you are adding a new element that is a duplicate? How does the hamcrest matcher know if a set contains a certain element (in any order)?

I tried creating descendants of ArrayList and List, and String that implement Comparable and failed (perhaps this should be a topic of a different post).
Like I suggested previously, I am surprised there is not some library in the maven repository that implements this already.

Can anyone improve on this awful code I wrote? It works, but it (my function compareIteratorCollections) does not use generics and is not as type-safe as it could be. Can someone show me how to write compareIteratorCollections using generics?

Here is my miserable matcher function:
1 year ago
Please help me understand why this test fails. The first assertThat passes but the assertThat in the for each loop fails.
This is probably because assertThat is doing shallow compares (comparing references) instead of deep compares (comparing the lists element by element).

Perhaps this is because List and ArrayList do not implement Comparable? If so, is there some library available in the maven repository that does have containers (such as lists) that implement Comparable?
If not, why?

2 years ago
Sorry for the confusion.

By maven library I mean JAR files available from the maven repository (probably a bad choice of terms! sorry!)

I have a function called GetPermutations that returns a Set<Collection<String>>.

I want to write a JUnit test for this function.

To write a JUnit test, I need a matcher to compare the actual and expected values.

So I create and populate a variable called expected of type Set<Collection<String>>.

Now, how do I compare "executed" with the returned value from GetPermuations?

Hamcrest is a library available on maven that will allow me to compare Sets if the elements of the set implement Comparable.

Unfortunately, ArrayLists, Arrays Lists don't implement Comparable.

Do you know of any libraries, preferably on the maven repository site, that implement collections that implement Comparable?

I could implement my own as I started to do. Surely someone has already done this and I could use their implementation.

I hope this helps.
Thank you for the very prompt response.

2 years ago
I need to write a JUnit test for a function that produces

When I started to implement this class:

I said to myself: "This is nuts! Surely someone has already done this for Array, LinkedList, ArrayList and friends!

But after google searching, I could not find any such examples...

Can someone point me to a maven library that will help me compare containers containing containers and maybe point me to an example?

I've been using the Hamcrest to compare Sets of Strings. Perhaps all I need is an example of using Hamcrest to compare Sets of Lists of Strings? I'm looking at the hamcrest javadocs and I'm not seeing anything obviouse.

2 years ago
Darn! Where is that edit button?

Regarding "Why do I think JMS is a good option"?  I assumed it was. Clearly AMPQ has some additional features.

Regarding that link: Wow! that is a lot of options! I like ActiveMQ because I can download and install and execute with Maven easily on my local PC.

   Can I have some help selecting one that something similar that has the kind of throttle I described above?


2 years ago
I like this link and the code works:

After google searching "ActiveMQ Throttle" I was surprised that normally this means throttling the producer (or even the TCP connection) and that is not what I want.

So let me restate my question:
Does ActiveMQ have a feature to throttle consumers so that only one message total is received and processed at a time? In the case of throttling for Microsoft's WCF/MSMQ, you need to specify the maximum concurrent instances, concurrent sessions, and concurrent calls (of the consumer) to be one. This is what I want in a java based application.

After reading this link, I think the answer is no:

If this is true, can someone recommend a java/groovy friendly message queue API or framework that does implement this kind of throttling?
From more google searching, it does not look like RabbitMQ supports this either. Strange. This is a feature of the Microsoft's WCF/MSMQ application I'm trying to port to an OS neutral implementation and I'm surprised to be having difficulty finding this feature in the java world.


2 years ago

I want to write a prototype/proof-of-concept application that implements a (cygwin) bash execution queue server (and client) with a throttle so only one queue entry (job) gets executed at a time.

I know that this is a common feature in build environments but I need some simple source code as a starting point for some fancier enhancements.

What do you recommend? JMS via Spring or JMS via EJB? Do you like JMS?

How do I implement that throttle? Is this a feature of JMS or the implementation?
I also need to be able to enumerate entries in the queue and cancel (remove) some entries before they start execution.
And I need to be able to pause the queue so it does not remove the next entry and start execution.

So there is ActiveMQ, RabbitMQ, AMQ and others... Which have the features I need?
This needs to run on Linux and Windows...
Having a queue that can survive reboots would be nice too.
That is all the requirements I can think of right now...

2 years ago
Can you give me some examples or tutorials on how I might implement a paywall and use OAuth?

Does OAuth help me implement my custom authorization or is my custom authorization something I layer on top of my calls to OAuth.
How do I store roles and the user-role relationship?
Do I have to create my own database and manage that myself, possibly with JPA or will OAuth help me?

Oh, and of course: what about SPRING? That has authorization features. Can I use SPRING to implement authorization on top of OAuth? I'd love to see an example of that!

2 years ago
I'm new to OAuth.

I see that if I use OAuth for my site, folks don't have to get a new username and password because they can use their facebook or twitter credentials.

Can I still have different levels of authorization and restrict access to certain pages depending if the user has paid for the service? This authorization feature is a very common feature and I don't understand the relationship between authorization and OAuth.
2 years ago