M
M
mitaichik2017-02-14 02:46:24
Java
mitaichik, 2017-02-14 02:46:24

How to send commands to a running application?

Hello! Newbie in java.
I have an application, it is constantly running (it does not have access to the outside world), it uses Spring. Sometimes I need to send him some commands, for example, clear the internal cache, recalculate something, etc.
I don’t need any wisdom, it’s stupid to send him a few commands from the console, well, look at the answer that it will display.
So far, it only occurs to me to use sockets - to embed ServerSocket into the application and connect to it. But what is already ready?
Thanks in advance!

Answer the question

In order to leave comments, you need to log in

3 answer(s)
V
Viktor Maksimov, 2017-02-14
@mitaichik

Of course have. There are two options as always.
1. MBean read here docs.spring.io/spring/docs/current/spring-framewor...
As a result, we get the ability to control the application, for example, through jvisualvm and the mbean plugin to it. Quite convenient.
2. The most convenient option for me if spring boot is used. Here you can deploy to docs.spring.io/spring-boot/docs/current/reference/...
As a result, we get the opportunity to connect to the application via ssh, to implement our own console commands. And also we get a service REST API with a bunch of built-in functionality.
Hope it helped.

S
ShamilSungatov, 2017-02-14
@ShamilSungatov

https://ru.wikipedia.org/wiki/%D0%A3%D0%B4%D0%B0%D...
But it seems to me that it would be easier to do it through webservices

D
Dmitry Alexandrov, 2017-02-14
@jamakasi666

There is also a crutch option, but nonetheless convenient in many cases.
You make the usual System.in \ out console with the commands you need in the software itself. Next, write a shell script in which you describe, for example, start\stop\status\restart\exec (command). The launch of the software should be done in screen with which some of the script commands will work. You launch the software accordingly already through this script.
The output will be the following, regularly cling to the server via ssh and pull this script as you like. Also in the script itself, you can make an automatic restart of the software if it has fallen.
Although the method is really a crutch, it is still very convenient and you don’t have to worry about safety.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question