Java 线程:是否可以从在同一 JVM 上运行的不同 Java 程序查看/暂停/杀死特定线程?

2022-01-16 00:00:00 multithreading jvm java

我有一个程序 'foo' 运行不同的线程,fooT1、fooT2、.. fooTn.

I have a program 'foo' running different threads, fooT1, fooT2, .. fooTn.

现在,如果我想编写另一个程序bar",它可能会杀死线程 fooTr,这可能吗?

Now if I want write another program 'bar', which could kill the thread fooTr, is that possible?

原因:线程 fooTr 跟踪产品许可证之一.如果这个线程被杀死;一个人可以无限期地运行这个产品.杀死 'foo' 本身是可以容忍的,因为这正是许可证到期时所做的事情.

Reason: One of the thread fooTr tracks product license. If this thread is killed; one may run this product indefinitely. And killing 'foo' itself is tolerable as 'foo' as that is exactly what is being done on license expiry.

系统:Linux 的 Fedora 发行版

System: Fedora Distribution of Linux

注意:启动 JVM 和程序 foo 的命令放在/etc/init.d 中,任何对 rc.1/rc.2/rc.3 结构有相当了解的人都可以更改/添加启动参数到这些.

Note: The commands which start JVM and program foo are placed in /etc/init.d and anyone who has a decent knowledge of rc.1/rc.2/rc.3 structure can change/add the starting parameters to these.

我希望我的问题很清楚.如果没有,我可以随时编辑它.

I hope my question is clear. If not, I can always edit it.

推荐答案

据我所知,直接这样做是不可能的.但是,您可以考虑在您的foo"上创建某种服务,可以从bar"调用该服务以终止线程.当然,有数百种方法可以实现这一点.我的第一个想法是使用 RMI.

To my knowledge it is not possible to do this directly. What you could consider however is to create some kind of service on your 'foo' that can be called from 'bar' to kill the thread. There are, of course, hundreds of ways to implement this. My first thought would be to do this using RMI.

相关文章