Mon problème est le suivant : lors de la 1ère génération d'un rapport la méthode run() de la tâche RunAndRender dure 10s et les fois suivantes uniquement 1s. C'est assez pénalisant.
Voila comment je produis mon rapport :
- j'ai une classe BirtEngine qui me crée un singleton ReportEngine :
Code :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94
|
public class BirtEngine {
private static IReportEngine birtEngine = null;
private static Properties configProps = new Properties();
private final static String configFile = "BirtConfig.properties";
public static synchronized void initBirtConfig() {
loadEngineProps();
}
public static synchronized IReportEngine getBirtEngine(ServletContext sc) {
if (birtEngine == null) {
EngineConfig config = new EngineConfig();
if (configProps != null) {
String logLevel = configProps.getProperty("logLevel");
Level level = Level.OFF;
if ("SEVERE".equalsIgnoreCase(logLevel)) {
level = Level.SEVERE;
} else if ("WARNING".equalsIgnoreCase(logLevel)) {
level = Level.WARNING;
} else if ("INFO".equalsIgnoreCase(logLevel)) {
level = Level.INFO;
} else if ("CONFIG".equalsIgnoreCase(logLevel)) {
level = Level.CONFIG;
} else if ("FINE".equalsIgnoreCase(logLevel)) {
level = Level.FINE;
} else if ("FINER".equalsIgnoreCase(logLevel)) {
level = Level.FINER;
} else if ("FINEST".equalsIgnoreCase(logLevel)) {
level = Level.FINEST;
} else if ("OFF".equalsIgnoreCase(logLevel)) {
level = Level.OFF;
}
config.setLogConfig(configProps.getProperty("logDirectory"),
level);
}
config.setEngineHome("");
IPlatformContext context = new PlatformServletContext(sc);
config.setPlatformContext(context);
HTMLEmitterConfig emitterConfig = new HTMLEmitterConfig( );
emitterConfig.setActionHandler( new HTMLActionHandler( ) );
HTMLServerImageHandler imageHandler = new HTMLServerImageHandler( );
emitterConfig.setImageHandler( imageHandler );
config.getEmitterConfigs( ).put( "html", emitterConfig ); //-NLS-1$
try {
Platform.startup(config);
} catch (BirtException e) {
e.printStackTrace();
}
IReportEngineFactory factory = (IReportEngineFactory) Platform
.createFactoryObject(IReportEngineFactory.EXTENSION_REPORT_ENGINE_FACTORY);
birtEngine = factory.createReportEngine(config);
}
return birtEngine;
}
public static synchronized void destroyBirtEngine() {
if (birtEngine == null) {
return;
}
birtEngine.shutdown();
Platform.shutdown();
birtEngine = null;
}
public Object clone() throws CloneNotSupportedException {
throw new CloneNotSupportedException();
}
private static void loadEngineProps() {
try {
// Config File must be in classpath
ClassLoader cl = Thread.currentThread().getContextClassLoader();
InputStream in = null;
in = cl.getResourceAsStream(configFile);
configProps.load(in);
in.close();
} catch (IOException e) {
e.printStackTrace();
}
}
} |
- mon singleton est initialisé au lancement de l'appli
- qd je veux produire mon rapport j'exécute le code suivant :
Code :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
|
ServletContext lServletContext = pRequest.getSession()
.getServletContext();
IReportEngine lReportEngine = BirtEngine.getBirtEngine(lServletContext);
// Open a report document
IReportRunnable lReportDesign = lReportEngine
.openReportDesign(lServletContext.getRealPath("/Reports")
+ "\\" + pReportName);
// Create Render Task
IRunAndRenderTask lTask = lReportEngine
.createRunAndRenderTask(lReportDesign);
// Set Render context to handle url and image locataions
HTMLRenderContext lRenderContext = new HTMLRenderContext();
// You must define HTMLServerImageHandler to use a URL
lRenderContext.setBaseImageURL(pRequest.getContextPath()
+ "/images/reports");
lRenderContext.setImageDirectory(lServletContext
.getRealPath("/images/reports"));
lRenderContext.setSupportedImageFormats("JPG;PNG;BMP");
HashMap lContextMap = new HashMap();
lContextMap.put(EngineConstants.APPCONTEXT_HTML_RENDER_CONTEXT,
lRenderContext);
lTask.setAppContext(lContextMap);
// Set parameters
Iterator<String> lKeys = pParameters.keySet().iterator();
while (lKeys.hasNext()) {
String lKey = lKeys.next();
lTask.setParameterValue(lKey, pParameters.get(lKey));
}
// Set Render Options
HTMLRenderOption lOptions = new HTMLRenderOption();
ByteArrayOutputStream lBy = new ByteArrayOutputStream();
lOptions.setOutputStream(lBy);
lOptions.setEmbeddable(true);
lTask.setRenderOption(lOptions);
lTask.run();
lTask.close();
return lBy; |
Dans ce code c'est la méthode run() qui prend 10s à la 1ère production du rapport et seulement 1s après. Quelqu'un pourrait-il m'aider à diminuer ce temps ?
Merci d'avance