Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

does java -server flag make any sense?

Tags:

java

jvm

I think everyone is aware of -server command line JVM parameter. Does it make any sense while running Java application as Server??

I read that it does some more optimizations, and because of that, some of your Java code can behave differently like

boolean flag=true;
while(flag) { 
   if(checkMethod()) {
      flag=false;
   }
} 

[EDIT] this code will work fine(same) in both scenario 1. without -server and 2. with -server, Will update once again with proper testable code.

it will never come out of while loop..

We have just started a new project, should we start using -server for testing?
Are you using it?

& I wonder if it really make sense and it is really important, why official document/tutorials of server products like tomcat/jetty/geronimo etc. never use/show -server tag in code examples ????

Cheers

like image 681
Nachiket Avatar asked May 29 '26 08:05

Nachiket


1 Answers

That can't be right. Java will never execute code incorrectly no matter what switches you add. It can optimize out the checkMethod call only if it can be proven to always return the same value.

In general, the -server switch does help performance by optimizing more aggressively (it assumes that the routines will live longer and be called more often). They used to have columns for Java and Java -server in the Computer Language Shootout, but they seem to have removed the straight "Java" because it never beat Java -server.

I seem to remember the -server causing a somewhat significant increase in many benchmarks.

like image 88
Bill K Avatar answered May 31 '26 22:05

Bill K



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!