All things Jythonic 26.4.2005

April 2005
MoTuWeThFrSaSu
     1 2 3
4 5 6 7 8 910
11121314151617
18192021222324
252627282930 
Feb
2005
 May
2005

A blog tracking jython developments

XML-Image Syndication

XML-Image Comment Feed

Letterimage Contact me

2005-04-26

PushToTest - Free open-source software test automation solutions - Writing Threaded Applications in Jython

Here is a quick tutorial on writing thread safe jython scripts. The author implements thread safe examples using both Python and Java methods. Here is the article's conclusion

Based on my experience writing threaded applications in Jython, using Java Threads and the Runnable interface is the best practice. The following Jython script implements the best practice for building threaded applications in Jython:

from java.lang import Thread, Runnable
import synchronize

  class myclass( Runnable ):
    def __init__( self, myparam ):
      self.storeit = myparam

    def setMyparam( self, myparam ):
      self.storeit = myparam
    setMyparam=synchronize.make_synchronized( setMyparam )

    def printMyparam( self ):
      print "myclass: myparam =",self.storeit
    printMyparam=synchronize.make_synchronized( printMyparam )

    def run( self ):
      for self.i in range(5):
        self.printMyparam()

  count = 2

  a = myclass()
  a.setMyparam( "frank" )

  t = Thread( a, "MyThread %d" % count )
  t.start()
posted at 22:05:52    #
Creative Commons License
This work is licensed under a Creative Commons License.