简体   繁体   English

访问单例的并发线程

[英]Concurrent threads accessing a singleton

how does Java behave when it has thousands of threads accessing the same instance?当 Java 有数千个线程访问同一个实例时,它的行为如何?

I am building an ERP and I am intending to create a Singleton so that it is able to do any kind of persistence (Insert, Update, Delete) in my base.我正在构建一个 ERP,我打算创建一个单例,以便它能够在我的基础上执行任何类型的持久性(插入、更新、删除)。 This singleton will have no global variables other than the instance itself.除了实例本身之外,这个单例没有全局变量。 It will have only its methods.它将只有它的方法。

My question is that as I will centralize all ERP persistence on this single instance, this can become a bottleneck and a cause for slowness.我的问题是,当我将所有 ERP 持久性集中在这个单一实例上时,这可能会成为瓶颈和缓慢的原因。 Can this occur?这会发生吗? I'm talking about 500,000 simultaneous hits in this instance.在这种情况下,我指的是 500,000 次同时点击。

如果您的单例是不可变的,则多个线程将同时使用其方法而不会降低延迟。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM