Project: Birt
Bug 122561 Java event handler class is loaded multiple times
Reported: 2006-01-03 15:33:11 | Status: resolved fixed

It appears that a Java event handler class is loaded twice for every time that an event is fired that requires the handler class. You would expect that the class is loaded once per Engine session. To reproduce, create a Java project in the workspace, set it to depend on the org.eclipse.birt.report.engine project, and drop in the attached CellEvenHandler.java file. Add the attached script_test.rptdesign file to a BIRT report project. Preview the report. You will find the following content in the output file "c:\scriptout.txt": Static init: org.eclipse.birt.test.CellEventHandler Static init: org.eclipse.birt.test.CellEventHandler org.eclipse.birt.test.CellEventHandler.onCreate Static init: org.eclipse.birt.test.CellEventHandler Static init: org.eclipse.birt.test.CellEventHandler org.eclipse.birt.test.CellEventHandler.onCreate Static init: org.eclipse.birt.test.CellEventHandler Static init: org.eclipse.birt.test.CellEventHandler org.eclipse.birt.test.CellEventHandler.onCreate Static init: org.eclipse.birt.test.CellEventHandler Static init: org.eclipse.birt.test.CellEventHandler org.eclipse.birt.test.CellEventHandler.onCreate Static init: org.eclipse.birt.test.CellEventHandler Static init: org.eclipse.birt.test.CellEventHandler org.eclipse.birt.test.CellEventHandler.onCreate Static init: org.eclipse.birt.test.CellEventHandler Static init: org.eclipse.birt.test.CellEventHandler org.eclipse.birt.test.CellEventHandler.onCreate Static init: org.eclipse.birt.test.CellEventHandler Static init: org.eclipse.birt.test.CellEventHandler org.eclipse.birt.test.CellEventHandler.onCreate Static init: org.eclipse.birt.test.CellEventHandler Check the Java class code and you will see that the CellEventHandler class is loaded twice for each Cell.onCreate event. This is a rather serious problem: the event handler class cannot use any static field to persist data across events. It causes very bad scripting performance since loading a class is an expensive operation. It appears that the problem resides in Engine's class loading logic: it uses a new class loader every time an event is fired to load the necessary event handler.

Files changed in fix:
engine/org.eclipse.birt.report.engine/src/org/eclipse/birt/report/engine/api/script/IRowData.java engine/org.eclipse.birt.report.engine/src/org/eclipse/birt/report/engine/api/script/eventadapter/CellEventAdapter.java engine/org.eclipse.birt.report.engine/src/org/eclipse/birt/report/engine/api/script/eventadapter/RowEventAdapter.java engine/org.eclipse.birt.report.engine/src/org/eclipse/birt/report/engine/api/script/eventhandler/ICellEventHandler.java engine/org.eclipse.birt.report.engine/src/org/eclipse/birt/report/engine/api/script/eventhandler/IRowEventHandler.java engine/org.eclipse.birt.report.engine/src/org/eclipse/birt/report/engine/api/script/instance/ICellInstance.java engine/org.eclipse.birt.report.engine/src/org/eclipse/birt/report/engine/api/script/instance/IRowInstance.java engine/org.eclipse.birt.report.engine/src/org/eclipse/birt/report/engine/executor/ExecutionContext.java engine/org.eclipse.birt.report.engine/src/org/eclipse/birt/report/engine/executor/GridItemExecutor.java engine/org.eclipse.birt.report.engine/src/org/eclipse/birt/report/engine/executor/ListingElementExecutor.java engine/org.eclipse.birt.report.engine/src/org/eclipse/birt/report/engine/script/internal/CellScriptExecutor.java engine/org.eclipse.birt.report.engine/src/org/eclipse/birt/report/engine/script/internal/ElementUtil.java engine/org.eclipse.birt.report.engine/src/org/eclipse/birt/report/engine/script/internal/RowData.java engine/org.eclipse.birt.report.engine/src/org/eclipse/birt/report/engine/script/internal/RowScriptExecutor.java engine/org.eclipse.birt.report.engine/src/org/eclipse/birt/report/engine/script/internal/ScriptExecutor.java engine/org.eclipse.birt.report.engine/src/org/eclipse/birt/report/engine/script/internal/instance/CellInstance.java engine/org.eclipse.birt.report.engine/src/org/eclipse/birt/report/engine/script/internal/instance/RowInstance.java