JSF Internationalization f:loadbundle or through faces-config: Performance point

拈花ヽ惹草 提交于 2019-12-05 10:37:40
BalusC

Out of these two which one gives me better performance?

I wouldn't worry about the performance. The ResourceBundle already caches them internally.


Lets say I have a page abc.xhtml and I am using f:loadBundle, and there 1000 users accessing this page, does this mean there would 1000 resouceBundle object created? or is it only object which is being shared by all the page instances?

By default, only one is created. See also the ResourceBundle API documentation:

Cache Management

Resource bundle instances created by the getBundle factory methods are cached by default, and the factory methods return the same resource bundle instance multiple times if it has been cached. getBundle clients may clear the cache, manage the lifetime of cached resource bundle instances using time-to-live values, or specify not to cache resource bundle instances. Refer to the descriptions of the getBundle factory method, clearCache, ResourceBundle.Control.getTimeToLive, and ResourceBundle.Control.needsReload for details.

You can easily testify if yourself in debugger by looking at instance's hashcode.


The <application> declaration has by the way the additional benefit that the bundle is also injectable in a managed bean by @ManagedProperty("#{msg}"). See also among others this Q&A: Read resource bundle properties in a managed bean.

You have seen from the answers that one global resource bundle suffices. On performance:

You have two kind of standard ResourceBundle instances:

  • PropertyResourceBundle - *[_LOCALE].properties files, and
  • ListResourceBundle, a java class (using package names with '.') - *[_LOCALE].class.

For ListResourceBundle:

Every locale java class creates an array of strings with shared (!) key and localized text. Sharing the key strings in the JVM is nice. Also all strings are loaded early.

So it might be worth delivering a ListResourceBundle.

For translation however, you then probably would have to maintain some non-java translation memory, tmx, xliff or so. And in the build process generate the java.

1st option - because it is application scoped and loads at start up

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!