Initialization of object once per thread

Darren Ball <[email protected]> Wed, 15 Apr 2015 11:05:55 -0400
Newsgroups gmane.comp.java.grinder.devel
Message-ID <CA+YPNhfcLfJAePO7k2VcPJQZZShCWGinCrVtnhKoxwnjuEAJ3w@mail.gmail.com>
--===============5280481113527008439==
Content-Type: multipart/alternative; boundary=001a1140a26a4e090c0513c4b0c9

--001a1140a26a4e090c0513c4b0c9
Content-Type: text/plain; charset=UTF-8

Hi All,

I recently found the following example online:

If you want one instance for all worker threads in a process, call it
from the top level of your script.


from mypackage import MyTest

myTest = MyTest()
myTest.init()

class TestRunner:
def __call__(self):
# use myTest

I have this exact code with onle the MyTest object being the
differentiator, and in the call I get a null pointer exception.


from net.grinder.script import Test
from net.grinder.script.Grinder import grinder
from com.myapp.api.controllers.perf.app import CreateAppPerf

createAppPerf = CreateAppPerf()
createAppPerf.initialize()

createAppTest = Test(1, "Create APP 1 Table 100 Fields")
createAppTest.record(createAppPerf.createApp)

class TestRunner:
    def __call__(self):
        createAppPerf.createApp(1,100)



Moving the createAppPerf.initialize() to the __init__ method works, but
this is not what I would like.  I would to initialize only once.

Any suggestions as how to do this so that createAppPerf is not null in
__call__?


Thanks,
Darren

--001a1140a26a4e090c0513c4b0c9
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">Hi All,<br><br>I recently found the following example onli=
ne:<br><br><blockquote style=3D"margin:0px 0px 0px 40px;border:none;padding=
:0px">If you want one instance for all worker threads in a process, call it=
<br>from the top level of your script.</blockquote><br><blockquote style=3D=
"margin:0px 0px 0px 40px;border:none;padding:0px">from mypackage import MyT=
est<br><br>myTest =3D MyTest()<br>myTest.init()<br><br>class TestRunner:<br=
>def __call__(self):<br># use myTest<br><br></blockquote>I have this exact =
code with onle the MyTest object being the differentiator, and in the call =
I get a null pointer exception.<div><br></div><div><br><div><div><div>from =
net.grinder.script import Test</div><div>from net.grinder.script.Grinder im=
port grinder</div><div>from com.myapp.api.controllers.perf.app import Creat=
eAppPerf</div><div><br></div><div>createAppPerf =3D CreateAppPerf()</div><d=
iv>createAppPerf.initialize()</div><div><br></div><div>createAppTest =3D Te=
st(1, &quot;Create APP 1 Table 100 Fields&quot;)</div><div>createAppTest.re=
cord(createAppPerf.createApp)</div><div><br></div><div>class TestRunner:</d=
iv><div>=C2=A0 =C2=A0 def __call__(self):</div><div>=C2=A0 =C2=A0 =C2=A0 =
=C2=A0 createAppPerf.createApp(1,100)</div></div></div></div><div><br></div=
><div><br></div><div><br></div><div>Moving the createAppPerf.initialize() t=
o the __init__ method works, but this is not what I would like.=C2=A0 I wou=
ld to initialize only once.</div><div><br></div><div>Any suggestions as how=
 to do this so that createAppPerf is not null in __call__?</div><div><br></=
div><div><br></div><div>Thanks,<br>Darren</div></div>

--001a1140a26a4e090c0513c4b0c9--


--===============5280481113527008439==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

------------------------------------------------------------------------------
BPM Camp - Free Virtual Workshop May 6th at 10am PDT/1PM EDT
Develop your own process in accordance with the BPMN 2 standard
Learn Process modeling best practices with Bonita BPM through live exercises
http://www.bonitasoft.com/be-part-of-it/events/bpm-camp-virtual- event?utm_
source=Sourceforge_BPM_Camp_5_6_15&utm_medium=email&utm_campaign=VA_SF
--===============5280481113527008439==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

_______________________________________________
Grinder-development mailing list
Grinder-development-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org
https://lists.sourceforge.net/lists/listinfo/grinder-development

--===============5280481113527008439==--