0

I have a main class : MyMainSDK

public static void main(String[] args) { 
        EventQueue.invokeLater(new Runnable() {
            public void run() {
                try {
                    MyMainSDK frame = new MyMainSDK();
                    frame.setVisible(false);
                    System.out.println("f1"); 
                } catch (Exception e) {
                    System.out.println("Error: " + e.getMessage()); 
                    e.printStackTrace();
                }
                System.out.println("f2"); 
            }
        });


    System.out.println("f3"); 
    }

and my class is:

    public MyMainSDK() {


           /*

             do something

                System.out.println("do something logs"); 

            */

       System.out.println("everything is finished"); 

 }

I run my java code on batch file. It works what I expect .

But the batch file seems it is not finished. But I see these logs:

f3
do something logs
f1
f2

how can I solve this?

thanks in advance

CompEng
  • 7,161
  • 16
  • 68
  • 122
  • 1
    Because you start the event dispatch thread, which never ends, since you never call System.exit(). Why would you create a frame, never show it and exit immediately? – JB Nizet Oct 02 '18 at 06:52
  • Why do you call `invokeLater` in the first place? Creating the frame and displaying it will result in pretty much the same thing you see. What you need to do is something like `frame.setDefaultCloseOperation(EXIT_ON_CLOSE)`. – daniu Oct 02 '18 at 06:53
  • ok I will try frame.setDefaultCloseOperation(EXIT_ON_CLOSE) – CompEng Oct 02 '18 at 07:00
  • This is Swing, right? – daniu Oct 02 '18 at 07:03
  • it just java code to work background – CompEng Oct 02 '18 at 07:04
  • Is this a GUI application? If it is just a batch-job you could try using multi-threading feature in Java to get the job in a background thread. The `invokeLater` is used with GUI applications. Look at these posts you may find what you need: [Run task in background](https://stackoverflow.com/questions/12551514/create-threads-in-java-to-run-in-background) and [Perform background task in Java](https://stackoverflow.com/questions/20369198/perform-background-task-in-java). – prasad_ Oct 02 '18 at 09:34

0 Answers0