简体   繁体   中英

is java can pre-compiled?

I run Java program like script many times per second and every time loading of script takes a lot of time

register.put("some word", new SomeClass(/* code */), some vars);

and this code repeats ~200 times (yeah)

there is a way to precompile this code? (like C++ precompiled headers)

Java gets compiled, not to machine code, but to bytecode.

If you wish to compile your Java application in machine-readable code (ie an executable), you can use GraalVM's native-image feature . Be aware, though, that there are certain limitations. For one, compilation is quite slow and memory-intensive. For another, SubstrateVM (the framework used for native compilation) operates under a closed-world assumption. This means that you cannot load classes during program execution. Another downside is that native images are not able to use the JIT compiler and thus the overall throughput of the program may decrease (see this GitHub issue for details). This list of limitations is not extensive. Please check the limitations when you run into problems.

You can also try to improve application startup by creating your own JVM runtime image with jlink . There is an article at medium that seems like a good entry point.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM