Mein Programm wird nicht stop nach run () - Methode in der main-thread endet

Ich bin mit Java. Der main-thread sendet die Daten an, während ein worker-thread lauscht auf Antworten. Ich habe auch Timer bei timeout Auftritt. In main () rufe ich die run(), die das beenden kann, entsprechend der Ausgabe. Hier ist, wie es aussieht:

class Send {
    Worker w;

    run() {
        //w was initialized in constructor
        w.start();
        ....
        w.join();
    }

    main(args) {
        Send s = new Send();
        s.run();
    }
    private class Worker extend Thread {
        public void run() {
            ....
        }
    }
} 

In s.run(), jedes mal wenn ich cancel den Timer oder den Timer neu starten, würde ich tun,

timer.cancel();
timer.purge();
timer = new Timer();
timer.schdule(...);

Den TimerTask ist einfach Aufruf einer statischen Methode in Senden zu behandeln, das timeout.
Also, was habe ich falsch gemacht, daß mein Programm hängen, nachdem der Haupt-thread beendet wird?
Danke.


EDIT: der out-put des kill -3 process-id:

Full thread dump OpenJDK 64-Bit Server VM (19.0-b09 mixed mode):

"DestroyJavaVM" prio=10 tid=0x00007f9f20035000 nid=0x73f1 waiting on condition [0x0000000000000000]
   java.lang.Thread.State: RUNNABLE

"Timer-10" prio=10 tid=0x0000000001a7d800 nid=0x740f in Object.wait() [0x00007f9f1e39c000]
   java.lang.Thread.State: WAITING (on object monitor)
    at java.lang.Object.wait(Native Method)
    - waiting on <0x000000075833fe78> (a java.util.TaskQueue)
    at java.lang.Object.wait(Object.java:502)
    at java.util.TimerThread.mainLoop(Timer.java:505)
    - locked <0x000000075833fe78> (a java.util.TaskQueue)
    at java.util.TimerThread.run(Timer.java:484)

"Low Memory Detector" daemon prio=10 tid=0x00007f9f20004800 nid=0x7402 runnable [0x0000000000000000]
   java.lang.Thread.State: RUNNABLE

"CompilerThread1" daemon prio=10 tid=0x0000000001a70000 nid=0x7401 waiting on condition [0x0000000000000000]
   java.lang.Thread.State: RUNNABLE

"CompilerThread0" daemon prio=10 tid=0x00007f9f20001000 nid=0x7400 waiting on condition [0x0000000000000000]
   java.lang.Thread.State: RUNNABLE

"Signal Dispatcher" daemon prio=10 tid=0x0000000001a6e800 nid=0x73ff waiting on condition [0x0000000000000000]
   java.lang.Thread.State: RUNNABLE

"Finalizer" daemon prio=10 tid=0x0000000001a49000 nid=0x73fe in Object.wait() [0x00007f9f1f3f2000]
   java.lang.Thread.State: WAITING (on object monitor)
    at java.lang.Object.wait(Native Method)
    - waiting on <0x00000007580b1310> (a java.lang.ref.ReferenceQueue$Lock)
    at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:133)
    - locked <0x00000007580b1310> (a java.lang.ref.ReferenceQueue$Lock)
    at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:149)
    at java.lang.ref.Finalizer$FinalizerThread.run(Finalizer.java:177)

"Reference Handler" daemon prio=10 tid=0x0000000001a47000 nid=0x73fd in Object.wait() [0x00007f9f1f4f3000]
   java.lang.Thread.State: WAITING (on object monitor)
    at java.lang.Object.wait(Native Method)
    - waiting on <0x00000007580b11e8> (a java.lang.ref.Reference$Lock)
    at java.lang.Object.wait(Object.java:502)
    at java.lang.ref.Reference$ReferenceHandler.run(Reference.java:133)
    - locked <0x00000007580b11e8> (a java.lang.ref.Reference$Lock)

"VM Thread" prio=10 tid=0x0000000001a40000 nid=0x73fc runnable 

"GC task thread#0 (ParallelGC)" prio=10 tid=0x00000000019d7000 nid=0x73f2 runnable 

"GC task thread#1 (ParallelGC)" prio=10 tid=0x00000000019d9000 nid=0x73f3 runnable 

"GC task thread#2 (ParallelGC)" prio=10 tid=0x00000000019da800 nid=0x73f4 runnable 

"GC task thread#3 (ParallelGC)" prio=10 tid=0x00000000019dc800 nid=0x73f5 runnable 

"GC task thread#4 (ParallelGC)" prio=10 tid=0x00000000019de800 nid=0x73f6 runnable 

"GC task thread#5 (ParallelGC)" prio=10 tid=0x00000000019e0000 nid=0x73f7 runnable 

"GC task thread#6 (ParallelGC)" prio=10 tid=0x00000000019e2000 nid=0x73f8 runnable 

"GC task thread#7 (ParallelGC)" prio=10 tid=0x00000000019e4000 nid=0x73f9 runnable 

"GC task thread#8 (ParallelGC)" prio=10 tid=0x00000000019e5800 nid=0x73fa runnable 

"GC task thread#9 (ParallelGC)" prio=10 tid=0x00000000019e7800 nid=0x73fb runnable 

"VM Periodic Task Thread" prio=10 tid=0x00007f9f20007800 nid=0x7403 waiting on condition 

JNI global references: 886

Heap
 PSYoungGen      total 150528K, used 7745K [0x00000007580b0000, 0x00000007628a0000, 0x0000000800000000)
  eden space 129088K, 6% used [0x00000007580b0000,0x00000007588405b8,0x000000075fec0000)
  from space 21440K, 0% used [0x00000007613b0000,0x00000007613b0000,0x00000007628a0000)
  to   space 21440K, 0% used [0x000000075fec0000,0x000000075fec0000,0x00000007613b0000)
 PSOldGen        total 343936K, used 0K [0x0000000608200000, 0x000000061d1e0000, 0x00000007580b0000)
  object space 343936K, 0% used [0x0000000608200000,0x0000000608200000,0x000000061d1e0000)
 PSPermGen       total 21248K, used 3130K [0x00000005fdc00000, 0x00000005ff0c0000, 0x0000000608200000)
  object space 21248K, 14% used [0x00000005fdc00000,0x00000005fdf0ea30,0x00000005ff0c0000)
  • ist Ihr Arbeitnehmer die run () - Methode, logisch zu Ende?
  • Sie haben, um eine nicht-daemon-thread, und führen Sie die Anwendung ausführen. Wenn Sie nur daemon-threads-der Prozess beendet wird.
  • Sieht aus wie Sie einen Timer-thread noch läuft - Timer-10 thread im WAIT-Zustand. Sie sind wahrscheinlich nicht aufrufen cancel() auf einem der Timer-Objekte.
InformationsquelleAutor derrdji | 2011-06-28
Schreibe einen Kommentar