I have developed a shell script, which calls main method of a java program RHEL
environment.
Shell script ( say app.sh
) have multiple options on the lines of tomcat.sh
start:
It will start a java program by calling main method
stop:
It will get running process id and kill the process
I have already implemented start
and stop
command and looking forward to implement pause command.
pause:
This option should get the pid of running java application and call a non-Main method .
I don't have issues to get the process id. But can I invoke non-Main method of java program from running process id?
EDIT:
How can I call a method in an object from outside the JVM? question offer solutions in different technologies but I can't move to different technology except using shell script.
The solution would be like the following:
The SO question that I mentioned in the comments contains all necessary technical details. Actually all credits should be given there, I'm just rearranging their words.
Alternatively in Unix-like systems, including Linux you may send a SIGSTOP signal for a given pid ( kill -STOP <pid>
), and the JVM will be stopped unconditionally until SIGCONT is received ( kill -CONT <pid>
). But I guess it'd be an overwhelmingly brutal solution. Likely you will lose all opened connections etc.
I have found one solution to get rid of limitation of she'll script calling only main method of a program.
One more solution: call a jsp page, which invokes remote method on Program A by using wget command from script in pause option.
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.