The bean configured in spring is the default Singleton, so in the program, the speed of getting an instance must be faster than creating an instance, saving resources. During the actual test today, we found that a new object is much faster than a spring object. Next I added a singleton test to compare the test results. Copy the public static void main (String [] args) {ReceiveProcess receiveProcess; applicationContext appCt = new ClassPathXmlApplicationContext ("classpath: applicationContext. xml "); long begin = System. currentTimeMillis (); int num = 10000000; for (int I = 0; I <num; I ++) {receiveProcess = (ReceiveProcess) appCt. getBean ("textReceive");} System. out. println ("spring obtains the total instance time:" + (Sy Stem. currentTimeMillis ()-begin); long begin2 = System. currentTimeMillis (); ReceiveProcess re = null; for (int j = 0; j <num; j ++) {re = new TextReceiveProcess ();} System. out. println ("Total time the instance was created:" + (System. currentTimeMillis ()-begin2); ReceiveProcess reInstance = null; long begin3 = System. currentTimeMillis (); for (int d = 0; d <num; d ++) {reInstance = TextReceiveProcess. getInstance ();} System. out. println ("total time in a single case:" + (System. currentTimeMillis ()-begin3);} result of copying the code: Total instance time for spring: 5257 total time for instance creation: total time for 48 instances: 16 occasionally, this result is not very understandable. Sometimes the time for creating an object is the same as that for a single instance. Why? Total time for spring instances: 5258 total time for instance creation: 32 in a single case: 31