应用程序在日食中运行速度更快 [英] Application runs faster in eclipse

查看:123
本文介绍了应用程序在日食中运行速度更快的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Eclipse中有一个可运行的java SE应用程序。我引导JPA在正常的Java 6 SE环境中工作。对数据库中的不同表的每个请求都不需要超过100ms。



问题是当我导出可运行的jar时,我说java -jar myapp。 jar,每个对数据库的请求都需要大约9秒。



我不明白为什么当我从eclipse运行应用程序时更快...

解决方案

事实上,每当我向数据库发出请求时,我都在创建一个实体经理:

  Persistence.createEntityManagerFactory(mysqldb); 

为了优化实体管理器的创建,我使用了一个这样的单身实体工厂: p>

  private static EntityManagerFactory em = Persistence 
.createEntityManagerFactory(mysqldb);

public static EntityManagerFactory getEmf()
{
return em;
}

这有助于提高eclipse之外的应用程序的性能,但没有当我在eclipse中运行它时,性能的变化。



我不太确定当从eclipse启动应用程序时它的工作原理是什么,但是这个解决方案解决了我现在的问题。


I have a runnable java SE application in eclipse. I bootstrap JPA to work in a normal java 6 SE environment. Each request to the different tables in the database doesn't take more than 100ms.

The problem is that when I export the runnable jar and I say java -jar myapp.jar, each of the request to the database take around 9 seconds.

I don't Understand why the application is faster when I run it from eclipse

解决方案

In fact, each time I was doing a request to the database, I was creating an entity manager:

Persistence.createEntityManagerFactory( "mysqldb" );

In order to optimize the creation of the entity manager I use a singleton entity factory like that:

private static EntityManagerFactory em = Persistence
        .createEntityManagerFactory( "mysqldb" );

public static EntityManagerFactory getEmf()
{
    return em;
}

this worked to improve the performance of the application outside eclipse, but there is no change in the performance when i run it inside eclipse.

I am not really sure of what is the reason it worked better when the application was launched from eclipse, but this solution solved my problem for the moment.

这篇关于应用程序在日食中运行速度更快的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆