Java线程:是否可以从同一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'本身是可以容忍的'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.