简体   繁体   English

在同一个Java应用程序的不同实例之间共享数据结构的最佳方法?

[英]Best way to share a data structure between different instances of the same java application?

Currently, I'm developing an application based on spring boot. 目前,我正在开发基于Spring Boot的应用程序。 One of the requirements is that the application should be real-time and I need some kind of unique data structure based on InvertedRadixTree (not exactly this but data strucutre is using the tree to answer the queries). 要求之一是应用程序应该是实时的,我需要某种基于InvertedRadixTree的独特数据结构(不完全是这种结构,而是数据结构使用树来回答查询)。 I developed an admin UI for crud operations. 我为粗体操作开发了一个管理UI。 The number of cruds are not so much and basically will be done by OPs employees. 杂物的数量不是很多,基本上将由OP员工完成。 the data structure that I developed is thread safe and is synchronized by database(which is mongodb) and since this is the only app using this database, I'm not worried about the other apps messing up with the data. 我开发的数据结构是线程安全的,并且通过数据库(mongodb)进行了同步,并且由于这是唯一使用此数据库的应用程序,因此我不担心其他应用程序会弄乱数据。 The only problem that I have is that if we have multiple instances of this app, and one of them do some crud operations on mongodb; 我唯一的问题是,如果我们有该应用程序的多个实例,并且其中一个实例在mongodb上执行了一些操作。 although the data structure of this instance will get updated, the other instance will not be updated. 尽管此实例的数据结构将被更新,但另一个实例将不被更新。 I created an scheduler to update the data structure from database every 12 hours, but I'm looking for another solution like sharing data structure between all the instances. 我创建了一个调度程序,每12小时更新一次数据库中的数据结构,但是我正在寻找另一种解决方案,例如在所有实例之间共享数据结构。 I really appreciate every suggestions. 我真的很感谢所有建议。

EDIT: After searching around, I found that updating the whole data structure doesn't take to much. 编辑:搜索后,我发现更新整个数据结构并不需要太多。 I wrote some test cases and put around a million record of my class inside mongodb and fetched the whole collection. 我写了一些测试用例,并在mongodb中放了上百万个类的记录,并获取了整个集合。 Fetching and data structure creation took less than a second. 提取和数据结构创建花费了不到一秒钟的时间。 So I ended up using this method instead of using some sophisticated method for synchronizing memory and database. 因此,我最终使用了这种方法,而不是使用一些复杂的方法来同步内存和数据库。

One of the suggestion can be that you can use a shared database. 建议之一是可以使用共享数据库。 Every time there is an update by any of the APP,It should be updated in the database.And every time you have to use the data you will have to load the fresh data from the database.This is the easiest way as far as i think ..!!! 每次有任何APP进行更新时,都应该在数据库中进行更新。每次使用数据时,都必须从数据库中加载新数据。这是迄今为止最简单的方法想.. !!!

我会使用类似redis http://redis.io/topics/pubsub之类的东西,并监听为该实例触发的事件以进行更改,如果数据不经常更新,则在每个实例上使用一些本地缓存

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Java:在不同线程之间共享锁的最佳方法 - Java: best way to share Lock between different threads 在不同的JUnit测试类之间共享数据的最佳方法是什么 - What is the best way to share data between different JUnit test classes 在相同类别的特定实例之间共享数据 - Share data between specific instances of same class 使用JBoss和Spring在Java Web应用程序之间共享业务对象实例的最佳方法是什么? - What's the best way to share business object instances between Java web apps using JBoss and Spring? 如何在应用程序的所有实例之间共享相同的电子邮件会话? - How to share the same email session between all instances of the application? Java:使用剪贴板在同一应用程序的不同实例之间复制粘贴java对象 - Java: use clipboard to copy-paste java objects between different instances of same application 哪种Java数据结构最适合我的应用程序? - Which is the best Java Data structure for my application? Java Jersey:什么是在主对象和Web服务之间共享数据的最佳方法 - Java Jersey: Whats the best way to share data between the Main-object and the Webservice 在具体的JPA类之间共享Java实现的最佳方法? - Best way to share Java implementation between concrete JPA classes? 在Java中,枚举值之间共享功能的最佳方法是什么? - In Java, what is the best way to share functionality between enum value?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM