singleton

Java Swing & Postgres user authentication: Close old connection when new connection opened

此生再无相见时 提交于 2020-01-06 20:08:08
问题 I have a Java Swing application that accesses a Postgres database using a simple Singleton Pattern: public class DatabaseConnection { private static final String uname = "*******"; private static final String pword = "*******"; private static final String url = "*******************************"; Connection connection; // load jdbc driver public DatabaseConnection(){ try{ Class.forName("org.postgresql.Driver"); establishConnection(); } catch (ClassNotFoundException ce) { System.out.println(

QT Access MainWindow SQLite Variable from Another Class

北城以北 提交于 2020-01-06 19:53:35
问题 My app opens the SQLite database connection when the MainWindow launches and closes it when the MainWindow is destroyed. How do I access the database connection from other classes. I think I need to use a singleton format but haven't had any luck implementing it. Here's what I have tried. It errors with. C:\Users\cbennett\C++\CA_Letter_Generator\letter.cpp:9: error: expected primary-expression before '.' token QSqlQuery qLetter = MainWindow.getDB().selectAll("letters","ltID=" + QString:

objective c: passing a char argument to function crashes the app

半城伤御伤魂 提交于 2020-01-06 19:29:30
问题 I wrote a singleton called SomeValues where I initialize a foo NSMutableArray. I then tried to write a function SetBFSV to set the values of this array from different control views. @interface SomeValues : NSObject { NSMutableArray *foo;} + (SomeValues *) sharedInstance; @implementation ... - (void) SetBFSV:(char)lbl ToVal:(long)BFSvl{ NSNumber *ValueBFSvl = [NSNumber numberWithLong:BFSvl]; NSString *Strlbl = [[NSString alloc] stringWithFormat:@"%s",lbl]; [foo setValue:ValueBFSvl forKey

Implementation of singleton thread-safe list

北战南征 提交于 2020-01-06 15:16:00
问题 I'm using Spring framework. Need to have a list of objects, which should get all data from database at once. When data is changed, list will be null and next get operation should fill data from database again. Is my code correct for multi-thread environment? @Component @Scope("singleton") public class MyObjectHolder { private volatile List<MyObject> objectList = null; public List<MyObject> getObjectList() { if (objectList == null) { synchronized (objectList) { if (objectList == null) {

Singleton class for moving heap to stack

江枫思渺然 提交于 2020-01-06 14:16:17
问题 I have written some class that moves heap allocated stuff to stack (hopefully :) ). This calss is singleton because only this class should be responsible for holding and managing part of stack. My question is: Is my code correct? Code is correct in the sense of programming (no compile errors, no memory errors and leaks (checked by valgrind)). But does the code really moves heap to stack? Here's the code: stack.hpp: class CStack{ public: void* getAlloc(long); static CStack* Instance(); private

php - Dynamically update Singleton class' value

霸气de小男生 提交于 2020-01-06 14:04:49
问题 This is a followup question to this question If I declare this as a singleton class: // Server.php class Server { private $stopper; private static $instance; public static getInstance() { if(!isset(self::$Server)) self::$Server = new static(); return self::$Server; } public function setStopper() { $this->stopper = TRUE; } public function startServer() { $self = $this; $consumer = new Consumer(); $consumer->onConsume(function($data) use($self, $consumer) { // some processing if($self-

PHP MySQLi Singleton for Ajax-Requests end in to many processes

好久不见. 提交于 2020-01-06 13:53:00
问题 I have a PHP application which uses AJAX to get information - in the back, it uses a PHP MySQLi singleton. The AJAX-requests are send every 0.5 second and they read some stuff out of the database and deliver it as a JSON String back to website. When I open the website several times (in different tabs), I then get an error because PHP, or rather apache, could not "fork another process". My server has enough RAM, but the problem is taht the process-limit of 130 processes was reached. cat /proc

PDO Prepare statement not processing parameters

[亡魂溺海] 提交于 2020-01-06 08:33:26
问题 I've exhausted all efforts at what appears to be a trivial problem, but gotten nowhere. There is a simple Prepare statement: $qry = $core->db->prepare("SELECT * FROM users WHERE email = '?'"); $qry->execute(array('email@address.com')); However, no rows are returned. Running the query with the parameters hardcoded into the query results in a successful selection of one row. I've tryed many different methods of doing the prepare, but even it this most simple form it isn't working. The PDO

Are there any downsides to the singleton pattern? [duplicate]

别说谁变了你拦得住时间么 提交于 2020-01-06 07:20:31
问题 This question already has answers here : Closed 9 years ago . 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 回答1: From Wikipedia: Some consider it an anti-pattern , judging that it is overused, introduces unnecessary limitations in situations where a

How to check if a web service is running in multiple threads instead of a single one?

我与影子孤独终老i 提交于 2020-01-06 04:46:06
问题 I have a webservice (asmx) that is running on 2 different servers that sit behind a load balancer. The service is called by multiple clients across our organization, as per my current knowledge, none of the clients use multiple threads. I'm investigating a production issue where some of the data in a few static variables is clearing or returning null or empty, causing db exceptions and foreign key constraint errors. Upon investigation, I noticed that the singleton pattern is not implemented