Siegfried Heintze

Ranch Hand
+ Follow
since Aug 11, 2000
Merit badge: grant badges
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

Rob Spoor wrote:I don't think the issue lies in your dependencies. If it were you'd get compiler errors. I think it's more with how you load the libraries.

All examples I've seen use Kernel32.INSTANCE and User32.INSTANCE. These call Native.load instead of Native.loadLibrary (see Kernel32 and User32). The latter is now deprecated. The calls to load also use some default options.

Shame on me! I should have studied Jeff Heatton's working code more closely and trusted ChatGPT less.

My apologies for being sloppy.

Whoa! This is kinda tedious writing the signature for each function you want to call be fore you call it. Surely, someone else has already done this for Kernel32?  Anyone know of where I might find this?
11 months ago

I'm trying to use and as a guide and the sample works.

I've tried adding this program generated ChatGPT and I'm getting a stack trace

I'm getting this error in IntelligJIdea when using Jeff Heaton's pom.xml file.

I think I need to enhance that pom.xml somehow.



11 months ago

I would like create a little program that plots some 2D points on a display that includes X&Y Axis with tick marks and labels and I am certain that this has already been done many times and being a very lazy programmer I don't want to write this my self because I've done it myself (in other languages decades ago) and surely someone has posted some java/groovy code somewhere.

I've been google searching and cannot find one.  The demo described Function Plotting Demo in GIA Book is nice but I cannot figure out how to add mouse listener to the Swing Builder.

Also, a demo that includes translating from device to world coordinates and world coordinates to device would be nice.
Pan and Zoom would be nice...

OK,... maybe I'm asking a lot but this should be a common thing to do!

Swing is fine. Java or groovy is fine. JavaFX ... I'd have to learn JavaFX but I suppose that would be OK.

I want to create a demo for linear regression where I can enter data with mouse clicks and (re)draw the best fitting line in real time.


2 years ago
The companion code to Groovy In Action 2nd Ed (GIA) has a nice Swing Builder demo program that plots functions (complete with a function parser). I've been looking at Apache Swing Builder Documentation hoping to find how to enhance the GIA example to plot some mouse clicks for a linear regression demo.

Where is the documentation for mouse support for Swing Builder?

How would I setup a Mouse listener for a Swing builder app like this GIA function plotter example ?


2 years ago

Stephan van Hulst wrote:The problem is not specific to ASP.NET Core, but the solution might be.

What solution is appropriate for your setup depends on how your application uses OAuth/OIC. Let's think about it for a second:

Lets say the client sends a bearer token with every request to your backend, and your backend uses the bearer token to perform actions on behalf of the user. Assuming that each node is stateless and uses the same database cluster, then you don't need to do anything at all because there is no cached state that needs to be shared between each application node.

Thanks Stephan....

I've been re-reading the Microsoft Documentation (again) and thinking about your example... Your right: if one node in a replica-set gets a bearer token from a third party authentication service like AzureAD/B2C, then the shared cache should make that available to the other nodes should the load balancer route that user to a different member of the replica set so there is no problem: that new node has the bearer token too (because of the shared cache)! So I wonder if the problem is when you use the (optional) Microsoft ASP.NET data protection feature because you cannot trust your cache with unencrypted data like bearer tokens? Do web server caches typically store bearer tokens unencrypted? If so, then you might want store the bearer tokens as (double?) encrypted in the cache but then the web servers need to safely store some encryption keys someplace else (like the azure key vault) and this ability to store/retrieve encrypted bearer tokens from the cache might be the feature that makes some (but not all) ASP.NET/Kestrel caches magical....

So I guess that begs the question: Is Microsoft the only one in town that offers this data protection feature for web servers? Surely AWS and Google offer it... I wonder what they call it?

Here is what the ASP.NET Data Protection Documentation says:

The canonical example of this is an authentication cookie or bearer token. The server generates an "I am Groot and have xyz permissions" token and hands it to the client. At some future date the client will present that token back to the server, but the server needs some kind of assurance that the client hasn't forged the token. Thus the first requirement: authenticity (a.k.a. integrity, tamper-proofing).

Since the persisted state is trusted by the server, we anticipate that this state might contain information that's specific to the operating environment. This could be in the form of a file path, a permission, a handle or other indirect reference, or some other piece of server-specific data. Such information should generally not be disclosed to an untrusted client. Thus the second requirement: confidentiality.

I assume that "persisted state" means the cache.

This leads me to believe that the Microsoft ASP.NET web server (Kestrel) does not by default encrypt its caches... And I'm guessing that the Tomcat, Jetty, nodejs web servers don't encrypt their bearer tokens (when storing them in the shared cache) either because you don't typically specify a third party key store...

I thought the big feature with JWT and bearer tokens was that they were encrypted and could not be forged easily (because of signatures) and that may be true for transmission over socket connections...  But, lets suppose you store the encrypted JWT/Bearer token in your cache and the cache is not secure and someone gets the encrypted bearer token and sends it to the web server.... Oh oh! Data breach!

Hmmm... Comments?
2 years ago
I have a question about creating a webapp (maybe springboot) that uses a common java based web servers like Tomcat or Jetty that Authenticates/Authorizes using OAuth/OpenIDConnect in a web farm environment (like a Kubernetes Replica set that has a auto scaler).


The microsoft documentation says: When Data Protection or caching isn't configured for a web farm environment, intermittent errors occur when requests are processed. This occurs because nodes don't share the same resources and user requests aren't always routed back to the same node.  A few paragraphs later they say

When any of the following symptoms occur intermittently, the problem is usually traced to improper Data Protection or caching configuration for a web farm environment:

Authentication breaks: The authentication cookie is misconfigured or can't be decrypted. OAuth (Facebook, Microsoft, Twitter) or OpenIdConnect logins fail with the error "Correlation failed."

Elsewhere they provide a list of magical caching plugins (not any cache will do ... I know this from hard experience) for C#/ASP.NET programmers that accommodate OpenIDConnect on web farms. Elsewhere they list the magical caching plugins to make your web app compatible with web farms and OpenIDConnect...

So my question is: Is the Microsoft documentation addressing problems specific to using ASP.NET with OpenIDConnect implementations on a web farm or is the need for magical caching plugins common to all web servers (like tomcast/jetty/nodejs) implementing OpenIDConnect in a web farm (like Kubernetes replica sets)? Again: I use the word magical here because not any  C#/ASP.NET redis cache (for example) will do the job.

In other words: if I deploy my springboot/tomcat webapp and use OAuth/OpenIDConnect to Authenticate/Authorize my users when the web app is running  with an autoscaler inside a kubernetes replica set, do I need to call some magical caching function? If so, were is the list of magical caching functions?

What is the appropriate forum to post this question in?


2 years ago
Wow! This is very strange...

I did not reboot or even restart the database (mysqld)...
Two days later it works for no apparent reason...

Anyone have any ideas?
3 years ago
I have a perl program that uses the same environment variables as my groovy code below and successfully displays the result from gov_unit.
So I know that the server is running, the IP address is correct, the table name and database name are correct and the user name/password are correct. However, when I run the following groovy program
it throws the exception:

java.sql.SQLNonTransientConnectionException: Could not create connection to database server. Attempted reconnect 10 times. Giving up.

I'm using groovy console 4.0.0.-alpha 1. Switching to Groovy 3.0.4 or 3.0.2 yields the same results...
I'm using Windows MySQL server 8.0.17-winx64 which was unzipped (instead of installed).
I could not find any config files like my.ini to experiment with changing the bind address.... However, since perl works, this should not be a problem.


3 years ago
There used to be an edit button so I could correct typos in my newly created post (that I missed using the previous feature). I don't see it now. Is it gone forever or just hiding?

5 years ago
I have a lot of questions on designing and implementing many-to-many relationships. It seems logical to me that there would be some book I could buy that would cover these issues but I have not found one yet. Can someone recommend a tutorial that discusses more than one brand of database?

I'm asking these questions for several reasons. Since I'm in between gigs I'm starting a new entrepreneurial effort that might make me some money and (more importantly) look good on my resume and help me brush up my java/database skills. I'm in the process of selecting database vendors, cloud vendors and frameworks (JDBC, springboot or EJB or ?, hibernate-database-first or hibernate-code-first, IBatis etc...)

Here is one sample many to many implementation from Microsoft: Northwind and PUBS sample databases for MSSQL Server. The Pubs database contains an implementation of a authors to book-titles many-to-many relationship I have been playing with.
(Yes, these are microsoft samples, but I'm interested in discussing junction tables in the context of the popular databases including MySQL, Oracle, PostgresSQL and MS SQL Svr).

To simplify things a bit, lets assume that my junction table only needs to contain the foreign key for the book and the foreign key for the author.

(1) What are some good naming conventions for the tables? Do I call the the table author or authors? books or book? What do I call the junction table? book2Author? What about reverse engineering feature in hibernate? I just discovered that has some rules about capitalization but I have not found them yet.

(2) I tend to use the popular approach of auto-increment integers as the primary key (I typically call this field "ID") for my tables. Does using an auto increment field called ID make sense for a junction table? It seems superfluous to me (unless of course, this is a ternary relationship and the auto increment id field of the junction table is going to be a foreign key field in a fouth table).

(3) What should I define as the primary key of a junction table? I think I want the concatenation of the two foreign keys to be unique to preserve referential integrity. Is this true? If so, should I make the primary key consist of the two foreign keys? Yikes -- now I am creating an index structure exclusively for referential integrity that will only hinder performance -- correct? When would I ever use a junction table if I already knew both foreign keys? The only time I would use a junction table is if I know the author_id and want the (multiple) book_id or I know the book_id and want the (multiple) author_ids. Correct? So what is the recommendation? Do I create a primary key consisting of both foreign keys, an index of just the author_id and another index of just the book_id so that each time I insert a row into the junction table I have to update three index structures?

(4) What is the favorite approach to populating these tables with test data? Is there a vendor neutral approach to dealing with SQL insert statements and those pesky auto increment fields? MS SQL Server and Oracle have a feature to allow you to temporarily specify the (otherwise) auto increment id fields of books and authors where you can subsequently hard code these ID fields as insert statements into the junction table (for test data only, of course). Alternatively, they also have features for retrieving the newly generated ID field from the INSERT statement. I think MSSql has the @@IDENTITY feature for this and MySQL has the last_insert_id(). Is there vendor neutral way of doing this? Are there any java/JDBC/hibernate/IBatis features to help me write vendor neutral code?

(5) Now what about production code and transactions? Do I need a transaction for anyone one of the CRUD operations on table that is part of a many-to-many relationship?
(5a) How do I insert into the book table, fetch the newly created integer ID, insert into the author table, fetch the second newly created ID and insert the two new IDs into the junction table? Do I have to create a transaction for this? How do I fetch the newly created IDs? When populating the test data I can hard code the integer ids (maybe) but not in production.
(5b) How do I delete a book? Do I delete the entries in the junction table first and then the book table? Does this need a transaction? What about the cascading delete feature (ON DELETE CASCADE) in MySQL? Do I want to use it? Can JDBC or hibernate or Ibatis help me implement "ON DELETE CASCADE" in a vendor neutral way?
(5c) What about reading? Do I need a transaction to find all the authors of a given book?
(5d) If I am just updating a book, I believe I don't need a transaction (assuming I'm not adding any authors). Is this true? Maybe not! What if I'm trying to update a book that has a single author and someone else is simultaneously trying to delete that book using the cascading delete feature?


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.

5 years 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?

7 years 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?

7 years ago
Thank you everyone. That was very helpful.

7 years 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:
7 years ago