Multiple singletons

Hi,
I'm hoping someone can help me out with this bit of code as I'm not that experienced with Java and can't work out what I should be doing.
I'm trying to alter a facial recognition library called faint as it currently has a hardcoded path for storing it's database and other information. It's main class is a singleton and from what I've read it isn't easy to pass parameters to them. It'd be nice if I could have an instance per database path, rather than a single instance per jvm. I don't know how easy this is and would really appreciate some help :)
Here's a sample of the code (GPL).
public class MainController {
     private static MainController uniqueInstance = null;
     private static final String PLUGIN_CONFIG_FILE = "Modules.conf";
     static final String PLUGIN_SUFFIX = ".data";
     private static final String APPLICATION_DIRECTORY = ".faint";
     // Controllers for Detection and Recognition
     private HotSpotController<IDetectionPlugin,IDetectionFilter> detectionHotSpot;
     private HotSpotController<IRecognitionPlugin, IRecognitionFilter> recognitionHotSpot;
     // Minimum scan window size in percent of original min(width, height)
     private int scanWindowSize = 15;
     // Dataholding
     private FaceDatabase faceDB;
     private File dataDir;
    // Image cache
     private BufferedImageCache bufferedImageCache = new BufferedImageCache();
      * Static method providing an instance of this class. There can only be
      * one instance at runtime, see Singleton Pattern for more info.
      * @return The only instance of MainController.
     public static MainController getInstance(){
          if (uniqueInstance == null)
               uniqueInstance = new MainController();
          return uniqueInstance;
      * Private Constructor called by the getInstance() method.
     private MainController(){
          uniqueInstance = this;
          dataDir = new File(System.getProperty("user.home") + File.separator + APPLICATION_DIRECTORY );
          dataDir.mkdirs();As you can see, I'd like to be able to pass a parameter to set the dataDir. In a perfect world I'd like only one instance per unique database path.
Any ideas?
Thanks very much for any help.

@tjacobs01, that sounds great but I can't quite figure out how to do it. But it sounds like exactly what I'm after.
@jverd, good point. From what I can tell it's just to make it thread safe with the database activity. I'm hoping to keep that by still only having one instance per database, instead of being stuck with a single database.
@tschodt, that sounds great but I haven't a clue how to do that :)
@manb, no clone method unfortunately.
If it's any help, here's a link to the full source: [http://faint.svn.sourceforge.net/viewvc/faint/trunk/src/de/offis/faint/controller/MainController.java?revision=2&view=markup|http://faint.svn.sourceforge.net/viewvc/faint/trunk/src/de/offis/faint/controller/MainController.java?revision=2&view=markup]
Thanks for the pointers so far, I am trying to work this out still and all the advice is helpful :)

Similar Messages

  • Singletons across multiple JVMs

    I have an EJB application container which is spread across multiple JVMs(something like a clustered EJB container). I am using a Singleton class to hand out 'running serial numbers'. Therefore there is a Singleton class per JVM(which is not very clean but i chose this path in the absence of anything better). Each singleton comes up when it is first invoked within a JVM and reads a starting running number and a pool of numbers from the database. This way multiple Singletons will not step on each other when doling out the serial numbers and there is no need to go back to the database for every request to the 'running serial number'.
    Is there some way to do some of the initialization within these Singleton's just ONCE across the multiple instances of the JVM ie. a real Singleton across multiple JVMs?
    Thanks
    Ramdas

    Pranav,
    thanks for your suggestions.
    the idea of using a Session bean to access a serialized object was one of my design options when i first implemented this, but then i decided against it because of the overhead of having to make an RMI call for every request to the 'running serial number'. The application being written is for a performance benchmark, and the request to the number being done at least once for every transaction, I chose to use Singletons.
    It is a clustered EJB container(not like most conatiners), in the sense that a single container is spread across multiple JVMs.
    Now if your application is getting clustured
    then you have a problem, in that what you can do is
    what object you have made put it in JNDI context and
    everytime you want to edit it pull it out edit and set
    it back. This will act a your singleton object in
    clustured environment accross JVM'sI did not fully understand the second part of your solution????
    Ramdas

  • Singleton Classes in Weblogic cluster

    Hi
    Our application is having singleton classes which we refresh programatically ;though very rarely. We need to move our application into a weblogic cluster. The sigleton class refresh also needs to reflect across the servers :
    I could see the SingletonService API here http://download.oracle.com/docs/cd/E12839_01/apirefs.1111/e13941/weblogic/cluster/singleton/SingletonService.html. This contain an activate() and deactivate() .Can we call this activate() method to refresh the singleton object whenever there is a refresh required ? Can we define multiple singleton service classes in the cluster ?
    Thanks
    Suneesh

    I've same issue with singleton service...
    1) I’ve created a cluster MyCluster with Man1 & Man2 managed instances.
    2) I’ve created singleton.jar out of TestCache.java, which is a singleton cache and have deployed it to the MyCluster.
    3) I’ve created man.jar out of StartupClassMan.java, which is a startup class and have deployed it to the MyCluster. And I’ve specified this as startup class for the whole MyCluster.
    4) For MyCluster, I’ve specified com.mytest.TestCache.class as singleton service with preferred server as Man1 with migratable to Man2.
    5) I run Man1, startup class StartupClassMan is invoked and it gets reference to TestCache, populates the cache & prints size as 1.
    6) Now when I run Man2, startup class StartupClassMan is invoked and it get references to TestCache & populates the cache & prints size as 1 only.
    For some reason, TestCache is not considered as true singleton. If it is true singleton, running Man2 should have printed size 2 as Man1 has already put one entry into the cache.
    And I also don't see activate & deactivate method being called when I run Man1 or Man2 servers. Any help on this is really appreciated.
    package com.mytest;
    import java.util.Map;
    import java.util.HashMap;
    public class TestCache implements weblogic.cluster.singleton.SingletonService
    private static TestCache testCache = new TestCache();
    private Map<String, String> mapCache = new HashMap<String, String>();
    private TestCache() {}
    public void activate() {
    System.out.println("TestCache activate called");
    public void deactivate() {
    System.out.println("TestCache deactivate called");
    public static TestCache getTestCache() {
    return testCache;
    public void put(String key, String value) {
    mapCache.put(key, value);
    public String get(String key) {
    return mapCache.get(key);
    public void remove(String key) {
    mapCache.remove(key);
    public int size() {
    return mapCache.size();
    package com.mytest;
    public class StartupClassMan
    public static void main(String args[]) {
    System.out.println("StartupClassMan loaded");
    TestCache testCache = TestCache.getTestCache();
    testCache.put("Man1","Man1");
    System.out.println("size: "+testCache.size());
    }

  • Singleton or servletcontext??

    Hi,
    For my web app I have a class, NoticeManager, that maintains a hashMap of users and notices. The hashMap key is a unique user id and the object is a Vector of Notice objects. I want all clients to be able to use the same noticeManager instance and all notice objects must have a unique ID.
    I'm not sure how to implement this correctly - my current thinking is
    - Make NoticeManager a singleton
    - Make the noticeManager instance available to all clients using the servletContext getAttribute and setAttribute methods.
    - implement the uniqueID as a class variable that gets implemented using a synchronized method
    Any thoughts/suggestions would be much appreciated
    regards
    Richard

    Implementing a singleton in J2EE is difficult (probably impossible) to do in a manner consistent with the standard in practice. A Singleton is only a unique to a single JVM. However the clustering requirement of a scalable App Server typically bring with it multiple JVM's. This results in multiple Singletons. Now depending on your detailed requirements (for example your choice of a Singleton may be pragmatic rather than absolute) this may or may not cause a problem in practice.
    The Servlet Context offer an excellent alternative. However I think this issue is likely to be resolved (standardised) in latter versions of the J2EE standard. I would therefore hide this behind a ScopeHandler facade, that supports Application, Session, Request and Page Scopes. This will minimise the impact of likely future changes and provides an elegant interface.

  • Urgent - JVM API

    Hi,
    How can I find out programmatically, if an instance of my applet is already running in the JVM? Does the JVM expose any such API?
    The problem is as such. I have an applet that runs in a browser. The classes that if refers to are all singleton. Now if a user opens a new browser using File->New (ie new thread), then my singleton classes fail. Hence I wanted to query the JVM to know if an instance of the applet is already running. Is there a better solution to this problem other than disabling the browser menu bar.
    Thanx.

    1 instance of the applet running under one JVMPretty sure that isn't possible. I believe (asking on a gui board might confirm this) that different class loaders are used in at least one browser. That means multiple applets will have multiple singletons which will not know about each other.
    I don't see anyway to find out about other class loaders so one couldn't use that to find them.
    You could have the applet open a socket server. If a second applet runs it will try to connect and will fail so it would exit.

  • Why isn't there a simpler way to initialize a subclass with its super class

    Let me explain my doubt with an example...
    public class Parent {
    �    public String parent;
    public class Child extends Parent{
    �    public String child;
    I've an instance of Parent p. I want to construct Child c, with the data in p.
    The only way that is provided by Java language seems to be, having a constructor in Child like
    public class Child extends Parent{
    �    public String child;
    �    public Child(Parent p){
    �    �    parent = p.parent;
    �    }
    The problem with this is there is lot of redundant assignment code.
    What I don't understand is why there is not a simpler way of doing this when a subclass is after all super class data + some other data(excuse me for not looking at the bahavior part of it)
    I'm looking for something as simple as Child c = p, which I know is wrong and know the reasons too.
    Yes, we can wrap Child over Parent to do this, but it necessitates repeating all the methods in Parent.
    Why is the language writers didn't provide a simple way of doing this? I should be missing something here...I'm just searching for an explanation. May be I'm asking a dumb question, but this bugs me a lot...
    Regards,
    Kothapalli.

    To answer DrClap, I'm demanding it now :-). Let me
    not suggest something that Mr.Gosling didn't think of;
    he should be having some reasons in not providing it.Because it's essentially impossible in the general case. One of the reasons you may be extending a class is to add new invariants to the superclass.
    eg- extend java.awt.Rectangle by BoundedRectangle - extra invariant that none of its corner points may be less than 0 or more than 100 in any dimension. (The rectangle must be entirely contained in the area (0,0)-(100,100))
    What would happen if you try to create a BoundedRectangle from a rectangle representing (50,50)-(150,150)? Complete invariant breakdown, with no generic way to handle it, or even recognise it.
    Actually, BIJ and sgabie are asking for it. Provide an
    automatic copy constructor. Every object should have
    an implicit copy constructor defined. From any
    subclass, I should be able to invoke
    super(parentClass). From the subclass, we can invoke
    super(parentClass) first and then go on to initialize the
    subclass data.
    I really don't know the implementation issues of this,
    but what I'm looking for is something like this. I'm just
    curious to know the implementation issues.Implementation issue #1: Classes that should not, under any circumstane, be copied.
    * eg 1- Singleton objects. If there's an automatic copy constructor, then multiple singletons can be created, making them essentially useless. This by extension kills the Typesafe Enum pattern also.
    * eg 2- Objects with extra information, such as java.sql.Connection - if you copied this, would the copy be using the same socket connection, or would another connection be required? What happens if opening another connection, and the JDBC driver requires the password to be entered for every new connection? If the wrong password is entered, what happens to the newly creating connection?
    Implementation issue #2: Copying implementation?
    * Already mentioned by RPWithey. The only guaranteed way to perform the copy would be with a shallow copy, which may end up breaking things.
    Why can't you write the copy constructor yourself? If it's a special case, it only has to be done once. If it's a recurring case, you could write a code generation tool to write them for you, along with most of the rest of the class.

  • How to create Multiple instances of This SingleTon class

    import java.io.*;
    import java.util.Properties;
    import java.net.URLEncoder;
    public class ddd
              // declaring variables
              static private ddd _instance;
              String connectIP;
              int connectPort;
              String systemID;
              String password;
         String systemType;
              // Constructor with arguments
              private ddd()
              globalInit();
         // method returning the ddd instance.
              public static      synchronized ddd getInstance()
              if (_instance == null)
                        _instance = new ddd();
              return _instance;
              // Global initialisations
              public void globalInit()
              systemID ="XXXXX" ;
              password ="XXXXX";
              systemType ="Null";
              public static void main(String[] args)
                   ddd sb;
                   sb = ddd.getInstance();
                   System.out.println(ddd.getInstance());

    Don't cross-post:
    http://forum.java.sun.com/thread.jsp?thread=547911&forum=54&message=2669925
    http://forum.java.sun.com/thread.jsp?thread=547912&forum=31&message=2669928
    Sorry, I can't help but think that this is one of the more foolish questions I've read in a while.
    The pattern Singleton means "I only want one of these in a single JVM". If you want multiple instances, or even a restricted number of instances, then rewrite the class (something like this):
    public class LimitedEdition
        public static final int MAX_EDITIONS = 3;
        private static int numEditions;
        public static void main(String [] args)
            try
                if (args.length > 0)
                    int numEditions = Integer.valueOf(args[0]).intValue();
                    for (int j = 0; j < numEditions; ++j)
                        LimitedEdition limited = new LimitedEdition();
                        System.out.println(limited);
            catch (Exception e)
                e.printStackTrace();
        public LimitedEdition() throws InstantiationException
            if (numEditions < MAX_EDITIONS)
                ++numEditions;
            else
                throw new InstantiationException("Only " + MAX_EDITIONS + " instances allowed");
        public String toString()
            return "[ instance # " + numEditions + "]";

  • Multiple instances of a Singleton-Object by updaterule ?

    Hi folks,
    I'm trying to load > 1 Mio. records from an ODS into another InfoProvider. Every record gets some keyfigures out of a very very expensive table-join.
    I tried creating this join in an ABAP-Singleton-Object to reduce uploading-time.
    This object holds a private-static attribute 'instance' as a reference to a instance of the object and a public-static 'getInstance()'-method, which returns the 'instance'-value. This method is standard-Singleton-like designed.
    Then I created a process-chain with:
    - an ABAP-process, which calls the 'getInstance()'-method
      of this Singleton.
      At the first pass this method calls the constructor and
      after that a private method, which creates the join and
      holds the result in an internal table.
      So the constructor is empty.
    - after that the data should be transfered (by an Info-
      Package) from the ODS to the other InfoProvider. In some
      fields of the update-rule and in the startroutine of
      the rule the 'getInstance()'-method of the Singleton is
      been called and by this reference to the only (so I
      thought) instance some other methods should return a
      calculated value out of the join.
    So theory .... the startroutine is been called for multiple datapackages (no problem) --- but for every package in the startroutine the 'getInstance()'-method calls the constructor, so I get multiple instances of a Singleton.
    The time-gap between the package-calls is > 10 secs., so the static-attribute should been set immediately in the first pass of the 'getInstance()', since the constructor is empty.
        Any ideas ???
        Bye Ralf

    -/-

  • Ensuring one singleton instance for multiple JVMs

    i am creating a singleton object. But singleton is per JVM (or rather per classloader) right? But i want to ensure only one instance of my singleton even if there are multiple jvms....how can i achieve that?

    javanewbie80 wrote:
    i am creating a singleton object. But singleton is per JVM (or rather per classloader) right? But i want to ensure only one instance of my singleton even if there are multiple jvms....how can i achieve that?You can't.
    Given computers A and B. Neither have any connectivity by any means to the other.
    Install the application on both and run it. There is no way for either application to know about the other thus only one of the following is possible.
    1. Both applications run and create an instance. Then there are two instances and thus it fails.
    2 The application refuses to run. Then there are none and thus it fails
    Other solutions are possible given that some reasonable requirements based on actual business driven needs are presented.

  • Accessing Singleton from multiple deployed applications

    Can this be done? I would like to be able to access a hashtable that is stored as a static member of a class common to two (or more) Applications.
    Is it possible to deploy two ears so that they share a VM? I tried it out thinking it might work this way by default but it does not seem to.
    I have built a caching mechanism that works across a cluster by utilizing JMS, with an MDB. I was hoping to be able to deploy the MDB in its own EAR so I could easily make use of it from any application.
    Thanks in advance
    ken clark

    "Ken Clark" <[email protected]> wrote in message news:3242170.1096548750958.JavaMail.root@jserv5...
    No, I meant the BEA Split Development Environment, wherein you set up all your source code pretty much like the compiled code willbe put into the EAR, and then use some BEA provided ant tags to do the build.
    >
    What I am confused about is how I could add an EJB jar to the EAR in a fairly low-impact way, such that the existing build scriptwould work. Should I simply add the deployable jar in the "Ear directory" and it will be taken care of?
    >
    IMHO split directory is suitable for very simple applications and
    it's hardly applicable to real-life apps.
    The resulting deployment structure (EAR) is indeed simple, but
    the ways all parts come together normally are more complex then
    just a set of peacefully laying files. For instance, one may have code
    generation, source files can have build-time parameters, 3rdparty libs
    can be coming from dynamic locations e.t.c. split dir can not cover
    such and many other cases. It makes it unusable for real life.
    So, ANT is your old good friend.
    Regards,
    Slava Imeshev

  • Can not access the Instance Data of a Singleton class from MBean

    I am working against the deadline and i am sweating now. From past few days i have been working on a problem and now its the time to shout out.
    I have an application (let's call it "APP") and i have a "PerformanceStatistics" MBean written for APP. I also have a Singleton Data class (let's call it "SDATA") which provides some data for the MBean to access and calculate some application runtime stuff. Thus during the application startup and then in the application lifecysle, i will be adding data to the SDATA instance.So, this SDATA instance always has the data.
    Now, the problem is that i am not able to access any of the data or data structures from the PerformanceStatistics MBean. if i check the data structures when i am adding the data, all the structures contains data. But when i call this singleton instance from the MBean, am kind of having the empty data.
    Can anyone explain or have hints on what's happening ? Any help will be appreciated.
    I tried all sorts of DATA class being final and all methods being synchronized, static, ect.,, just to make sure. But no luck till now.
    Another unfortunate thing is that, i some times get different "ServicePerformanceData " instances (i.e. when i print the ServicePerformanceData.getInstance() they are different at different times). Not sure whats happening. I am running this application in WebLogic server and using the JConsole.
    Please see the detailed problem at @ http://stackoverflow.com/questions/1151117/can-not-access-the-instance-data-of-a-singleton-class-from-mbean
    I see related problems but no real solutions. Appreciate if anyone can throw in ideas.
    http://www.velocityreviews.com/forums/t135852-rmi-singletons-and-multiple-classloaders-in-weblogic.html
    http://www.theserverside.com/discussions/thread.tss?thread_id=12194
    http://www.jguru.com/faq/view.jsp?EID=1051835
    Thanks,
    Krishna

    I am working against the deadline and i am sweating now. From past few days i have been working on a problem and now its the time to shout out.
    I have an application (let's call it "APP") and i have a "PerformanceStatistics" MBean written for APP. I also have a Singleton Data class (let's call it "SDATA") which provides some data for the MBean to access and calculate some application runtime stuff. Thus during the application startup and then in the application lifecysle, i will be adding data to the SDATA instance.So, this SDATA instance always has the data.
    Now, the problem is that i am not able to access any of the data or data structures from the PerformanceStatistics MBean. if i check the data structures when i am adding the data, all the structures contains data. But when i call this singleton instance from the MBean, am kind of having the empty data.
    Can anyone explain or have hints on what's happening ? Any help will be appreciated.
    I tried all sorts of DATA class being final and all methods being synchronized, static, ect.,, just to make sure. But no luck till now.
    Another unfortunate thing is that, i some times get different "ServicePerformanceData " instances (i.e. when i print the ServicePerformanceData.getInstance() they are different at different times). Not sure whats happening. I am running this application in WebLogic server and using the JConsole.
    Please see the detailed problem at @ http://stackoverflow.com/questions/1151117/can-not-access-the-instance-data-of-a-singleton-class-from-mbean
    I see related problems but no real solutions. Appreciate if anyone can throw in ideas.
    http://www.velocityreviews.com/forums/t135852-rmi-singletons-and-multiple-classloaders-in-weblogic.html
    http://www.theserverside.com/discussions/thread.tss?thread_id=12194
    http://www.jguru.com/faq/view.jsp?EID=1051835
    Thanks,
    Krishna

  • How do I use multiple classes to access the same object?

    This should be staightforward. I have and object and I have multiple GUIs which operate on the same object. Do all the classes creating the GUIs need to be inner classes of the data class? I hope this question makes sense.
    Thanks,
    Mike

    public final class SingletonClass {
    private static SingletonClass instance;
    private int lastIndex = 10;
    public final static SingletonClass getInstance()
    if (instance == null) instance = new SingletoClass();
    return instance;
    public int getLastIndex() {
    return lastIndex;
    }1) This won't work since one could create a new SingletonClass. You need to add a private constructor. Also, because the constructor is private the class doesn't have to be final.
    2) Your design isn't thread-safe. You need to synchronize the access to the shared variable instance.
    public class SingletonClass {
        private static SingletonClass instance;
        private static Object mutex = new Object( );
        private int lastIndex = 10;
        private SingletonClass() { }
        public static SingletonClass getInstance() {
            synchronized (mutex) {
                if (instance == null) {
                    instance = new SingletonClass();
            return instance;
        public int getLastIndex() {
            return lastIndex;
    }if you are going to create an instance of SingletonClass anyway then I suggest you do it when the class is loaded. This way you don't need synchronization.
    public class SingletonClass {
        private static SingletonClass instance=new SingletonClass();
        private int lastIndex = 10;
        private SingletonClass() { }
        public static SingletonClass getInstance() {
            return instance;
        public int getLastIndex() {
            return lastIndex;
    }If you don't really need an object, then you could just make getLastIndex() and lastIndex static and not use the singleton pattern at all.
    public class SingletonClass {
        private static int lastIndex = 10;
        private SingletonClass() { }
        public static int getLastIndex() {
            return lastIndex;
    }- Marcus

  • How do you handle multiple at the same address?

    My wife just got an iMac. She is using the Birthday feature in Address Book and iCal to track our friends and family birthdays and anniversaries.
    Question:
    How do you track it when multiple people are at the same address? For instance, our friends are a family of four, but they all live at the same address. Do you need to make a separate Address Book card for each of them, even the 1 year old baby? Or can you track multiple people in a single card with custom fields?
    If you do need to make multiple cards, then how do you handle mailing lists? For instance, if I make separate cards for all four of them, how do I make sure I only send on Christmas card when I use my Mac to print labels?
    Thanks for any advice.

    This is really an issue that you're going to have to resolve yourself since Apple's address book isn't really built with this in mind - darn it. For me there are three scenarios. First, a singleton. No problem. Second a family for which all members share the same information - acquantences to whom I don't send birthday greetings. These get one card and I'll put in both (or all) their names in the first name field (as in Bob and Jean). If there are children, in the last name field I'll add 'and Ken' or 'and the kids'. Third, a family for which some fields are different - perhaps cell phone number, birthday, etc.
    For mailing purposes, I create a holiday group and put the people I'll be sending cards to into the group.

  • How to reference multiple instances of the same Java object from PL/SQL?

    Dear all,
    I'm experimenting with calling Java from PL/SQL.
    My simple attempts work, which is calling public static [java] methods through PL/SQL wrappers from SQL (and PL/SQL). (See my example code below).
    However it is the limitation of the public static methods that puzzels me.
    I would like to do the following:
    - from PL/SQL (in essence it needs to become a forms app) create one or more objects in the java realm
    - from PL/SQL alter properties of a java object
    - from PL/SQL call methods on a java object
    However I fail to see how I can create multiple instances of an object and reference one particular object in the java realm through public static methods.
    My current solution is the singleton pattern: of said java object I have only 1 copy, so I do not need to know a reference to it.
    I can just assume that there will only ever be 1 of said object.
    But I should be able to make more then 1 instance of an object.
    To make it more specific:
    - suppose I have the object car in the java realm
    - from PL/SQL I want to create a car in the java realm
    - from PL/SQL I need to give it license plates
    - I need to start the engine of a scpecific car
    However if I want more then 1 car then I need to be able to refrence them. How is this done?
    Somehow I need to be able to execute the following in PL/SQL:
    DECLARE
    vMyCar_Porsche CAR;
    vMyCar_Fiat CAR;
    BEGIN
    vMyCar_Porsche = new CAR();
    vMyCar_Fiat = new CAR();
    vMyCar_Porsche.setLicensePlates('FAST');
    vMyCar_Porsche.startEngine();
    vMyCar_Fiat.killEngine();
    END;
    Thanks in advance.
    Best Regards,
    Ruben
    My current example code is the following:
    JAVA:
    ===
    CREATE OR REPLACE AND RESOLVE JAVA SOURCE NAMED CODAROUL."RMG/BO/RMG_OBJECT" as package RMG.BO;
    public class RMG_OBJECT {
    private static RMG_OBJECT instance = new RMGOBJECT();
    private String rmgObjectNaam;
    private RMG_OBJECT(){
    this.rmgObjectNaam = "NonDetermined";
    public static String GET_RMGOBJECT_NAAM () {
    String toestand = null;
    if (_instance == null) {toestand = "DOES NOT EXIST";} else { toestand = "EXISTS";};
    System.out.println("instance : " + toestand);
    System.out.println("object name is : " + _instance.rmgObjectNaam);
    return _instance.rmgObjectNaam;
    public static Integer SET_RMGOBJECT_NAAM (String IN)
    try
    _instance.rmgObjectNaam = IN;
    return 1;
    catch (Exception e)//catch
    System.out.println("Other Exception: " + e.toString());
    e.printStackTrace();
    return 5;
    } //catch
    PL/SQL Wrapper:
    ==========
    CREATE OR REPLACE FUNCTION CODAROUL.SET_RMGOBJECT_NAAM(NAAM IN VARCHAR2) return NUMBER AS
    LANGUAGE JAVA NAME 'RMG.BO.RMG_OBJECT.SET_RMGOBJECT_NAAM (java.lang.String) return java.lang.Integer';
    Calling from SQL:
    ==========
    CALL dbms_java.set_output(2000);
    select CODAROUL.GET_RMGOBJECT_NAAM() from dual;
    Edited by: RubenS_BE on Apr 6, 2012 5:35 AM
    Edited by: 925945 on Apr 6, 2012 5:41 AM

    You can do this by manually creating a new iterator binding in your binding tab.
    So instead of dragging the VO directly to the page, go to the binding tab, add a new executable iterator binding, and point to that one from your ELs in the page itself.

  • How do i use classloaders to create singletons

    I have some code that correctly creates a singleton because the code runs within a clients vm , and there should only be instance of the class per user. But for testing purposes I would like to mimic two users, to do this they each require their own instance of the singleton. I have read that using custom classloaders there could be one instance of each singleton per classloader, but dont understand how to do this. Can someone give me an example

    As I understand it you are simulating what amounts to
    a number of instances running in separate JVMs
    (probably on different machines) by running multiple
    instances in the same JVM. The natural way to do this
    would be to start multiple threads, each representing
    the action of one of these clients. (To do it
    sequentially would be a very poor test, since you
    need to cope with multiple, simultaneous
    activities).Yes, correct
    >
    The use of ThreadLocal enables you to have a separate
    instance of the "singleton" class for each thread.
    Any calls to the getInstance() method in the class
    made within one of the threads will return the
    details of the user "logged in" on that thread.
    Ok,fine but Ive simplified the use case there are a number of singletons involved (most of which are not called directly by the test code but by each other) , all of these would have to be identified and modified.
    InheritableThreadLocal extends this by passing the
    same instance to any child threads formed in one of
    these threads after initially intanciating an
    instance in a Thread (quite possibly uneccessary).Not needed, (thanks for explaining it though)
    And you can, if you wish, leave this in in the
    production version providing you do the login in the
    root thread of the client JVM.
    We do not want to allow the client to do such things.
    This, I have to say, would be a vastly less messy
    solution (and a much milder distortion between test
    and production) than anything based on ClassLoaders
    could possibly provide. Using custom class loaders
    quickly gets very messy indeed.
    I was hoping that by having two threads, each defining their own instance of a classloader it would get round the singleton behaviour and this is the only problem I am trying to solve. Obviously this would not be desirable in production but if it solves my testing problem Ill be happy, whether or not this is possible I still cant ascertain.
    If you have existing code you aren't allowed to
    change, then the best solution is probabllly to run
    multiple JVMs, exactly as in the real live case.We are using junit and taking advantage of its reporting facilities,ant integration and so on. If I was to have two JVMs I would have to split my test into two coorporating tests that would have to run in parallel but as far as Junit was concerned were two seperate tests, I can see this causing problems with reporting and causing side effects on other tests if something failed. Im aware that I am not really writing 'unit' tests in the strict test but the Junit framework provides advantages over plain old java.

Maybe you are looking for

  • How do I make this code generate a new pro when the "NEXT" button is pushed

    How do I make this code generate a new set of problem when the "NEXT" Button is pushed * To change this template, choose Tools | Templates * and open the template in the editor. /* Figure out how to create a new set of problms * Type a list of specif

  • What are  the input parameters for Function Module

    Dear Experts, I want to generate a Sales Tax returns report,those fields are not available in my existing Datasources. For that i want to write a Generic Datasource with Function Module. audat bukrs vkorg vtweg spart aurat auart netwr mwsbp kschl zed

  • Showing as connected to the internet but can't get...

    Hi, This is my first post so apologies in advance if I'm using this incorrectly! I have BT Infinity and have had very few problems since getting it but for the last few days I have been unable to get online. I've called BT a few times and it is showi

  • Parameters in sub report can't be changed

    I have a main report and a drill through report - I can pass all my parameters no worries but when I try to change the parameter value in the second report it will not let me. It reverts to the parameters in the first report. I have another set of re

  • ITAB - look for duplicates

    I want to do something like this.... Let's say my ITAB has MATNR & DUP fields & let's say ITAB has entries like this... ITAB-MATNR      ITAB-DUP 123 123 345 456 if any of the MATNR's are repeated in ITAB I want to flag DUP for such repeated records s