Forum Discussion

fb36's avatar
fb36
New Contributor
16 years ago

How to pass java object to load test threads?

I am trying to create a load test.
I have a script code that creates a socket connection object (non-soap).
I want that code to run only once (not re-run for each thread)
and all threads to use that same object to send messages to the test system.

So if I put my script code into "Setup script" window of the load test then
it will run only once when the load test started?

Also how to pass my java connection object to threads?
I tried using context.setProperty("connectionObj")/context.getProperty("connectionObj")
to pass but it does not seem to be working.

1 Reply

  • Hi
    You want to have a singleton in  pattern word.
    One way is to put your script in  a jar in the directory ext
    Your class should be something like this in a multi-threading environment :

    public class Singleton {


      private Singleton() {
        }

        public static Singleton getInstance() {
            if (null == instance) {
                synchronized(objetSynchrone__) {
                    if (null == instance) {
                        instance = new Singleton();
                    }
                }
            }
            return instance;
        }


     


        private static Singleton instance;

        private static Object objetSynchrone__;
    }