singleton

Do I need to import members of a singleton object into its companion class in Scala?

The Good Book states that: A class and its companion object can access each other’s private members. Perhaps naively, I took this as meaning that a class didn't need to explicitly import the members from its companion object. I.e., the following would work: object Foo { def bar = 4 } class Foo { def foo = bar } Well, the re...

Jython: Access singleton Java class (static)

Hi, I cannot seem to get the syntax quite right for this: I have a Jython script and a Java application loaded into the same JVM (for testing). I need to access a particular part of the application through a Singleton class from the Jython script. How do I do this? Thanks EDIT: The set up is for automated testing, so assume that t...

Best way to load website settings once?

Hi, I'm still in need of help. I have website settings that I want to load using a singleton pattern. There are so many negatives about using this pattern and every one advices to use Inversion of Control or Dependency Injection. I have not yet worked with IoC or DI. What is the best way to load website settings once and use it acro...

Using Singleton in different classes

How do you create a instance of a singleton that can be used in other classes? For Example: //Singleton_Class.h #ifndef Singleton_Class #define Singleton_Class class Singleton { private: static Singleton _instance; Singleton() {} ~Singleton() {} Singleton(const Singleton &); Singleton & operator=(const Singleton &); pub...

JavaScript namespace with Singleton usage? I'm stumped!

Hey everyone, This is my first post on StackOverflow. This community has provided me with some great insights into lots of different coding questions over the years. So since I've been stuck on this particular task in JS for days, I decided I'd lean on this great community and see what sort of help I could get on my question. I saw a...

How to throw an exception from an enum constructor?

How can I throw an exception from an enum constructor? eg: public enum RLoader { INSTANCE; private RLoader() throws IOException { .... } } produces the error Unhandled exception type IOException ...

singleton creator in dwr

i want to create a comet application using dwr. here is my problem: i want to create a connection class as the comet connection between server and javascript. It should be unique among the session, so i want it to be singleton. i define the creator of this class as singleton however i can't get it work. any idea? here is my dwr.xml <dwr...

GWT+Java: Globals, Singletons, and Headaches.

So here's my project: I am building a central interface/dashboard to present the test data for several test types of multiple product versions. We're using TestNG on our massive product, and while not enough tests are being written, that's a discussion for another topic. Here's what the directory structure looks like: Filesystem/prod...

Can singleton class be static?

Hi, Can singleton class be static? ...

global variables in C++

In a C++ multi-threaded application with many classes, i am trying to find out what are the methods to define a global variable C style, define it as global in any one source file, define it as extern in a header which is included in the classes that access this variable. Write a Singleton class, which contains these global variables a...

WPF: Cannot reuse window after it has been closed.

I am trying to keep one instance of a Window around and when needed call ShowDialog. This worked find in winforms, but in WPF I recieve this exeception: System.InvalidOperationException: Cannot set Visibility or call Show, ShowDialog, or WindowInteropHelper.EnsureHandle after a Window has closed. Is there any way to do something li...

Need to know how to check if the inputted string has terminated within a thread-safe logger in C++

I am very new at this and apologise if my question is not clear. I have created a thread safe logger in C++. This logger will be used in a large program & will be called from multiple places. I am using a singleton so there is only one instance of the logger. This logger outputs to a file & to the console. It behaves similar to cout; it...

php Singleton pattern with Abstract class and Interface

I am developing a framework. And I have confronted with some difficulties. For Database I have created Abstract class, Interface and some Adapters for different SCDB. For example, Mysqli adapter has the constructor, which call the constructor of parent with settings array as parameter. Mysqli class uses the next scheme: class Hybrid_Db_...

C++ Singleton design question.

I have a requirement to have a only a single instance of a class at any given point of time. Singleton is the obvious candidate. But I have some other conditions that are not typical of a Singleton. The lifetime of the singleton is not the lifetime of the program. This object has to be created every time I enter a particular state and ...

How does Singleton work in Spring?

Spring default setting is Singleton for beans. So does that mean when 100 users access the same the site (service or bean), do those 100 sessions share the single instance of that service bean in thread manner or will 100 beans be created and each session has its own bean. If it is a latter, then how does Singleton pattern apply to it? C...

Can I have a singleton lifecycle webservice on glassfish V3?

Hi, I have a simple webservice created with Netbeans 6.5 and deployed into 2 glassfish servers V2.1 and V3. The ws has a basic method GetInstanceID that I call 3 times from a client. @WebService() public class FirstWS { private long m_instanceID = 0; //instance id //Log private void WriteLog(String cadena){ String msg = ""; ...

Corrupted singleton data using CxxTest

This is a weird problem and I'm not sure what to make of it. I have something like the following: struct Parms { const std::string value1; const std::string value2; std::string parm1; std::string parm2; Parms() : parm1(value1), parm2(value1) {} static const Parms& getDefaults() { static Parms defa...

Double checked locking pattern: Broken or not?

Why is the pattern considered broken? It looks fine to me? Any ideas? public static Singleton getInst() { if (instace == null) createInst(); return instace; } private static synchronized createInst() { if (instace == null) { instace = new Singleton(); } } ...

EF 4.0 model caching the data, and does not detect the modified data.

Dear All, I am developing ASP.NET application and I have problem with the EF 4.0 model. The EF model detects the newly added and deleted data, but not the modified data from the database. Here is an example of the problem what I have. A- Database: Script to generate the "Employees" database table CREATE TABLE [dbo].[Employees] ( ...

What's wrong with this singleton I created

I created a class which allows access to global access to a variable while only creating it once, essentially a singleton. However, it doesn't match any of the 'correct' ways to implement a singleton. I assume that it's not mentioned because there is something 'wrong' with it but I can't see any problem with it other then the lack of l...