Real differences between “java -server” and “java -client”?

前端 未结 11 2136
旧时难觅i
旧时难觅i 2020-11-22 03:52

Is there any real practical difference between \"java -server\" and \"java -client\"?

All I can find on Sun\'s site is a vague

\"-server st

11条回答
  •  太阳男子
    2020-11-22 04:47

    the -client and -server systems are different binaries. They are essentially two different compilers (JITs) interfacing to the same runtime system. The client system is optimal for applications which need fast startup times or small footprints, the server system is optimal for applications where the overall performance is most important. In general the client system is better suited for interactive applications such as GUIs

    We run the following code with both switches:

    package com.blogspot.sdoulger;
    
    public class LoopTest {
        public LoopTest() {
            super();
        }
    
        public static void main(String[] args) {
            long start = System.currentTimeMillis();
            spendTime();
            long end = System.currentTimeMillis();
            System.out.println("Time spent: "+ (end-start));
    
            LoopTest loopTest = new LoopTest();
        }
    
        private static void spendTime() {
            for (int i =500000000;i>0;i--) {
            }
        }
    }
    

    Note: The code is been compiled only once! The classes are the same in both runs!

    With -client:
    java.exe -client -classpath C:\mywork\classes com.blogspot.sdoulger.LoopTest
    Time spent: 766

    With -server:
    java.exe -server -classpath C:\mywork\classes com.blogspot.sdoulger.LoopTest
    Time spent: 0

    It seems that the more aggressive optimazation of the server system, remove the loop as it understands that it does not perform any action!

    Reference

提交回复
热议问题