Search Results

Search found 774 results on 31 pages for 'singleton'.

Page 23/31 | < Previous Page | 19 20 21 22 23 24 25 26 27 28 29 30  | Next Page >

  • Issue with Java join() method.

    - by gmunk
    First of all here are some code snippets: http://pastebin.com/9ZCwekXs http://pastebin.com/TtLLXPYP I'm trying to animate some images. The thing is that I want the main thread to wait for the animation thread to finish and then to continue. I searched around, read a little bit and decided to use the join() method. It perfectly waits for the thread to finish but I doesn't animate correctly. The repaint() method gets called 2 times instead of nine. I think maybe the problem is because I used singletons. Here is the singleton implementation. http://pastebin.com/bA3qLZJE

    Read the article

  • Setup Hibernate Session Factory in Tomcat

    - by Mark Estrada
    Hi All, I have been reading around the Hibernate core and I am still exploring some of its capability. It was mention in the docs that the SessionFactory is the heavyweight component of Hibernate thus it should be setup only once in a web application and in singleton. Each Session factory should pertain to one JDBC connection. Does anybody knows how to properly setup the session factory in tomcat web applications? Any links or tutorials would be better. Should I set it up as a contextlistener class also? Thanks.

    Read the article

  • How to manage db connections on server?

    - by simpatico
    I have a severe problem with my database connection in my web application. Since I use a single database connection for the whole application from singleton Database class, if i try concurrent db operations (two users) the database rollsback the transactions. This is my static method used: All threads/servlets call static Database.doSomething(...) methods, which in turn call the the below method. private static /* synchronized*/ Connection getConnection(final boolean autoCommit) throws SQLException { if (con == null) { con = new MyRegistrationBean().getConnection(); } con.setAutoCommit(true); //TODO return con; } What's the recommended way to manage this db connection/s I have, so that I don't incurr in the same problem.

    Read the article

  • iOS: How to access the `UIKeyboard`?

    - by MattDiPasquale
    I want to get a pointer reference to UIKeyboard *keyboard to the keyboard on screen so that I can add a transparent subview to it, covering it completely, to achieve the effect of disabling the UIKeyboard without hiding it. In doing this, can I assume that there's only one UIKeyboard on the screen at a time? I.e., is it a singleton? Where's the method [UIKeyboard sharedInstance]. Brownie points if you implement that method via a category. Or, even more brownie points if you convince me why it's a bad idea to assume only one keyboard and give me a better solution.

    Read the article

  • Eclipse Plugin: Enablement of an Action based on the current selection

    - by Itay
    I am using the org.eclipse.ui.popupMenus extension point for adding a sub-menu whose Action that is bounded to the following class: public class MyAction implements IObjectActionDelegate { private Logic logic = Logic.getInstance(); // Singleton public void setActivePart(IAction a, IWorkbenchPart targetPart) { // Nothing here } public void run(IAction a) { // Do something... } public void selectionChanged(IAction a, ISelection s) { a.setEnabled(logic.isEnabled(s)); } } This action is working correctly in most cases (including the call a.setEnabled() in selectionChanged()). My problem at the very first time my action is being invoked. The selectionChanged method is called only after the menu item has been displayed (and not when the user has made the selection) which means that the call to a.setEnabled() will have no affect. Any ideas on how to make my action receive selectionChanged() notifications even before the fist time it is being invoked?

    Read the article

  • Are today's young programmers getting wrapped around the axle with patterns and practices?

    - by Robert Harvey
    Recently I have noticed a number of questions on SO that look something like this: I am writing a small program to keep a list of the songs that I keep on my ipod. I'm thinking about writing it as a 3-tier MVC Ruby on Rails web application with TDD, DDD and IOC, using a factory pattern to create the classes and a singleton to store my application settings. Do you think I'm taking the right approach? Do you think that we're handing novice programmers a very sharp knife and telling them, "Don't cut yourself with this"? NOTE: Despite the humorous tone, this is a serious (and programming-related) question.

    Read the article

  • Error handling and polymorphism

    - by Neeraj
    I have an application with some bunch of code like this: errCode = callMainSystem(); switch (errCode){ case FailErr: error("Err corresponding to val1\n"); case IgnoreErr: error("Err corresponding to val2\n"); ... ... default: error("Unknown error\n"); } The values are enum constants. Will it make some sense to have something like: // Error* callMainSystem() ... Some code return FaileErr(); // or some other error // handling code Error* err = callMainSystem(); err->toString(); The Error class may be made singleton as it only has to print error messages. What are the pros and cons of above methods,size is an important criteria as the application needs to be supported on embedded devices as well. P.S: I don't want to use exception handling because of portability issues and associated overheads.

    Read the article

  • Using the StackTrace Class in a production environment to get calling method info

    - by andy
    hey guys We have a "log" class which uses Relection.MethodBase to send current class info to the log. The reflection.MethodBase stuff happens in the class itself. However, I'd like to move that stuff to a single external "log" singleton type class. In this scenario the external log class needs to get the CALLING info, not the current method info. I'm using stacktrace to do this, which isn't in the Reflection namespace. Can I guarantee that "that" specific information (calling method) will be there in a production environment? var stackTrace = new StackTrace(); return LogManager.GetLogger(stackTrace.GetFrame(1).GetMethod().DeclaringType); cheers!

    Read the article

  • IOS restkit error

    - by user1302602
    I am sending a Post with object loader and getting this error in output window. FYI, My didFailWithError: delegate never got hit. Not sure why. `objectLoader:didFailWithError:]:` unrecognized selector `sent to class 0x123608` How did i find out what is 0x123608? I set the router in AppDelegate class and Mapping in AppDelegate too. here is a method in my class which inherit RKObjectLoaderDelegate. I am using shared singleton. [[RKObjectManager sharedManager] postObject:review usingBlock:^(RKObjectLoader *loader){ // loader.params=params, loader.objectMapping = [[RKObjectManager sharedManager].mappingProvider objectMappingForClass:[myclass class]]; loader.serializationMIMEType = RKMIMETypeJSON; // We want to send this request as JSON loader.method = RKRequestMethodPOST; loader.serializationMapping = [RKObjectMapping serializationMappingUsingBlock:^(RKObjectMapping* mapping) { [mapping mapAttributes:@"field1", @"field2",@"field3",nil]; }]; loader.targetObject = nil; loader.delegate = self; }]; }

    Read the article

  • What's the point of having to provide a cacheName for NSFetchedResultsController?

    - by dontWatchMyProfile
    NSFetchedResultsController *frc = [[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest managedObjectContext:moc sectionNameKeyPath:nil cacheName:@"Root"]; Why do we have to think about a cacheName? How important is this decision? What would happen if there are two NSFetchedResultsController instances using the exact same cacheName? Does that matter? Is that some kind of singleton stuff? Thinking about Core Animation, there's also this strange animationID parameter, but setting it to the exact same thing for dozens of simultaneous animations doesn't hurt the animations at all. So I guess it's probably the same thing here...or not?

    Read the article

  • How to synchronize static method in java.

    - by Summer_More_More_Tea
    Hi there: I come up with this question when implementing singleton pattern in Java. Even though the example listed blow is not my real code, yet very similar to the original one. public class ConnectionFactory{ private static ConnectionFactory instance; public static synchronized ConnectionFactory getInstance(){ if( instance == null ){ instance = new ConnectionFactory(); } return instance; } private ConnectionFactory(){ // private constructor implementation } } Because I'm not quite sure about the behavior of a static synchronized method, I get some suggestion from google -- do not have (or as less as possible) multiple static synchronized methods in the same class. I guess when implementing static synchronized method, a lock belongs to Class object is used so that multiple static synchronized methods may degrade performance of the system. Am I right? or JVM use other mechanism to implement static synchronized method? What's the best practice if I have to implement multiple static synchronized methods in a class? Thank you all! Kind regards!

    Read the article

  • Javascript: variable scope & the evils of globals

    - by Nick
    I'm trying to be good, I really am, but I can't see how to do it :) Any advice on how to not use a global here would be greatly appreciated. Let's call the global G. Function A Builds G by AJAX Function B Uses G Function C Calls B Called by numerous event handlers attached to DOM elements (type 1) Function D Calls B Called by numerous event handlers attached to DOM elements (type 2) I can't see how I can get around using a global here. The DOM elements (types 1 & 2) are created in other functions (E&F) which are unconnected with A. I don't want to add G to each event handler (because it's large and there's lots of these event handlers), and doing so would require the same kind of solution as I'm seeking here (i.e., getting G to E&F). The global G, BTW, is an array that is necessary to build other elements as they, in turn, are built by AJAX. I'm not convinced that a singleton is real solution, either. Thanks.

    Read the article

  • How to configure Spring-DM OSGi service for new instance per call?

    - by Bhav
    I'm starting to delve into using Spring DM and OSGi services in an RCP application. I've created a service which is used by another bundle in the RCP application. It does a lookup of the service via calls to getBundleContext().getServiceReference() using the explicit bundle names and service class names. I'm not using DI anywhere yet. The issue I'm running into is that the service that is returned in the requesting bundle is a singleton. At times I notice a threading issue since it is a "stateful" service. How do I configure the application to get back a new service instance with each call? Here is my spring xml file contents which registers the service: <bean id="myServBean" class="com.xyz.ClassImpl"/> <osgi:service ref="myServBean" class="com.xyz.Class"/>

    Read the article

  • How to trigger code on two different servers in a WAS cluster?

    - by Dean J
    I have an administrative page in a web application that resets the cache, but it only resets the cache on the current JVM. The web application is deployed as a cluster to two WAS servers. Any way that I can elegantly have the "clear cache" button on each server trigger the method on both JVMs? Edit: The original developer just wrote a singleton holding a HashMap to be the cache in question. Lightweight and (previously) worked just fine for the requirements. It caches content pulled from six or seven web services for specified amounts of time. Edit: The entire application in question is three pages, so the elegant solution might well be the lightest solution.

    Read the article

  • Eclipse Plugin: Enablement of an Action based on the current selection - before the

    - by Itay
    Here's my problem: I am using the org.eclipse.ui.popupMenus extension point for adding a sub-menu whose Action that is bounded to the following class: public class MyAction implements IObjectActionDelegate { private Logic logic = Logic.getInstance(); // Singleton public void setActivePart(IAction a, IWorkbenchPart targetPart) { // Nothing here } public void run(IAction a) { // Do something... } public void selectionChanged(IAction a, ISelection s) { a.setEnabled(logic.isEnabled(s)); } } This action is working correctly in most cases (including the call a.setEnabled() in selectionChanged()). My problem at the very first time my action is being invoked. The selectionChanged method is called only after the menu item has been displayed (and not when the user has made the selection) which means that the call to a.setEnabled() will have no affect. Any ideas on how to make my action receive selectionChanged() notifications even before the fist time it is being invoked?

    Read the article

  • Castle Windsor Weak Typed Factory

    - by JeffN825
    In a very very limited number of scenarios, I need to go from an unknown Type (at compile time) to an instance of the object registered for that type. For the most part, I use typed factories and I know the type I want to resolve at compile time...so I inject a Func<IMyType> into a constructor ...but in these limited number of scenarios, in order to avoid a direct call to the container (and thus having to reference Windsor from the library, which is an anti-pattern I'd like to avoid), I need to inject a Func<Type,object>...which I want to internally container.Resolve(type) for the Type parameter of the Func. Does anyone have some suggestions on the easiest/most straightforward way of setting this up? I tried the following, but with this setup, I end up bypassing the regular TypedFactoryFacility altogether which is definitely not what I want: Kernel.Register(Component.For(typeof (Func<Type, object>)).LifeStyle.Singleton.UsingFactoryMethod( (kernel, componentModel, creationContext) => kernel.Resolve(/* not sure what to put here... */))); Thanks in advance for any assistance.

    Read the article

  • Open generic interface types of open implementation don't equal interface type?

    - by George Mauer
    Here's a test that should, in my opinion be passing but is not. [TestMethod] public void can_get_open_generic_interface_off_of_implementor() { typeof(OpenGenericWithOpenService<>).GetInterfaces().First() .ShouldEqual(typeof(IGenericService<>)); } public interface IGenericService<T> { } public class OpenGenericWithOpenService<T> : IGenericService<T> { } Why does this not pass? Given Type t = typeof(OpenGenericWithOpenService<>) how do I get typeof(IGenericService<)? I'm generally curious, but if you're wondering what I'm doing, I'm writing a Structuremap convention that forwards all interfaces implemented by a class to the implementation (as a singleton).

    Read the article

  • Covariant return types in Java enums

    - by Kelvin Chung
    As mentioned in another question on this site, something like this is not legal: public enum MyEnum { FOO { public Integer doSomething() { return (Integer) super.doSomething(); } }, BAR { public String doSomething() { return (String) super.doSomething(); } }; public Object doSomething(); } This is due to covariant return types apparently not working on enum constants (again breaking the illusion that enum constants are singleton subclasses of the enum type...) So, how about we add a bit of generics: is this legal? public enum MyEnum2 { FOO { public Class<Integer> doSomething() { return Integer.class; } }, BAR { public Class<String> doSomething() { return String.class; } }; public Class<?> doSomething(); } Here, all three return Class objects, yet the individual constants are "more specific" than the enum type as a whole...

    Read the article

  • "Reloading" Bindings in Ninject2?

    - by Michael Stum
    I'm using Ninject2 for DI and I have a Module that loads data from a config file. I wonder if there is a way to tell the Kernel or the Module to reload the config? (I can trigger that through code if needed) What worries me is the lifetime of existing objects. Say I have ITest bound to TestImpl1 in Singleton Scope and I change the config to bind ITest to TestImpl2 instead. All new requests should get TestImpl2, but the classes that already requested TestImpl1 before obviously keep it. However, what if all users of TestImpl1 are gone - will TestImpl1 be properly garbage collected and disposed in case it implements IDisposable? Or will it just be orphaned? Do I have to loop through each type and call Unbind/Bind on it? Or can I just unload the entire Module and reload it while still managing any existing object?

    Read the article

  • proper way of setting an attribute in Doctrine?

    - by ajsie
    in some tutorials they tell you to set up an attribute like this: $manager = Doctrine_Manager::getInstance(); Doctrine_Manager::getInstance()->setAttribute( Doctrine::ATTR_AUTO_ACCESSOR_OVERRIDE, true); and in the documentation it shows you this: $manager = Doctrine_Manager::getInstance(); $manager->setAttribute( Doctrine::ATTR_AUTO_ACCESSOR_OVERRIDE, true); i wonder which one i should use? isn't it the latter one? cause how can you set an attribute to a singleton class in the first one? isn't the second one more correct?

    Read the article

  • what is main focus for a developer when coding?

    - by ajsie
    i read a lot of books about how to code right and usually the are talking about all these techniques from a point of view i can't understand. eg. lets consider the singleton pattern. i'm restricting so the class can only be instantiated once. but since it's only me creating the application, if i know that the class only should be instantiated once, then why would i create it a second time? i feel like missing the big picture. what is my main goal when coding an application? how should i think? thanks

    Read the article

  • How to deal with multiple Facebook requests simultaneously

    - by Peter Warbo
    I'm using the Facebook SDK for my app. I have created a singleton class FacebookHelper to deal with all Facebook related logic. Whenever I make a Facebook request (i.e download friends) I set an enum i.e FacebookRequestDownloadFriends so that FacebookHelper knows how to handle errors and success for that request (since handling can be different between the different requests) This solution has worked out fine until now, because now I'm doing 2 Facebook Requests at the same time so when I set the enum for the first request i.e FacebookRequestDownloadFriends and then it will be overwritten just shortly with another request FacebookRequestDownloadEvents, so there will be confusion obviously. How can I deal with this issue without having to refactor too much code?

    Read the article

  • JFileChooser returns incorrect path in OS X (folders only mode)

    - by Virat Kadaru
    I have a problem in java swing where the user has to select a folder, so I am using the code below. JFileChooser fc = new JFileChooser(); fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); if(fc.showDialog(singleton, SELECT) == JFileChooser.APPROVE_OPTION) { File folder = fc.getSelectedFile(); String path = folder.getPath() + File.separatorChar + MYAPPFOLDER; } Now there are 2 ways a user may select the folder Navigate to the folder and select the folder Navigate to the folder, go into the folder, and click select Both ways work fine on windows but on OS X, I get If I do 1 : path = Users/<username>/Desktop/MYAPPFOLDER If I do 2 : path = Users/<username>/Desktop/Desktop/MYAPPFOLDER How do I avoid this 2nd case? Thanks in advance.

    Read the article

  • Statically Init a derived class

    - by AC
    With c++, Is there a way to get a derived class to inherit its own static initializer? I am trying to do something like the following: class Base { public: class StaticInit { public: virtual StaticInit() =0; }; }; class Derived: public Base { public: virtual StaticInit::StaticInit() { //do something with the derived class } static StaticInit init; } static Derived::StaticInit init; it would also be nice if I didn't have to define the init var in each derived class. I am currently redefining the StaticInit internal class in each derived class but it seems redundant. Each derived class is a singleton, and I need the instance to be stored in a lookup table at program startup.

    Read the article

  • What is the definition of a Service object ?

    - by Maskime
    I've been working a lot with PHP. But recently i was sent on a work wich use Java. In PHP i used to do a lot of Singleton object but this pattern has not the same signification in Java that it has in PHP. So i wanted to go for an utility class (a class with static method) but my chief doesn't like this kind of classes and ask me to go for services object. So my guess was that a service object is just a class with a constructor that implement some public methods... Am i right ?

    Read the article

< Previous Page | 19 20 21 22 23 24 25 26 27 28 29 30  | Next Page >