我编写了一个从我的邮件帐户中检索邮件的 Java 程序。
此 jar 由 Ubuntu 服务器上的 cronjob 每 15 分钟调用一次。
定时任务:
/bin/sh /root/scripte/cron_bugtracker.sh
cron_bugtracker.sh:
java -jar /path/to/file.jar
jar 工作正常,但程序不退出。
当我这样做时,它总是使用as 命令ps ax | grep java
显示很多 java 进程:java -jar /path/to/file.jar
32208 ? Sl 0:59 java -jar /path/to/file.jar
我的 Java 程序是这样工作的:
- 在主要我调用构造函数
- 在构造函数中,我使用 javax.mail 调用获取邮件的方法。*
- 然后程序就完成了……至少应该是
有谁知道为什么程序不退出?请帮忙。
编辑:
在日志文件中我发现了这个:
“控制”是我的主类的名称。
Full thread dump Java HotSpot(TM) Client VM (23.1-b03 mixed mode):
"Service Thread" daemon prio=10 tid=0xb76bd000 nid=0x292 runnable [0x00000000]
java.lang.Thread.State: RUNNABLE
"C1 CompilerThread0" daemon prio=10 tid=0xb76bb400 nid=0x291 waiting on condition [0x00000000]
java.lang.Thread.State: RUNNABLE
"Signal Dispatcher" daemon prio=10 tid=0xb76b9800 nid=0x290 waiting on condition [0x00000000]
java.lang.Thread.State: RUNNABLE
"Finalizer" daemon prio=10 tid=0xb7681c00 nid=0x28f in Object.wait() [0xa10ad000]
java.lang.Thread.State: WAITING (on object monitor)
at java.lang.Object.wait(Native Method)
- waiting on <0xa1585650> (a java.lang.ref.ReferenceQueue$Lock)
at java.lang.ref.ReferenceQueue.remove(Unknown Source)
- locked <0xa1585650> (a java.lang.ref.ReferenceQueue$Lock)
at java.lang.ref.ReferenceQueue.remove(Unknown Source)
at java.lang.ref.Finalizer$FinalizerThread.run(Unknown Source)
"Reference Handler" daemon prio=10 tid=0xb7680000 nid=0x28e in Object.wait() [0xa10fe000]
java.lang.Thread.State: WAITING (on object monitor)
at java.lang.Object.wait(Native Method)
- waiting on <0xa1585228> (a java.lang.ref.Reference$Lock)
at java.lang.Object.wait(Object.java:503)
at java.lang.ref.Reference$ReferenceHandler.run(Unknown Source)
- locked <0xa1585228> (a java.lang.ref.Reference$Lock)
"main" prio=10 tid=0xb7606000 nid=0x28c runnable [0xb77ae000]
java.lang.Thread.State: RUNNABLE
at java.lang.ClassLoader.findBootstrapClass(Native Method)
at java.lang.ClassLoader.findBootstrapClassOrNull(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
- locked <0xa1855398> (a java.lang.Object)
at java.lang.ClassLoader.loadClass(Unknown Source)
at com.sun.mail.pop3.POP3Folder.createMessage(POP3Folder.java:362)
at com.sun.mail.pop3.POP3Folder.getMessage(POP3Folder.java:343)
- locked <0xa18261a0> (a com.sun.mail.pop3.POP3Folder)
at javax.mail.Folder.getMessages(Folder.java:947)
- locked <0xa18261a0> (a com.sun.mail.pop3.POP3Folder)
at javax.mail.Folder.search(Folder.java:1231)
at Control.receive(Control.java:53)
at Control.<init>(Control.java:29)
at Control.main(Control.java:24)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader.main(JarRsrcLoader.java:58)
"VM Thread" prio=10 tid=0xb767a800 nid=0x28d runnable
"VM Periodic Task Thread" prio=10 tid=0xb76bf800 nid=0x293 waiting on condition
JNI global references: 163
Heap
def new generation total 4928K, used 2907K [0xa1580000, 0xa1ad0000, 0xa6ad0000)
eden space 4416K, 65% used [0xa1580000, 0xa1856e20, 0xa19d0000)
from space 512K, 0% used [0xa19d0000, 0xa19d0000, 0xa1a50000)
to space 512K, 0% used [0xa1a50000, 0xa1a50000, 0xa1ad0000)
tenured generation total 10944K, used 0K [0xa6ad0000, 0xa7580000, 0xb1580000)
the space 10944K, 0% used [0xa6ad0000, 0xa6ad0000, 0xa6ad0200, 0xa7580000)
compacting perm gen total 12288K, used 2688K [0xb1580000, 0xb2180000, 0xb5580000)
the space 12288K, 21% used [0xb1580000, 0xb1820230, 0xb1820400, 0xb2180000)
No shared spaces configured.