开发者

Loading Resources Once in Java

I have a project in Java requiring to load large files (corpus for NLP) for every execution. Let's call it method load(), and this is only called once, and the method process(String text) can be called multiple times where these belong to the class Tagger.

My problem is that whenever I need to tweak some code except for class Tagger and recompile/run the project, where the project calls the method process(),开发者_C百科 I have to wait for some 10 or more seconds just to have these resources loaded. Can I maintain these resources or the Tagger class itself, such that I can edit any code and recompile them, without unloading the Tagger class or unloading the resources?

My option is to use web services or some servlets, but are there more alternative solutions? Or libraries to create these services easier? Since the solution is only required during development stage, but not required after deployed, when users really load the resources once during the program execution and terminates when closed.

Thanks,


You might consider hot swapping, which allows you to recompile one or more classes and merge them into an already-running application.

http://java.sun.com/j2se/1.4.2/docs/guide/jpda/enhancements.html#hotswap


Here's a guide to reloading classes with a dynamic class loader, which probably is your best bet: http://www.zeroturnaround.com/blog/reloading-objects-classes-classloaders/


If the slow down is do to processing the data maybe try serializing the tagger class and saving it to disk. Loading the class when the program starts.


Well, if you use a dynamic language like Groovy, you could issue statements to be compiled at runtime, while these resources are already loaded.

Also if you're editing a JSP I know the servlet container typically listens for changes to the file and will re-compile the page if it finds any.


I think JRebel can do the work for me easily. But the approaches above can be a substitute for this commercial tool. Thanks.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜