Reputation: 2589
i've written an Java program that retrieves Mails from my mail account.
This jar is called by a cronjob on a Ubuntu Server every 15 minutes.
cronjob:
/bin/sh /root/scripte/cron_bugtracker.sh
cron_bugtracker.sh:
java -jar /path/to/file.jar
The jar works fine but the program dosen't exit.
When I do ps ax | grep java
it always shows a lot java processes with java -jar /path/to/file.jar
as command:
32208 ? Sl 0:59 java -jar /path/to/file.jar
My Java-Program works like that:
Does anyone know why the programm doesn't exit? Please help.
EDIT:
In the logfiles I found this:
"Control" is the name of my Main Class.
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.
Upvotes: 3
Views: 2121
Reputation: 11715
Do a thread dump to find out what's still running: you can use jstack PID for that, if you're using the Oracle JVM.
Upvotes: 3
Reputation: 16736
Put a debug print at the very end of the program. If you see the print, then it means that the main thread ends, but the program doesn't exit. I'm guessing that JavaMail has a thread left open (perhaps a Mail Session), that needs closing. Are you sure you're closing all resources before exiting?
Upvotes: 1
Reputation: 9424
Try to finish the JVM explicitly using when the job is done. This is the code to do this:
System.exit(0);
As iccthedral said, maybe there is some code that is blocking your program.
Upvotes: 0