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
yes java can behave different when you use the -server flag, but that requires the program itself to have at least one error. The only case I can think of is a missing volatile or missing synchronisation for a variable accessed by multiple Threads.
Calling the exit() method without optimization will lead the thread to exit the loop, when optimization is turned on the optimizer may gues that the loop will never end and replace the test with a simple jump, as stop is not volatile and is not modified from within the loop.
This behavior has to be expected as a variable accessed by several threads should either be declared volatile or accessed only over synchronized methods.
just remembered that there is a stop() method in Thread, replaced it with exit() for clarity.