singleton

Is it necessary to deconstruct singleton sql connections?

谁说胖子不能爱 提交于 2019-12-12 03:24:11
问题 Normally I'm using the statements: using (SqlConnection connection = new SqlConnection("Data ...")) { .... } to define areas where I use sql commands. Now for a specific application I'm considering putting the sql connection into a singleton instead of the above construct: public class SimpleClass { // Static variable that must be initialized at run time. public static SqlConnection singletonConnection; // Static constructor is called at most one time, before any // instance constructor is

Mage registry key “_singleton/info/feed” already exists

久未见 提交于 2019-12-12 03:21:44
问题 Error i encountered while accessing mysite.com/admin admin area is Mage registry key "_singleton/info/feed" already exists I couldn't found anything on web relating this except a discussion in a non english forum and i am not being able to access backend. 回答1: I'm answering this regarding @pankaj Comment As my backend is already blocked with error page, option i have to clear cache and session is : To clear the cache, simply delete everything from the /var/cache directory and then reload your

Is a singleton a good way of instantiating a HttpClient

最后都变了- 提交于 2019-12-12 03:09:10
问题 I have a C# library that makes calls to a restful web service using a HttpClient. The class library is used inside an MVC application that could run for weeks without being restarted. Is a singleton a good way of creating the HttpClient so I have just one HttpClient for the very long life of the MVC application? 回答1: I singleton would keep the HttpClient for the life of the application, but I would ask why you want to do that. It is not good practice. HttpClient implements IDisposable ,

Java EE Singleton Scheduled Task Executed twice

半城伤御伤魂 提交于 2019-12-12 02:38:15
问题 I want to execute two tasks on scheduled time (23:59 CET and 08:00 CET). I have created an EJB singleton bean that maintains those methods: @Singleton public class OfferManager { @Schedule(hour = "23", minute = "59", timezone = "CET") @AccessTimeout(value = 0) // concurrent access is not permitted public void fetchNewOffers() { Logger.getLogger(OfferManager.class.getName()).log(Level.INFO, "Fetching new offers started"); // ... Logger.getLogger(OfferManager.class.getName()).log(Level.INFO,

Are Multiple singleton instances possible in a shared DLL?

 ̄綄美尐妖づ 提交于 2019-12-12 01:53:22
问题 I am going to develop a DLL for an MFC Application, and suppose I have a singleton class in this DLL with some synchronization mechanism. And this DLL is used by other processes, namely EXEs. The question is: is this singleton created only once for all sharing processes or every process has its own singleton? And How can I solve this multiple singleton problem? 回答1: I suppose you are talking about Windows. In that case every process has its own singleton. You could place it in shared memory

Creating a Singleton Controller class in JavaFX

做~自己de王妃 提交于 2019-12-12 01:41:49
问题 I am running into issues getting the below code to execute. All of it works except for the part in the Prompter that says This is my issue area. In that area i need to return the value of controller.getNoun().getText(); which works fine but returns null because i cant figure out how to call controller without initializing it. I tried a Singleton class based on another thread on this site but Controller never got initialized until i called it here so my Noun value was still getting nulled out.

how to make a sington dialog

旧城冷巷雨未停 提交于 2019-12-12 01:35:49
问题 In android app, having a few activities with multiple fragments. Those activities or fragment could be running alive even if it's not on the top of the backStack, and receiving notifications from different services. When some event happens it is required to show a dialog to communicate with user. The activity or fragment on top of the stack may not have the handler for that event. Any other activity or fragment who is interested should react to open one dialog to the user. The problem is the

Singleton: Where to create instance?

我的未来我决定 提交于 2019-12-12 01:34:39
问题 Does anyone have any preferences or comments about using either ... static id sharedReactor = nil; +(id)sharedInstance { if(sharedReactor == nil) sharedReactor = [[super allocWithZone:NULL] init]; return sharedReactor; } OR: static id sharedReactor = nil; +(void)initialize { if(sharedRandomReactor == nil) { sharedRandomReactor = [[super allocWithZone:NULL] init]; } +(id) sharedInstance { return sharedReactor; } To my mind using +(void)initialize seems a lot more elegant, I am just curious

Encapsulating an expensive resource without using a Singleton

时光总嘲笑我的痴心妄想 提交于 2019-12-12 01:33:41
问题 I am working on updating a legacy application that is absolutely rife with Singleton classes. A perfect example would be the SnmpConnector class: public SnmpConnector { public static IEnumerable<string> HostIpAddresses { ... } private static SnmpConnector instance; public static SnmpConnector Instance { if (instance == null) instance = new SnmpConnector(); return instance; } private SnmpConnector() { foreach (string IpAddress in HostIpAddresses) { ... } } ... } The goal of this update is to

Concise Singleton impl that supports reentrancy

余生长醉 提交于 2019-12-12 00:35:41
问题 I would like to find a concise C# implementation of the Singleton pattern, and I am wondering if it should support the following scenario. What if my singleton's private constructor, as part of initializing the instance, calls a constructor that itself tries to access the singleton currently being initialized? This is what I meant by reentrancy in this question's title. Some would say that a constructor shouldn't do anything complex enough that could lead to this occurring. But what if, due