Fork me on GitHub
#java
<
2021-10-15
>
Linus Ericsson13:10:46

Is it possible to do any network stack introspection in java? like getting the Socket-object using a certain port inside the JVM?

jumar15:10:30

What problem are you trying to solve?

Linus Ericsson15:10:19

I just dropped a running Jetty server and had to restart the jvm for the nth time.

jumar15:10:50

So to make Jetty stop listening on the port you have to restart the process?

Linus Ericsson15:10:28

Yes, i drop the thread (running in the repl/development)

jumar15:10:54

What you mean by “drop”?

Linus Ericsson15:10:40

I start the server, then i loose the reference to the running server, cannot stop it and it blocks the port.

jumar15:10:12

Ah, so you should then save the reference in a var.

Linus Ericsson15:10:13

Yes. But the problem is that it easy to reload the namespace or similar and drop the server anyway. Defonce doesnt always work either.

jumar15:10:16

When defonce doesn’t work? Tools.refresh?

jumar15:10:04

If you are just playing around you can save the reference inside a comment block.

rickmoynihan14:10:34

*1 *2 and *3 are also your friends if you forget to hold it somewhere; but only if you remember to bind it or close it before you’ve entered 3 things in your REPL 🙂

Linus Ericsson14:10:32

I would just want to have the ability to go somewhere in jetty and kill everything. Or just interrupt the thread from the JVM or something similar.

rickmoynihan14:10:49

you may be able to find something in jetty, if it holds things in a static variable or something… However it’s also a general problem, so better solved with general solutions. FWIW you’ll rarely lose the reference if you use a component system; something like integrant with its repl tools etc.

jumar14:10:41

You can list all the threads and try to find the right one and interrupt it. You can also use advanced stuff like hotspot serviceability agent and do all sorts of crazy stuff but you don’t want that. I’d really question your project/workflow setup - once I got it right I’ve never had such problem or it was very rare and I could just restart the repl