1

(1) I wrote a question about this issue but I think I did not state the problem correctly so I removed it. To get to the point, in my GUI application, I notice when I want to measure the running time taken by a method using System.currentTimeMillis();, the time becomes very short and unrealistic comparing with the standard way of running jar file via terminal or console, does Java Swing make some effects here?

(2) Since I want to keep my GUI and also solve this issue, I read about the possibility of disabling JIT, how can I write it as a piece of code in my program so when it runs, JIT is disabled during the runtime of my application only.

Thank you.

Jacki
  • 95
  • 2
  • 8

1 Answers1

2

Run your program using the -Xint option, which "Runs the application in interpreted-only mode. Compilation to native code is disabled, and all bytecode is executed by the interpreter. The performance benefits offered by the just in time (JIT) compiler are not present in this mode."

As a concrete example, this AnimationTest displays the average time spent in paintComponent() using System.nanoTime(). With the -Xint option, the time remains fairly constant:

java -Xint -cp build/classes overflow.AnimationTest

Without the option, i.e. with compilation to native code, it's easy to see a secular decrease in paint time, sometimes by as much as an order of magnitude:

java -cp build/classes overflow.AnimationTest
Community
  • 1
  • 1
trashgod
  • 203,806
  • 29
  • 246
  • 1,045
  • Thank you for the response. How can I do that as a code in my class constructor since my application will be run by unexperienced people. – Jacki May 02 '16 at 22:18
  • You can specify that option when deploying via [tag:java-web-start], but I would't. – trashgod May 02 '16 at 22:22