简体   繁体   English

外部Java程序:处理SIGTERM

[英]External java program: Handle SIGTERM

I have java program (with a gui) which is running on a host. 我有一个在主机上运行的Java程序(带有gui)。 On runtime a user can add some data records. 在运行时,用户可以添加一些数据记录。 The program just works with them. 该程序只适用于他们。

Later the system maybe shuts down or the program is just closed by SIGTERM. 稍后,系统可能会关闭,或者该程序刚刚被SIGTERM关闭。

Unfortunately the porgram only seems to store the data records if it is closed manually by the user with the "X". 不幸的是,如果用户使用“ X”手动将其关闭,则该porgram似乎仅存储数据记录。

Now i have the problem that i maybe lose some data if the program is closed by SIGTERM. 现在我有一个问题,如果程序被SIGTERM关闭,我可能会丢失一些数据。 Unfortunately there is no contact email address to ask the author for the change. 不幸的是,没有联系电子邮件地址要求作者进行更改。

I tried to decompile it with "jd gui" which seemed to work more or less. 我试图用似乎或多或少起作用的“ jd gui”反编译它。 I thought then i just could add the signal handler and invoke the "window close" method. 我以为那我可以添加信号处理程序并调用“窗口关闭”方法。

But "jd gui" created code like this: 但是“ jd gui”创建了如下代码:

/* 110:269 */       if ((??? = Thread.currentThread().getContextClassLoader()) != null) {
/* 111:270 */         return ???;

And i also get many other errors if i try to compile the source. 如果我尝试编译源代码,我还会遇到许多其他错误。

I think this is because the jar file is obfuscated by some tool. 我认为这是因为jar文件被某些工具混淆了。 Unfortunately the decompiled code doesn't work and i am not able to recompile the file with the JFrame. 不幸的是,反编译后的代码无法正常工作,而且我无法使用JFrame重新编译文件。

Long story short: Is it possible to write a "wrapper program" which just handles SIGTERM and then invokes the JFrame "close method" (or how it is called) of the main frame (which is the only JFrame)? 长话短说:是否可以编写一个仅处理SIGTERM的“包装程序”,然后调用主框架(这是唯一的JFrame)的JFrame“关闭方法”(或如何调用)?

I just do not know how to invoke such a method of an external running java program. 我只是不知道如何调用外部运行的Java程序的这种方法。

Thank you very much. 非常感谢你。

Best regards Kevin 最好的问候凯文

Try to deobfuscate the application. 尝试对应用程序进行模糊处理。 Have a look here (2009) - Tool to deobfuscate Java codes . 在这里看看(2009)-用于反混淆Java代码的工具

Maybe it is possible to resolve the source so that you are able to diggin deeper into the source and compile it. 也许可以解析源代码,以便您能够更深入地挖掘源代码并进行编译。

Otherwise it is quite complicated to hook into a Swing based ui event queue from outside a wrapper application. 否则,从包装应用程序外部插入基于Swing的ui事件队列非常复杂。

Maybe you can decompile the main class and replace its main method with your own and add a shutdownhook see: Useful example of a shutdown hook in Java? 也许您可以反编译主类,并用自己的主类替换其主方法,并添加一个shutdownhook请参见: Java中的shutdown钩子的有用示例? which calls the onClose (deobfuscated) method. 该方法调用onClose(反混淆)方法。

Any way, an interesting and challening question! 无论如何,这是一个有趣而充满挑战的问题!

Create your own class with a main method which installs a shutdown hook to save before closing. 使用main方法创建自己的类,该方法将安装关闭钩子以在关闭前进行保存。 then invoke the original programs main method. 然后调用原始程序的main方法。 add this to the jar and use this class to launch the program. 将其添加到jar并使用此类启动程序。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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