带有云SQL的应用引擎上的连接池



听起来像是新的云SQL SQL SQL JDBC驱动程序(1)支持连接池。

我们的应用程序使用Spring Hibernate,我们正在尝试使用现有的Java框架之一进行连接池(BONECP,C3P0,HIKARI),并且由于应用引擎限制而无法使用任何一个。在下面使用Spring Hibernate C3P0堆叠跟踪。有人设法使它工作吗?

[INFO] java.lang.NoClassDefFoundError: java.lang.management.ManagementFactory is a restricted class. Please see the Google  App Engine developer's guide for more details.
[INFO]  at com.google.appengine.tools.development.agent.runtime.Runtime.reject(Runtime.java:51)
[INFO]  at com.mchange.v2.c3p0.management.ActiveManagementCoordinator.<init>(ActiveManagementCoordinator.java:54)
[INFO]  at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
[INFO]  at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
[INFO]  at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
[INFO]  at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
[INFO]  at com.google.appengine.tools.development.agent.runtime.Runtime.newInstance_(Runtime.java:127)
[INFO]  at com.google.appengine.tools.development.agent.runtime.Runtime.newInstance(Runtime.java:148)
[INFO]  at com.mchange.v2.c3p0.C3P0Registry.<clinit>(C3P0Registry.java:146)
[INFO]  at java.lang.Class.forName0(Native Method)
[INFO]  at java.lang.Class.forName(Class.java:190)
[INFO]  at com.google.appengine.tools.development.agent.runtime.RuntimeHelper.checkRestricted(RuntimeHelper.java:70)
[INFO]  at com.google.appengine.tools.development.agent.runtime.Runtime.checkRestricted(Runtime.java:64)
[INFO]  at com.mchange.v2.c3p0.impl.DriverManagerDataSourceBase.<init>(DriverManagerDataSourceBase.java:212)
[INFO]  at com.mchange.v2.c3p0.DriverManagerDataSource.<init>(DriverManagerDataSource.java:72)
....

(1):旧驱动程序= com.google.appengine.api.rdbms.appenginedriver。新驱动程序= com.mysql.jdbc.googledriver。

我们最终通过使用tomcat dbcp(http://tomcat.apache.org/tomcat-7.0.0.0-doc/jdbc-pool.html)来解决此问题。大多数其他池的问题在于它们使用螺纹,这是App Engine的模型在前端实例(长寿命线)上阻止的。

这是一个古老的问题,但我想提供我认为是一个更准确的答案。Google App Engine dis 允许应用程序通过使用 ThreadFactory

来创建线程。

hikaricp允许配置外部ThreadFactory

所以,配置将进行这样的事情:

import com.google.appengine.api.ThreadManager;
...
HikariConfig config = new HikariConfig();
config.setThreadFactory(ThreadManager.backgroundThreadFactory());
...

更新:解决下面有关前端实例的评论...如其他地方所述:

"Keep in mind that instances are created and destroyed dynamically, and requests are routed
to instances based purely on availability. ... There is no guarantee that requests of a
particular sort will always be handled by the same instance, nor is it assured that an
instance will still be around after a given request is handled. Outside of a request
handler, the application is not given the opportunity to rescue data from local memory
prior to an instance being shut down."

这大大降低了连接池在前端的有用性。实际上,如果数据库不是内存的,那是一个坏主意,因为它可以产生大量的连接。关于局部内存数据库,它们不仅在GAE的上下文中脆弱,而且"连接顶部"很少是可扩展性因子。

我使用tomcat dbcp 1.4为GAE前端实例创建了一个示例,该实例不允许线程在请求范围之外生活。这与Java 7一起使用。

https://github.com/kennberg/appengine-java-connection-pool

相关内容

  • 没有找到相关文章

最新更新