Thanks for the clear and amazingly prompt reply, Charlie!
That got me going. At first I was troubled by seeing all of my new
threads labeled "Thread" in the log4j output (is this a bug?). I found
that by assigning my own names to the threads I could see each thread
executing as expected. I ended up with this:
t1 = Thread(target=JavaClassA.methodA, name='t1')
t2 = Thread(target=JavaClassB.methadB, name='t2')
t1.start()
t2.start()
t1.join()
t2.join()
Thanks again,
Ted
On Wed, Jul 8, 2009 at 6:46 PM, Charlie Groves<
charlie.groves@...> wrote:
> Hi Ted,
>
> On Wed, Jul 8, 2009 at 1:32 PM, Ted Larson
> Freeman<
freeman@...> wrote:
>> In my first attempt, using threads, "test.py" included code
>> like this:
>>
>> from threading import Thread
>> Thread(JavaClassA.methodA()).start()
>> Thread(JavaClassB.methodB()).start()
>
> Check out the docs for the Thread object:
>
http://docs.python.org/library/threading.html#thread-objects The
> first argument is the thread group, so you're setting the thread group
> for your threads with the results of methodA and methodB. Since
> you're calling methodA and methodB to create arguments for Thread,
> they're run in the main thread.
>
> What you want to do is set the target of the Thread to the function or
> method you want invoked on the new thread, and then call start. For
> example, the code below calls add on an ArrayList on a separate
> thread:
>
> Jython 2.5.0+ (trunk:6503:6505M, Jul 8 2009, 18:36:14)
> [Java HotSpot(TM) 64-Bit Server VM (Apple Inc.)] on java1.6.0_13
> Type "help", "copyright", "credits" or "license" for more information.
>>>> from threading import Thread
>>>> from java.util import ArrayList
>>>> l = ArrayList()
>>>> Thread(target=l.add, args=(5,)).start()
>>>> l
> [5]
>
> The args keyword arg is a tuple of positional arguments to pass to the
> target method.
>
> With your examples, you'd want to do
> Thread(target=JavaClassA.methodA).start() and
> Thread(target=JavaClassB.methodB).start().
>
> Hope this helps,
> Charlie
>
> ------------------------------------------------------------------------------
> Enter the BlackBerry Developer Challenge
> This is your chance to win up to $100,000 in prizes! For a limited time,
> vendors submitting new applications to BlackBerry App World(TM) will have
> the opportunity to enter the BlackBerry Developer Challenge. See full prize
> details at:
http://p.sf.net/sfu/Challenge> _______________________________________________
> Jython-users mailing list
>
Jython-users@...
>
https://lists.sourceforge.net/lists/listinfo/jython-users>
>
>
------------------------------------------------------------------------------
Enter the BlackBerry Developer Challenge
This is your chance to win up to $100,000 in prizes! For a limited time,
vendors submitting new applications to BlackBerry App World(TM) will have
the opportunity to enter the BlackBerry Developer Challenge. See full prize
details at:
http://p.sf.net/sfu/Challenge_______________________________________________
Jython-users mailing list
Jython-users@...
https://lists.sourceforge.net/lists/listinfo/jython-users