slow-spring/hibernate在tomcat生产服务器上的web应用程序

jei2mxaa  于 2021-07-24  发布在  Java
关注(0)|答案(0)|浏览(157)

我的spring/hibernate web应用程序有以下问题。在我的开发环境中,get请求需要+-1秒钟(web服务器是Tomcat8.5)。当我在生产服务器(deploying.war文件)上部署我的web应用程序并且我对同一个页面执行get请求时,需要+-4秒。。
在后端,我对mssql执行hibernate请求,并将所有请求推送到jsp页面。
我不知道为什么生产环境会耽搁这么久。。所以现在是我的问题。。有人能告诉我搜索的方向吗?
我看了服务器的规格,这些都很好。运行在4%内存上的cpu也只占用了20%的内存。生产服务器和数据库之间没有防火墙或防病毒
休眠配置

Configuration cfg = new Configuration();
    cfg.getProperties().setProperty("hibernate.connection.driver_class", "com.microsoft.sqlserver.jdbc.SQLServerDriver");
    cfg.getProperties().setProperty("hibernate.c3p0.min_size", "5");
    cfg.getProperties().setProperty("hibernate.c3p0.max_size", "20");
    cfg.getProperties().setProperty("hibernate.c3p0.timeout", "3000");
    cfg.getProperties().setProperty("hibernate.c3p0.max_statements", "150");
    cfg.getProperties().setProperty("hibernate.c3p0.idle_test_period", "3000");
    cfg.getProperties().setProperty("hibernate.dialect", "org.hibernate.dialect.SQLServerDialect");
    cfg.getProperties().setProperty("hibernate.show_sql", "true");
    cfg.getProperties().setProperty("hibernate.current_session_context_class", "thread");
    cfg.getProperties().setProperty("hibernate.connection.username", "sa");
    cfg.getProperties().setProperty("hibernate.connection.password", "test");
    cfg.getProperties().setProperty("hibernate.generate_statistics", "true");
    cfg.getProperties().setProperty("hibernate.connection.url", "jdbc:sqlserver://10.13.1.84\\GSQLVS03;databaseName=toolboxdb;instanceName=WHD");
    cfg.addAnnotatedClass(FunctionClasses.class);
    cfg.addAnnotatedClass(ApplicationClasses.class);
    cfg.addAnnotatedClass(AssetType.class);
    cfg.addAnnotatedClass(Assets.class);
    cfg.addAnnotatedClass(AssetFamily.class);
    factory = cfg.buildSessionFactory();

代码获取请求

@GetMapping("/getAssets")
public String getAssets(Model theModel) {
    Assets a = new Assets();
    List<Assets> theAssets = new ArrayList<>();
    List<AssetType> theAssetsType = new ArrayList<>();
    List<AssetFamily> theAssetFamily = new ArrayList<>();
    List<ApplicationClasses> theApplicationClasses = new ArrayList<>();
    List<String> sizeFunctionClasses = new ArrayList<>();
    List<String> sizeChildAssets = new ArrayList<>();

    SessionFactory factory = a.factory();
    Session session = factory.getCurrentSession();

    try {
        session.beginTransaction();
        theAssets = session.createQuery("from Assets").getResultList();

        for(int i = 0; i < theAssets.size(); i++){
            if(theAssets.get(i).getFunctionClasses().size() == 0){
                sizeFunctionClasses.add("0");
            }
            else{
                sizeFunctionClasses.add("1");
            }
            if(theAssets.get(i).getChildAssets().size() == 0){
                sizeChildAssets.add("0");
            }
            else{
                sizeChildAssets.add("1");
            }
        }

       theAssetsType = session.createQuery("from AssetType ").getResultList();
        theApplicationClasses = session.createQuery("from ApplicationClasses ").getResultList();
        theAssetFamily = session.createQuery("from AssetFamily ").getResultList();
        session.getTransaction().commit();
    } finally {
        session.close();
        factory.close();
    }

    theModel.addAttribute("assets", theAssets).addAttribute("assetTypes", theAssetsType).addAttribute("assetFamily", theAssetFamily)
            .addAttribute("applicatieGroepen", theApplicationClasses).addAttribute("sizeFunctionClasses",sizeFunctionClasses).addAttribute("sizeChildAssets",sizeChildAssets);
    return "list-assets";
}

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题