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 in abstractions like Hibernate, Spring, et...
Hi everyone,
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. This may have occurred bec...
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_cast<T*> (a_singleton));
}
static void Dele...
Hi SO's
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..
import logging
class LowClass:
...
Hi SO's,
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 me how to del the thing? I've s...
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.
I have written a simple destroy method li...
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".
...
public class db
{
public static string connectionString =
WebConfigurationManager.ConnectionStrings["connectString"].ConnectionString;
public static SqlConnection OpenConnection()
{
SqlConnection connection = new SqlConnection(connectionString);
connection.Open();
return connection;
}
}...
Dear ladies and sirs.
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 removal or lazy initia...
I am sorry if this is a duplicate or too elementary, but how do I make a singleton class that can be subclassed?
...
Simple question. Can I do this:
object Xyz extends Actor { ... }
or do Actors have to be classes with instances?
...
Until recently, our app shared a single Apache HttpClient instance using the ThreadSafeClientConnManager across the whole application. The http client instance was held by a singleton class.
Since I dislike the singleton pattern for its numerous problems, I refactored our API accessor to be a per-thread object, but now for every thread ...
Hi, I met a problem when trying @Singleton of Guice:
import com.google.inject.Singleton;
@Singleton
public class ConfigManager {
private String data;
public void setData(String data) {
this.data = data;
}
public String getData(){
return this.data;
}
public static void main(String[] args){
Confi...
My question is about threads being queued. For my example I have one Spring context. I have a method named CalculateTax in a stateless class. A request comes in, a thread is created (tA) and it eventually enters the CalculateTax method. Within the same "time frame" another request comes in and another thread is created (tB). Now, here is...
There is this DB-connection-like object that my web application will need. It is pretty slow to create and will be used rarely, so I would like to keep only a single instance of it around. If several requests need it at the same time, they will lock() the object and serialize their access.
To make things more fun the object is an IDispo...
Hi All,
I happened upon an article recently discussing the double checked locking pattern in Java and it's pitfalls and now I'm wondering if a variant of that pattern that I've been using for years now is subject to any issues.
I've looked at many posts and articles on the subject and understand the potential issues with getting a re...
Or it's better to use another Design Pattern?
...
Hi,
I am using my own custom navigationBar, but i need to access it in a number of different views because i need to add buttons, change title and so forth.
Should i pass a reference to my navigationBar each time i show a new view, or just make it a singleton so i can access it from any view?
...
I'm using this pattern for singletons, in the example the singleton is PlanetEarth:
var NAMESPACE = function () {
var privateFunction1 = function () {
privateFunction2();
};
var privateFunction2 = function () {
alert('I\'m private!');
};
var Constructors = {};
Constructors.PlanetEarth = function () {
privateFunction1();
...
Working in C# and Java, I've seen basically one way everybody initializes singletons:
static obj _inst = null;
obj getInstance() {
if (_inst == null) {
_inst = new obj();
}
return _inst;
}
Now, when I move to Objective-C for the iPhone, whenever I see code samples, I see basically the same thing:
static obj _inst = nil;
+...