1 /*
 2  * Copyright (c) 2024, Oracle and/or its affiliates. All rights reserved.
 3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 4  *
 5  * This code is free software; you can redistribute it and/or modify it
 6  * under the terms of the GNU General Public License version 2 only, as
 7  * published by the Free Software Foundation.
 8  *
 9  * This code is distributed in the hope that it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12  * version 2 for more details (a copy is included in the LICENSE file that
13  * accompanied this code).
14  *
15  * You should have received a copy of the GNU General Public License version
16  * 2 along with this work; if not, write to the Free Software Foundation,
17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18  *
19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20  * or visit www.oracle.com if you need additional information or have any
21  * questions.
22  */
23 
24 import java.lang.management.ManagementFactory;
25 import java.lang.management.RuntimeMXBean;
26 
27 import io.quarkus.runtime.Quarkus;
28 import io.quarkus.runtime.QuarkusApplication;
29 import io.quarkus.runtime.annotations.QuarkusMain;
30 
31 @QuarkusMain
32 public class Main {
33     public static void main(String... args) throws Exception {
34  	long mainStart = System.currentTimeMillis();
35  	RuntimeMXBean runtimeMXBean = ManagementFactory.getRuntimeMXBean();
36  	// This includes all the time spent inside the JVM before main() is reached
37  	// (since os::Posix::init is called and initial_time_count is initialized).
38  	long vmStart = runtimeMXBean.getStartTime();
39  	long maxBeanOverHead = System.currentTimeMillis() - mainStart;
40 
41         if (Boolean.getBoolean("autoQuit")) {
42             Quarkus.manualInitialize();
43             Quarkus.manualStart();
44 
45             long end = System.currentTimeMillis();
46             System.out.println("#### Booted and returned in " + (end - vmStart - maxBeanOverHead) + "ms");
47             System.out.println("#### (debug) mainStart = " + mainStart);
48             System.out.println("#### (debug) vmStart = " + vmStart);
49             System.out.println("#### (debug) before main (mainStart - vmStart) = " + (mainStart - vmStart));
50             System.out.println("#### (debug) maxBeanOverHead = " + maxBeanOverHead);
51             System.out.println("#### (debug) end = " + end);
52 
53             System.out.println("Done .. Exiting");
54             System.exit(0);
55         } else {
56             Quarkus.run(MyApp.class, args);
57         }
58     }
59 
60     public static class MyApp implements QuarkusApplication {
61         @Override
62         public int run(String... args) throws Exception {
63             System.out.println("Do startup logic here");
64             Quarkus.waitForExit();
65             System.out.println("Done");
66             Thread.sleep(1000);
67             System.out.println("Exiting");
68             Quarkus.asyncExit(0);
69             return 0;
70         }
71     }
72 }