Three years on, JNet still runs a real JVM inside the .NET process, but the boundary is now much cheaper: generated C# wrappers, a two-gate event filter and zero-copy array access. The follow-up article quantifies what changed and where the limits remain.
Key points
- JNetReflector turns any JAR into compilable C#: generics, listener wiring, Dispose patterns and InvokeWithSignature.
- JNet 2.6.7+ adds ListenerShallManageEvent, whose two gates discard unhandled JVM events in 30–35 ns.
- Instance calls reach 162 ns on .NET 8 and 178 ns on .NET 10 with InvokeWithSignature, down 65% from 2.6.6.
- JCOBridgeStream and JCOBridgeDirectBuffer expose JVM arrays as ReadOnlySpan; DirectByteBuffer AsSpan is zero-copy without HPA.
- DirectByteBuffer AsSpan moves 100 MB at 17.9 GB/s, while the naive MemoryStream path is seven times slower.
- A pooled thread-local buffer replaced per-event allocations, cutting test time from 23s to 14s.
Why it matters
This matters to teams that keep a Java-only library or a Kafka/streams stack in their .NET solution: generated C# from a JAR replaces hand-written JNI glue, which is where most of the maintenance pain sat. The real value is the measured cost of each event; dropping unhandled event types at the first gate is two orders of magnitude cheaper than a full invocation. Read the tables carefully though — the .NET 10 columns are not uniformly faster than .NET 8, so do not assume a runtime upgrade buys you anything in your own scenario. Zero-copy also depends on the edition: verify JCOBridge.IsHPAEdition, the versions (JNet 2.6.7+, JCOBridge 2.6.9) and the one-JVM-per-process lifecycle before you adopt it.
Real-world use
- A .NET service consuming Kafka topics through KNet, which is generated on top of JNet.
- EF Core applications reading Kafka records via the KEFCore provider.
- A Kafka Streams or OPC-UA subscription that fires many event types, most with no .NET handler.
- Embedding AWT/Swing screens inside a WinForms or WPF desktop app.
- Pulling 100 MB audio samples or sensor payloads from JVM memory into .NET without copying.
This summary was generated by the agent from the original post on DEV Community: #dotnet. The full text and all rights belong to its author and publisher. Go to original