singleton

Trouble creating a simple singleton class in Jersey 2 using built-in Jersey dependency injection

爱⌒轻易说出口 提交于 2020-05-09 21:40:19
问题 I am having trouble getting a very basic implementation of a singleton class off the ground with Jersey 2 (2.7) and only Jersey's built-in HK2 dependency injection. I am running this on Tomcat. My goal is to create a singleton instance of a support class that will be used by various web service methods. I don't have a strong preference between constructor injection, method injection, and annotating a class member (as I do below). Here is my to-be-singleton class: package singletest; import

do we need volatile when implementing singleton using double-check locking

懵懂的女人 提交于 2020-05-09 06:05:32
问题 suppose we use double-check lock to implement singleton pattern: private static Singleton instance; private static Object lock = new Object(); public static Singleton getInstance() { if(instance == null) { synchronized (lock) { if(instance == null) { instance = new Singleton(); } } } return instance; } Do we need to set variable "instance" as "volatile"? I hear a saying that we need it to disable reordering: When an object is created , reordering may happen: address=alloc instance=someAddress

do we need volatile when implementing singleton using double-check locking

馋奶兔 提交于 2020-05-09 06:04:21
问题 suppose we use double-check lock to implement singleton pattern: private static Singleton instance; private static Object lock = new Object(); public static Singleton getInstance() { if(instance == null) { synchronized (lock) { if(instance == null) { instance = new Singleton(); } } } return instance; } Do we need to set variable "instance" as "volatile"? I hear a saying that we need it to disable reordering: When an object is created , reordering may happen: address=alloc instance=someAddress

Azure function running multiple times for the same service bus queue message

杀马特。学长 韩版系。学妹 提交于 2020-05-02 03:31:54
问题 I have an Azure function (based on the new C# functions instead of the old .csx functions) that is triggered whenever a message comes into an Azure Service Bus Queue. Once the function is triggered, it starts processing the service bus message. It decodes the message, reads a bunch of databases, updates a bunch of others, etc... This can take upwards of 30 minutes at times. Since, this is not a time sensitive process, 30 minutes or even 60 minutes is not an issue. The problem is that in the

Is this really a singleton? [closed]

三世轮回 提交于 2020-04-16 07:09:14
问题 Closed . This question is opinion-based. It is not currently accepting answers. Want to improve this question? Update the question so it can be answered with facts and citations by editing this post. Closed 2 years ago . I've got a singleton class like this. class UserInteraction { private CustomerInformation _loginDetails; private MusicDetails[] _musicFilesDownloaded; private static volatile UserInteraction _interactionObject = null; private static object syncRoot = new Object(); private

Is this really a singleton? [closed]

二次信任 提交于 2020-04-16 07:08:10
问题 Closed . This question is opinion-based. It is not currently accepting answers. Want to improve this question? Update the question so it can be answered with facts and citations by editing this post. Closed 2 years ago . I've got a singleton class like this. class UserInteraction { private CustomerInformation _loginDetails; private MusicDetails[] _musicFilesDownloaded; private static volatile UserInteraction _interactionObject = null; private static object syncRoot = new Object(); private

Best way to implement Unity Singleton?

自作多情 提交于 2020-04-16 04:43:11
问题 I'm a beginner to Unity. I'm currently implementing Singleton. I have questions while studying. What is the best way to implement Singleton in Unity like the title? I understand why use a singleton. that is.. " To create an object once and use it whenever need it. " Do I understand it properly? There are many ways to implement singletons. It's right? Then, Which part of the many methods are used in common? My singleton code is: public class GameSingleton<T> : MonoBehaviour where T :

The need for volatile modifier in double checked locking in .NET

耗尽温柔 提交于 2020-03-07 05:35:35
问题 Multiple texts say that when implementing double-checked locking in .NET the field you are locking on should have volatile modifier applied. But why exactly? Considering the following example: public sealed class Singleton { private static volatile Singleton instance; private static object syncRoot = new Object(); private Singleton() {} public static Singleton Instance { get { if (instance == null) { lock (syncRoot) { if (instance == null) instance = new Singleton(); } } return instance; } }

The need for volatile modifier in double checked locking in .NET

不羁的心 提交于 2020-03-07 05:33:09
问题 Multiple texts say that when implementing double-checked locking in .NET the field you are locking on should have volatile modifier applied. But why exactly? Considering the following example: public sealed class Singleton { private static volatile Singleton instance; private static object syncRoot = new Object(); private Singleton() {} public static Singleton Instance { get { if (instance == null) { lock (syncRoot) { if (instance == null) instance = new Singleton(); } } return instance; } }

Are Java Spring services evil as they are singleton? [closed]

≯℡__Kan透↙ 提交于 2020-03-03 04:43:11
问题 Closed . This question is opinion-based. It is not currently accepting answers. Want to improve this question? Update the question so it can be answered with facts and citations by editing this post. Closed 5 years ago . I have read a number of discussions on web and stack which claim singletons to be evil. Like: root-cause-of-singletons and Why is Singleton considered an anti-pattern? I read comments like "singletons make code complex, pain to reuse and test". I work with code that has