这实际上是你需要启动一个服务:监听到stop的命令的时候把全部的服务退出。也就是说它是一个用来管理你应用的服务。像tomcat也是它的http服务在8080,他的管理端口在另外一个端口

解决方案 »

  1.   

    Why is Thread.stop deprecated?
    Because it is inherently unsafe. Stopping a thread causes it to unlock all the monitors that it has locked. (The monitors are unlocked as the ThreadDeath exception propagates up the stack.) If any of the objects previously protected by these monitors were in an inconsistent state, other threads may now view these objects in an inconsistent state. Such objects are said to be damaged. When threads operate on damaged objects, arbitrary behavior can result. This behavior may be subtle and difficult to detect, or it may be pronounced. Unlike other unchecked exceptions, ThreadDeath kills threads silently; thus, the user has no warning that his program may be corrupted. The corruption can manifest itself at any time after the actual damage occurs, even hours or days in the future. --------------------------------------------------------------------------------Couldn't I just catch the ThreadDeath exception and fix the damaged object?
    In theory, perhaps, but it would vastly complicate the task of writing correct multithreaded code. The task would be nearly insurmountable for two reasons:A thread can throw a ThreadDeath exception almost anywhere. All synchronized methods and blocks would have to be studied in great detail, with this in mind. 
    A thread can throw a second ThreadDeath exception while cleaning up from the first (in the catch or finally clause). Cleanup would have to repeated till it succeeded. The code to ensure this would be quite complex. 
    In sum, it just isn't practical. 
    --------------------------------------------------------------------------------What about Thread.stop(Throwable)?
    In addition to all of the problems noted above, this method may be used to generate exceptions that its target thread is unprepared to handle (including checked exceptions that the thread could not possibly throw, were it not for this method). For example, the following method is behaviorally identical to Java's throw operation, but circumvents the compiler's attempts to guarantee that the calling method has declared all of the checked exceptions that it may throw:     static void sneakyThrow(Throwable t) {
            Thread.currentThread().stop(t);
        }--------------------------------------------------------------------------------What should I use instead of Thread.stop?
    Most uses of stop should be replaced by code that simply modifies some variable to indicate that the target thread should stop running. The target thread should check this variable regularly, and return from its run method in an orderly fashion if the variable indicates that it is to stop running. (This is the approach that JavaSoft's Tutorial has always recommended.) To ensure prompt communication of the stop-request, the variable must be volatile (or access to the variable must be synchronized). For example, suppose your applet contains the following start, stop and run methods:     private Thread blinker;    public void start() {
            blinker = new Thread(this);
            blinker.start();
        }    public void stop() {
            blinker.stop();  // UNSAFE!
        }    public void run() {
            Thread thisThread = Thread.currentThread();
            while (true) {
                try {
                    thisThread.sleep(interval);
                } catch (InterruptedException e){
                }
                repaint();
            }
        }You can avoid the use of Thread.stop by replacing the applet's stop and run methods with: 
        private volatile Thread blinker;    public void stop() {
            blinker = null;
        }    public void run() {
            Thread thisThread = Thread.currentThread();
            while (blinker == thisThread) {
                try {
                    thisThread.sleep(interval);
                } catch (InterruptedException e){
                }
                repaint();
            }
        }
      

  2.   

    joachimz(joachimz) 
    你这种说法不是我想知道的,tomcat有通过web端口8007来管理web站点的功能.但我现在非常非常想知道的是java进程之间能不能通信??,是怎样通信的??tomcat好像是通过实现一个Daemon接口,daemon接口有start(),stop()等方法.而看tomcat程序实现这两个方法的程序实在是困难的事情,我没有找到具体是哪个类实现的stop方法才是核心方法.由于我这个服务器程序要在linux的命令行模式下使用.是以后台的方式运行的.
    所以boss要求能够通过start, stop来开启或退出服务.而不是杀死服务进程.那样会造成其他java程序(tomcat)也会被杀死
      

  3.   

    你在监听的端口上一看关闭请求来了,就停止服务。
    停止的方法很多, takecare已经说得很清楚了。
    最好不要用pipe实现进程间通信,可以实现,
    但是这里不适用于你,放弃这个念头吧。
    你可以参考tomcat,weblogic的实现。