Все вопросы: [singleton]

270 вопросов

0
голосов
10ответов
383 просмотров

How to manage a dictionary of lazily created objects in a multithreaded environment in .NET?

This question is in continuation of this one. The deal is simple. Given: A collection of lazily created singletons. Multithreaded environment. Wanted: An implementation with as little lock penalty as possible when an already created object is accessed. It is OK to pay higher penalty on rem...

2
голосов
4ответов
8671 просмотров

SqlConnection as a static singleton object

public class db { public static string connectionString = WebConfigurationManager.ConnectionStrings["connectString"].ConnectionString; public static SqlConnection OpenConnection() { SqlConnection connection = new SqlConnection(connectionString); connection....

1
голосов
2ответов
139 просмотров

debugging Flex ActionScript singleton

When I am stepping through code in the Flex debugger, and enter my singleton class, "this" appears in the variables window but this cannot be expanded. How do you inspect the variables of "this".

6
голосов
3ответов
22246 просмотров

The procedure entry point could not be located in the dynamic link library Core.dll

I am converting my project to use DLLs and am trying to break apart my Singleton class to avoid using templates. My class, LudoMemory, originally inherited from Singleton. I am trying to give it the functions to destroy and create itself now and have my main engine not rely on the Singleton. ...

1
голосов
2ответов
3574 просмотров

Python Singletons - How do you get rid of (__del__) them in your testbench?

Many thanks for the advice you have given me thus far. Using testbenches is something this forum has really shown me the light on and for that I am appreciative. My problem is that I am playing with a singleton and normally I won't del it, but in a testbench I will need to. So can anyone show ...

6
голосов
5ответов
7426 просмотров

Ensure that only one instance of a class gets run

I have an underlying class which I want to place in some code. I only want it to be instantiated or started once for a given app although it might be called many times.. The problem with the code below is that LowClass is started over and over again. I only want it to start once per test.. im...

2
голосов
1ответов
6493 просмотров

Singleton in a DLL?

So i am trying to export somethings in a project to DLL. Anyways a few of the projects use a singleton class very heavily. template <typename T> class DLL_IMP VA_Singleton { protected: VA_Singleton () {}; ~VA_Singleton () {}; public: static T *Get(){ return (static_cas...

5
голосов
4ответов
11308 просмотров

Is using a singleton for the connection a good idea in ASP.NET website

I'm currently using a singleton on my web application so that there is always only one connection to the database. I want to know if it's a good idea because right now I'm having trouble with that error: Timeout expired. The timeout period elapsed prior to obtaining a connection from the pool....

2
голосов
1ответов
3889 просмотров

MySQL - Connection using Singleton pattern or a ConnectionPool?

The topic has already been on the table in some previous questions. New elements come with new problems. I am seeking here for the best way to handle database connection(s), concerning aspects of : maintainability, performance, security and implementation. I must mention that i am not interested ...

0
голосов
3ответов
1658 просмотров

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...

2
голосов
2ответов
1048 просмотров

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. I...

25
голосов
4ответов
5462 просмотров

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...

2
голосов
3ответов
459 просмотров

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 produ...

1
голосов
1ответов
4825 просмотров

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

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 "impleme...

2
голосов
1ответов
397 просмотров

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 Perso...

3
голосов
2ответов
2209 просмотров

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 resolvin...

11
голосов
5ответов
27007 просмотров

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.

5
голосов
6ответов
7042 просмотров

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.

5
голосов
4ответов
4569 просмотров

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 othe...

3
голосов
1ответов
1174 просмотров

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.

1
голосов
2ответов
245 просмотров

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 i...

26
голосов
3ответов
16115 просмотров

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.

4
голосов
6ответов
4458 просмотров

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...

5
голосов
1ответов
1097 просмотров

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 ...

309
голосов
37ответов
141865 просмотров

Simplest/Cleanest way to implement singleton in JavaScript?

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

0
голосов
3ответов
1251 просмотров

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 stat...

0
голосов
3ответов
527 просмотров

abstract an Interface `ISingleton` to be base class

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 IS...

0
голосов
2ответов
488 просмотров

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 u...

55
голосов
8ответов
58999 просмотров

C++ singleton vs. global static object

A friend of mine today asked me why should he prefer use of singleton over global static object? The way I started it to explain was that the singleton can have state vs. static global object won't...but then I wasn't sure..because this in C++.. (I was coming from C#) What are the advantages on...

0
голосов
3ответов
319 просмотров

singleton inside of a construct method in PHP?

Is it ok to use a singleton method inside of a __constructor to initiate the class if it wasn't already?