singleton

Creating a singleton from any given class in javascript

I have written the following function that permits creation of singleton classes from given classes: function SingletonFrom(Constructor) { return function() { var self = arguments.callee; if (self._instance === undefined) { switch (arguments.length) { // this is ugly case 0: self._instanc...

abstract an Interface `ISingleton` to be base class

Hi , I have 3 interface classes IVideo , IAudio , IGPIO and three other classes that will implement those interface: Video_impl , Audio_impl , GPIO_impl. Things is simple so far. But then ,I want all those object to be singleton. Here are the questions: Is it a good idea to abstract an Interface ISingleton , so that Video_impl , Audi...

Implementing Singleton across requests to HttpHandler

I am attempting to create a singleton service that is used to process incoming requests to an HttpHandler. At the moment the service is being instantiated on every request. I make a call to the static class that holds an instance of the service, implemented as a singleton as below: public static class ServerApplication { static Servi...

Simplest/Cleanest way to implement singleton in JavaScript?

What is the simplest/cleanest way to implement singleton pattern in JavaScript? ...

How to add convenience class methods to a Singleton class in ruby

Let's say I have a singleton class like this: class Settings include Singleton def timeout # lazy-load timeout from config file, or whatever end end Now if I want to know what timeout to use I need to write something like: Settings.instance.timeout but I'd rather shorten that to Settings.timeout One obvious way to ma...

Destructor for Singleton

Question : Should i write destructor for a singleton which has program scope (comes alive when program starts and dies when program ends) Detail : i am in a dilemma on "shall i write destructor for a singleton class or not ?" 1) This class has program scope 2) Class uses a lot of memory on heap, So releasing that will take time...

Singleton across classloaders/EJB:How to avoid multiple instance of JCS Cache due to multiple class loader/EJB's?

I want to use JCS (Java Cache System) to cache ldap queries which should be shared by multiple EJB's (class loaders) to avoid the duplicate searches. I have created a singleton wrapper to create only one instance of JCS cache but due to each EJB's having their own class loader, it creates multiple instance of JCS cache so ldap search re...

What is the correct way to write a singleton pattern in Ruby?

I'm trying to write the most secure singleton in Ruby that I can. I'm new to the language, which is so elastic that I don't have a strong feeling that my singleton class will be successful at creating only one instance. As a bonus, I'd like the object to only become instantiated if really used. Thanks! ...

what is a singleton class? Can it help me running single instance of a class for two related services?

This might sound complex but i will ask anyway: I am running a service A which uses class X. I want to start another service B which uses classes A besides new classes. Service A is already running. I do a hot deployment of Service B. Here is the real question - Will Service B use the same instance of class X or a separate instance....

How can I use a singleton class in AOP (aspect oriented programming)?

Language by choice is AspectJ but I am open for a generic answer. ...

How to create a true singleton in java?

I am facing a problem with my singleton when used across multiple class loaders. E.g Singleton accessed by multiple EJBs. Is there any way to create a singleton which has only one instance across all class loader? I am looking for pure java solution either using custom class loader or some other way. ...

How to make a singleton class threadsafe?

I am implementing a singleton class in Java to make sure no more than one instance of the class is created. ...

How can a singleton class use an interface?

I read at many places that singletons can use interfaces. Some how I am unable to comprehend this. ...

How do you share Java Caching System (JCS) resource across multiple EJB

I am using JCS to store the ldap search results which should be shared by multiple EJB. I have created a singleton class to initialize JCS only once but due to EJB's classloader, it's been initialized multiple times with its own copy. so search resources are not shared. How are you guys resolving issue where you need to share the cache ...

Problem in understanding how singleton methods work in Ruby

I am struggling to understand how singleton methods work in Ruby at the object level. When I define a simple Person class and add singleton method and instance methods and try to access eigenclass object id of that object it returns different ids. To put simply here is my test code. class Person attr_accessor :someAccessor def met...

Why use the ServletContext object in a web-app containing servlets and "worker" threads in Java

Hi, I currently have a web-app where I have Servlets reading and writing to the ServletContext attributes and I have "working" Threads (Daemon threads) which get initialized on startup and currently hold as a member the ServletContext object. For a couple of reasons I'm thinking of moving to "implement Runnable" instead and I'm kind of s...

If not a singleton, then what?

So I'm working on a middleware layer. I'm consuming a COM DLL that deals with the low level hardware interaction, and providing an interface for the UI to do IO with the hardware. As part of the design of my layer, we put in a contextmanager that arranges the various pieces of hardware to produce contexts that our application can work ...

Module pattern vs. instance of an anonymous constructor

So there's this so-called module pattern for creating singletons with private members: var foo = (function () { var _foo = 'private!'; return { foo: function () { console.log(_foo); }, bar: 'public!' } })(); There's also this method that I found on my own, but haven't seen anything written about: var foo =...

Scalability implications of converting stateless session beans to POJOs

Imagine a heavily-used service object that's implemented as an EJB 2.1 SLSB, and that also happens to be thread-safe in itself by virtue of having no state whatsoever. All its public methods are transactional (via CMT), most simply requiring a transaction, but some requiring a new transaction. If I convert this SLSB to a genuine singlet...

Why am I getting unresolved externals?

I am writing an immutable binary search tree in c++. My terminating nodes are represented by a singleton empty node. My compiler (visual c++) seems to be having trouble resolving the protected static member that holds my singleton. I get the following error: error LNK2001: unresolved external symbol "protected: static class boost::sh...