Play! framework, a single instance of Jetty, deploying multiple projects, sharing libs

I am trying to deploy two or more independent Play! (1.2.4) based on the same instance of Jetty.

According to this post , apparently, you can extract the shared lib from each directory PrjName.war/WEB-INF/lib and place them in the shared lib directory, i.e. jetty/lib/ext .

We have a large number of small independent projects that we would like to implement using Play! but they must all be deployed in the same instance. Jetty uses all libraries to reduce the use of RAM. Is my assumption correct that multiple projects sharing the same lib will reduce the total memory?

My attempts to put all the libraries in a shared folder, i.e. jetty/lib/ext , worked for one project, but the deployment of the second project failed and crashes the first.

The problem seems to be related to conflicting instances of EhCache.

Here is the jetty log:

 ... at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at org.eclipse.jetty.start.Main.invokeMain(Main.java:469) at org.eclipse.jetty.start.Main.start(Main.java:612) at org.eclipse.jetty.start.Main.parseCommandLine(Main.java:265) at org.eclipse.jetty.start.Main.main(Main.java:79) Caused by: net.sf.ehcache.ObjectExistsException: Cache play already exists at net.sf.ehcache.CacheManager.addCache(CacheManager.java:859) at play.cache.EhCacheImpl.<init>(EhCacheImpl.java:32) at play.cache.EhCacheImpl.newInstance(EhCacheImpl.java:41) at play.cache.Cache.init(Cache.java:241) at play.Play.start(Play.java:511) ... 42 more 

Any help is greatly appreciated.

+7
source share
1 answer

When you use shared banks, Jetty will use the System Classloader to load classes inside shared banners. And, since Play EhCacheImpl is (almost) a singleton, the second launch application will affect the first and vice versa. This is the exception you are getting now: Play is trying to specify two caches in the same classloader with the same name. I can think of the following solutions:

  • Fix Playframework so that it can handle this situation.
  • Use your own cache implementation (not sure if this is the only thing that prevents both of your applications from working together)
  • Use the general setup and replicate banks for each application.

Option 3 sounds better to me since you don't need to create a framework and it is also safer with regression errors. As for the memory area, you can use visualvm to check if the memory consumption differs substantially justified for common banners.

+1
source

All Articles