简体   繁体   中英

Can I use the command line/a script to modify variables in a java program that is already running

I have a threaded TCP connection that is essentially waiting to receive messages inside a while(true) loop. The functionality of the program itself works great but it is not closing the socket/thread gracefully on exit and occasionally I get zombie processes that I have to kill before I can reconnect on the same port. I am writing a script that is going to be in charge of closing this and another program that runs in parallel with it. Originally my plan was to use a ShutdownHook to clean everything up at the end but the shutdown hook is being triggered by the script which kills the process.

Is there any way that I can pass information to/modify a variable in the Java program while it is already running such as the boolean associated with the while loop? [while(true) just seems like bad coding]

If not does anyone have a better idea of how to use a script to clean up and close more gracefully a program that is running as a jar with no GUI.

Thanks in advance

It is hard to understand why this is needed. Can't the program be debugged to determine a better/more reliable way of ensuring the socket is closed properly before exit?

You could look into the use of system variables that the program looks at have an outside element influence the running logic state of your application.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM