2017-11-22 2 views
-1

私は春のフレームワークを学んでいます。私は春には基本的なhello worldプログラムを行いました。実行は約600ミリ秒かけて実行していますパフォーマンスは大きなアプリケーションを構築できます。ここにコードですなぜ単純なコードを実行するのにこのSpringアプリケーションが多くの時間を費やしているのですか

public class MainApp { 

@SuppressWarnings("resource") 
public static void main(String[] args) { 
    long time=System.currentTimeMillis(); 
     ApplicationContext context = new ClassPathXmlApplicationContext("Beans.xml"); 
     HelloWorld obj = (HelloWorld) context.getBean("helloWorld"); 
     System.out.println(obj.getMessage()); 
     System.out.println("time in milliseconds"+System.currentTimeMillis()- 
    time); 
    } 
    } 

私は上記のコードを依存性注入のためのスプリング構成ファイルで実行しています。なぜ単純なコードのためにこの時間がかかるのですか?ここに出力されます

Nov 22, 2017 10:17:15 PM 
org.springframework.context.support.ClassPathXmlApplicationContext 
prepareRefresh 
INFO: Refreshing 
org[email protected]78e03bb5: 
startup date [Wed Nov 22 22:17:15 IST 2017]; root of context hierarchy 
Nov 22, 2017 10:17:15 PM 
org.springframework.beans.factory.xml.XmlBeanDefinitionReader 
loadBeanDefinitions 
INFO: Loading XML bean definitions from class path resource [Beans.xml] 
Hello World! 
time in milliseconds 656 

私は上記のプログラムを実行しています。Windows 7搭載のIntel i3プロセッサ。

+0

Beans.xmlには何がありますか? Springフレームワークは、Dependency Injectionや他の多くのものを容易にするために多くのことを持っています。したがって、開始の遅延。また、Beans.xmlで定義したBeanの数にもよります。 – pvpkiran

+0

はい、コンテキストはアプリケーションの起動時にロードされ、その後は再び実行されません。 –

+0

656ミリ秒は何もありません。大きな市場シェアを持つフレームワークに石を投げること以外に、あなたの人生に役立つ何かをするべきです。 –

答えて

0

テスト手法は完全に正しいわけではありません。この実行では、毎回フレームワークを開始し、xmlからBean定義を読み込みます。 656msは、+ xmlを読み込むのに必要なコードの量を考慮するとかなり高速です。

開始されると、はるかに高速に動作します。