Changing the performance of a Java application depending on how it runs

hope this is a quick and easy question. I recently developed a Java processor intensive application in Netbeans. It uses an A * path that distorts tens of thousands of times per second to solve a game that matches a plate game. The application is complete and it works pretty fast (I tested in netbeans all the time). I programmed it at 700 attempts per second (each attempt is probably 20 or so). When I create a project, it creates a jar, and I can run it outside of netbeans. If I use the command line (Windows 7) and use java -jar theFile.jar, I run it at 1000 attempts per second. This is understandable, since the IDE probably used a bit of processor power and held it (my application is multi-core, you can set the number. Usually I use 3/4, so it does not slow down my system too much). Now, the confusing part. Obviously, I do not want the user to have to use the command line every time they want to run this application in windows. They should just click on the jar. The problem is that when I double-click the jar file, the program works with 300 attempts per second!

Why do these three ways to run the same program, all other things being equal, have such a huge impact on performance? My fix for creating a script to run the .jar command prompt on command, or will you guys find out what is going on here? Thank you very much!

Edit: new information

I made a batch file with the command: java -jar theFile.jar When this is executed, it runs at the same speed as if I ran it in the console (so, 1000 at / sec)

However, I also made an executable with a simple C ++ program. The program had only a couple of lines and was System ("java -jar theFile.jar"); and return 0 ;. Continuously, this works at a double-click speed of the jar file, around 300att / sec. How strange! These may be different IDE parameters, but I'm not sure how to check the system defaults or how to change them for this particular bank.

+4
source share
1 answer

You may encounter differences between the client and server versions of HotSpot VM . From in this article :

  • On the platforms commonly used for client applications, the JDK comes with a VM implementation called the Java HotSpot β„’ client virtual machine (VM client). The client VM is configured to reduce startup time and memory footprint. It can be called using the -client command-line option when the application starts.

  • On all platforms, the JDK comes with an implementation of a Java virtual machine called the HotSpot Java Virtual Machine (server VM). VM server is designed for maximum program execution speed. It can be invoked using the -server command-line option when the application starts.

I assume that clicking on the jar file may cause the client virtual machine if you do not set the -server flag. This article provides more detailed information:

What is the difference between -client and -server systems?

These two systems are different binary files. They are essentially two different compilers (JITs) interacting with the same runtime system. the client system is optimal for applications that require quick start-up times or small prints, the server system is optimal for where overall performance is most important. The common client system is better suited for interactive applications such as graphical interfaces. Some of the other differences include compilation policies, default heap settings, and attachment policies.

Where can I get server and client systems?

Client and server systems boot from 32-bit Solaris and boot Linux. For 32-bit Windows, if you download the JRE, you only get the client, you need to download the SDK to get both systems.

For the 64-bit version, only the server system is enabled. On Solaris, a 64-bit JRE is an overlay on top of a 32-bit distribution. However, on Linux and Windows, this is a completely separate distribution.

I want java to be -server by default. I have many scripts that I cannot change (or do not want to change). Is there any way to do this?

Since Java SE 5.0, with the exception of 32-bit Windows, the server VM will be automatically selected on server-class machines. the server class machine definition may change from release to release, so please check the appropriate ergonomic document for the definition for your release. For 5.0, this is Ergonomics in the 5.0 Java Virtual Machine [tm].

Do I need to warm my loops first so that Hotspot compiles them?

It is not recommended to heat the hinges for HotSpot. HotSpot contains On Stack Replacement Technology, which compiles the working (interpreted) method and replacing it while it is still working in the loop. No need to waste time using applications, endless (or very long) loops to get better application performance.

+3
source

All Articles