user1564811
user1564811

Reputation: 11

Java application not exit on calling System.exit(0)

I have a Java application running on both Mac and Windows. I call System.exit(0) on user pressing "exit" button. The application works well on Win7. But on Mac, after I press "exit" button, the program can not exit. There is no response from the application.

According to the Activity Monitor, all user threads are terminated. I don't know what the program is waiting for.

I could't paste the whole output of Activity Monitor, but here is an example:

851 Thread_435381: Java: Exception Handler Thread  
851 Thread_435386: Java: Gang worker#0 (Parallel GC Threads)
851 Thread_435493
851 thread_start  (in libsystem_c.dylib) + 34  [0x92abd6de]  
851 _pthread_start  (in libsystem_c.dylib) + 335  [0x92ab9ed9]  
851 CAPThread::Entry(CAPThread*)  (in CoreMediaIO) + 123  [0x9a5e3a3d]  
851 CMIO::DAL::RunLoop::OwnThread(void*)  (in CoreMediaIO) + 160  [0x9a5eded2]  
851 CFRunLoopRunInMode  (in CoreFoundation) + 120  [0x9329c328]  
851 CFRunLoopRunSpecific  (in CoreFoundation) + 332  [0x9329c47c]  
851 __CFRunLoopRun  (in CoreFoundation) + 1428  [0x9329cda4]  
851 __CFRunLoopServiceMachPort  (in CoreFoundation) + 170  [0x93293c7a]  
851 mach_msg  (in libsystem_kernel.dylib) + 70  [0x942601f6]  
851 mach_msg_trap  (in libsystem_kernel.dylib) + 10  [0x94260c22]'  

Upvotes: 1

Views: 943

Answers (3)

user1565007
user1565007

Reputation:

Make a Thread Dump to see which threads are blocking exit. To do so, open a command prompt, and do ps -eaf | grep java. Find your pid and do , kill -3 3 times.

You should get a Thread dump and see which thread is blocking. REgards Philippe

Upvotes: 0

cpliu338
cpliu338

Reputation: 647

I think you are using swing JFrame, in addition to Kumar Vivek Mitra's answer, to exit, you can also do this:

jFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

Upvotes: 0

Kumar Vivek Mitra
Kumar Vivek Mitra

Reputation: 33534

1. I think you are mixing your Non-Gui work with the Gui.

2. I hope you have kept your Event Dispatcher Thread only for GUI purpose and nothing else, if you havent try this..and then try to do it...

public static void main(String[] args){

        EventQueue.invokeLater(new Runnable(){

               public void run(){


                      myframe.setVisible();

                   }


          });


   }

Upvotes: 1

Related Questions