singleton

How to manage Singleton instance?

This is a duplicate of: http://stackoverflow.com/questions/2155688/what-is-a-singleton-in-c I don't think it is duplicate, as here what I am looking for is best strategy for releasing/disposing the Singleto object when not in use. How to implement a Singleton so that object instance can be released/disposed when all it's references are...

Are there more ways to define a tuple with only one item?

I know this is one way, by placing a comma: >>> empty = () >>> singleton = 'hello', # <-- note trailing comma >>> len(empty) 0 >>> len(singleton) 1 >>> singleton ('hello',) Source: http://docs.python.org/tutorial/datastructures.html Are there more ways to define a tuple with only 1 item? ...

Glassfish initialising Singleton bean twice

Hi, I have a singleton ejb which is getting initialised twice. I have no idea why and it is completly defenting the point in having a singleton bean as far as I can tell. Any help will be appreciated. As you can see I tried to put a static boolean in to prevent the multiple initialisation (not that it should be required) but it made no ...

mod_passenger, threads and singleton classes

I have a question regarding mod_passenger and Singleton classes (rails 2.3.5 and ruby 1.9.1). In my aplication, I have a Singleton class that implements a thread pool (thread safe). Also there is controller to manage all the threads (kill and start them). This controller uses the previous singleton class to do the actions over the thre...

Singleton and Exception

Hi Guys, Whats the best way to design a singleton class that could throw an exception? Here I have a Singleton (using Bill Pugh's method, documented in Wiki for Singleton). private static class SingletonObjectFactoryHolder{ //1 private static final ObjectFactory INSTANCE = new ObjectFactory(); } private Obje...

PHP Singleton: not holding instance

Hi All, I'm just becoming dive into php after ages working in vb.net. I wanna write a logger class that runs as singleon over my webapp, here the code: class cLog{ private $data = NULL; static private $instance = NULL; static public function getInstance(){ if(self::$instance == NULL){ echo "empty!"; self::$inst...

Is this the definitive ref counted Objective C singleton implementation??

Here is what I have concocted, after poring over the singleton literature. Have I forgotten anything? @implementation MySingleton static MySingleton *mySharedInstance = nil; //called by atexit on exit, to ensure all resources are freed properly (not just memory) static void singleton_remover() { //free resources here } + (MySin...

IDisposable in Singleton-- Good Practice?

I have a Singleton class that manages the connection to an external device. The idea of my application is that I need that external device to be presented all the time when the application is alive. The Singleton has the following functionalities: Initialization, look for the device at the application startup time communicate with the...

iphone global settings - best way to implement it?

Hi all, I'd like to have some settings that I can access from anywhere in my app. Is there a best way to implement this? Right now I'm just sticking properties in my app delegate, then access them with: ClientAppDelegate *appDelegate = (ClientAppDelegate *)[[UIApplication sharedApplication] delegate]; settingValue = appDelegate.setting...

Django with fastcgi and threads

I have a Django app, which spawns a thread to communicate with another server, using Pyro. Unfortunately, it seems like under fastcgi, multiple versions of this thread are fired off, and a dictionary that should be globally constant within my program, isn't. (Sometimes it has the values I expect, sometimes not) What's the best way to e...

How to make a singleton in PHP4?

How do I make a singleton in PHP4? Is static available in PHP4? HELP!!!!!!!!!!!!!! ...

Force initialization of singleton in c++ before main()

I am using singletons as follows: // Foo.hpp class Foo { static Foo* instance() { static Foo* foo = new Foo(); return foo; } } Now, my singleton is initialized the first time Foo::instance() is called. I want to make sure this is before main executes (my code is multi threaded, I want all singletons initialized before pThr...

How can I implement a singleton class in perl?

What's the best practice for implementing Singletons in Perl? ...

How can I make one class solely responsible for creating and providing access to another class.

This is how I understand I can implement the singleton pattern in C#: public class ChesneyHawkes{ private static ChesneyHawkes _instance = new ChesneyHawkes(); public ChesneyHawkes Instance {get{return _instance;}} private ChesneyHawkes() { } } What if I want to provide a single instance of an object, so that the...

Why is PMF.java a 'final' class?

According to the App Engine docs, the PersistenceManagerFactory should only be created once in the application. It provides this sample: package guestbook; import javax.jdo.JDOHelper; import javax.jdo.PersistenceManagerFactory; public final class PMF { private static final PersistenceManagerFactory pmfInstance = JDOHelper...

Where should I keep my FacebookSession object for a Flex AS3 project?

This question extends beyond the Facebook library and is really a general architecture question. I am using the Facebook AS3 lib which has a FacebookSession class. The class contains data for a facebook session so that I can make authenticated calls to the Facebook API. I am using the Facebook API all over my Flex app and I am tempted...

Are there any downsides to the singleton pattern?

Possible Duplicates: What is so bad about Singletons Problems with Singleton Pattern Are there any downsides to the singleton pattern? I heard this was an interview question and i am coming up short on what was meant. imho, it's about the usage and nothing in the pattern itself is problematic ...

C++ templated class implementation of the multiton pattern

I implemented the multiton pattern using a templated class in C++. #ifndef MULTITON_H #define MULTITON_H #include <map> template <typename Key, typename T> class Multiton { public: static void destroy() { for (typename std::map<Key, T*>::iterator it = instances.begin(); it != instances.end(); ++it) { de...

StructureMap singleton usage (A class implementing two interface)

public interface IInterface1 { } public interface IInterface2 { } public class MyClass : IInterface1, IInterface2 { } ... ObjectFactory.Initialize(x => { x.For<IInterface1>().Singleton().Use<MyClass>(); x.For<IInterface2>().Singleton().Use<MyClass>(); }); var x = ObjectFactory.GetInstance<IInterface1>(); var y = ObjectFactor...

problems with singleton COM servers and windows services

Hi, I am using Windows XP SP2, VS 2008 SP1 like this: brought up 2 singleton COM servers out of process in c++ one GUI app in c++ The GUI app used to instantiate both singleton COM servers and then two other programs used to load each singleton COM server - one server for the first prog, the other for second prog. All went well mi...