具有多个服务器的JPA [英] JPA with Multiple Servers

查看:129
本文介绍了具有多个服务器的JPA的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在开发一个使用JPA(Toplink,目前)持久化的项目。目前,我们正在运行单个应用程序服务器,但是,为了冗余,我们想添加一个负载均衡器和另一个应用程序服务器(并且可能会增加更多)。



首先,我遇到了JPA缓存的问题。由于两个进程将更新同一个数据库,JPA缓存返回缓存的值,而不是去数据库。我看到如何关闭它,数据库本身实现了一个级别的缓存。是完全关闭缓存的方式去这里吗?我看到的方法告诉JPA总是从查询级别的数据库获取,但在多服务器环境中,似乎你总是希望这种情况发生。



除了这个特定的问题,我感兴趣的任何人谁已实施一个JPA解决方案与多个应用程序服务器和在实施过程中出现的问题(和任何建议)。


解决方案

如您所见,您可以禁用共享缓存,请参阅 http://wiki.eclipse.org/EclipseLink/Examples/JPA/Caching 或< a href =http://wiki.eclipse.org/EclipseLink/FAQ/How_to_disable_the_shared_cache%3F =noreferrer> http://wiki.eclipse.org/EclipseLink/FAQ/How_to_disable_the_shared_cache%3F



根据您的数据和要求,EclipseLink中还有其他选项。




  1. 停用共享缓存


  2. 启用缓存协调请参阅 http://www.eclipse .org / eclipselink / api / 2.1 / org / eclipse / persistence / config / PersistenceUnitProperties.html#COORDINATION_PROTOCOL


  3. 设置缓存无效超时(请参阅 http: //www.eclipse.org/eclipselink/api/2.1/org/eclipse/persistence/annotations/Cache.html#expiry%28%29


  4. 启用乐观锁定,这将确保任何过时的对象不能被更新,当对失效数据发生更新时,它将失败,并且EclipseLink将自动使缓存中的对象无效。


  5. 调查EclipseLink和Oracle Coherence的Oracle TopLink集成以提供分布式缓存。


另请参阅 http://en.wikibooks.org/wiki/Java_Persistence/Caching# Caching_in_a_Cluster



没有完美的解决方案,使用的解决方案通常取决于数据/类,通常一个应用程序有一组只读类,read - 主要是类和写主要类。就我个人而言,我将启用缓存为只读的1天超时,启用缓存协调缓存的读取主要,并禁用写入的缓存大多。


I am currently working on a project that uses JPA (Toplink, currently) for its persistence. Currently, we are running a single application server, but, for redundancy, we would like to add a load balancer and another application sever (and possibly more as it grows).

First, I'm running into the issue of JPA caching. Since two processes will be updating the same database, the JPA cache returns the cached value rather than going to the database. I see how to turn that off, and the database itself implements a level of caching. Is turning off the cache completely the way to go here? I see the ways to tell JPA to always get from the database at a query level, but in a multi-server environment, it seems that you'll always want that to happen.

Along with this specific question, I'm interested in anyone out there who has implemented a JPA solution with multiple application servers and what problems arose during the implementation (and any suggestions you have).

Thanks much.

解决方案

As you have found, you can disable the shared cache, see http://wiki.eclipse.org/EclipseLink/Examples/JPA/Caching or http://wiki.eclipse.org/EclipseLink/FAQ/How_to_disable_the_shared_cache%3F

There are also other options available in EclipseLink depending on your data and requirements.

A list of option include:

  1. Disable shared cache

  2. Enable cache coordination (see, http://www.eclipse.org/eclipselink/api/2.1/org/eclipse/persistence/config/PersistenceUnitProperties.html#COORDINATION_PROTOCOL)

  3. Set a cache invalidation timeout (see, http://www.eclipse.org/eclipselink/api/2.1/org/eclipse/persistence/annotations/Cache.html#expiry%28%29)

  4. Enable optimistic locking, this will ensure that any stale object cannot be updated, when an update on stale data occurs it will fail, and EclipseLink will automatically invalidate the object in the cache.

  5. Investigate the Oracle TopLink integration of EclipseLink and Oracle Coherence to provide a distributed cache.

See also, http://en.wikibooks.org/wiki/Java_Persistence/Caching#Caching_in_a_Cluster

There is no perfect solution, the solution used normally depend on the data/class, normally an application has a set of read-only classes, read-mostly classes and write mostly classes. Personally I would enable the cache for the read-only with a 1 day timeout, enable the cache with cache coordination for the read-mostly, and disable the cache for the write mostly.

这篇关于具有多个服务器的JPA的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆