r/java • • 11h ago

JobRunr's "black magic" lambda parsing no longer needs ASM (uses the JDK 25 Class-File API)

https://www.jobrunr.io/en/blog/jobrunr-v9.1.0/
39 Upvotes

5 comments sorted by

2

u/TyGirium 9h ago

Java can serialize functional interface's lambda into SerializedLambda by itself. Why is JobRunr using some custom parsing, for speed? Not saying they are doing something wrong, I am just curious what was the reason.

3

u/iNX0R 7h ago

JobRunr parses the lambda through the SerializedLambda to get a Job's metadata (class, method, parameters and their values). These are all then serialized to JSON and saved in a database for later execution. It has a few but important practical benefits, such as being nicer to display in the UI or better portability by not depending on compiler details (it's important that a serialized job keep working over different deployments). We also avoid asking every argument captured by the lambda to implement Serializable (we don't need/want to serialize a bean captured by the lambda).

4

u/definitelyoneof 8h ago

I'm pretty sure they (ab)use SerializedLambda already, but they also have to parse lamba bodies to discover what methods it calls, which is where ASM comes in.

5

u/iNX0R 7h ago

Spot on u/definitelyoneof. SerializedLambda gives us the synthetic lambda$... method and captured values, and then bytecode parsing walks that lambda body to find the actual method call and parameters. On JDK 8 to 24 that is ASM; on JDK 25+ our Multi-Release JAR swaps that step over to java.lang.classfile instead.

2

u/TyGirium 7h ago

Thank you both!