| 1 |
import threading |
| 2 |
import unittest |
| 3 |
import jpyutil |
| 4 |
|
| 5 |
jpyutil.init_jvm(jvm_maxmem='512M') |
| 6 |
import jpy |
| 7 |
|
| 8 |
|
| 9 |
class MyThread(threading.Thread): |
| 10 |
|
| 11 |
def __init__(self, value): |
| 12 |
threading.Thread.__init__(self) |
| 13 |
Integer = jpy.get_type('java.lang.Integer') |
| 14 |
self.intObj = Integer(value) |
| 15 |
|
| 16 |
def run(self): |
| 17 |
|
| 18 |
self.intValue = self.intObj.intValue() |
| 19 |
|
| 20 |
|
| 21 |
class TestMultipleThreads(unittest.TestCase): |
| 22 |
|
| 23 |
|
| 24 |
def test_multi_thread_access(self): |
| 25 |
|
| 26 |
t1 = MyThread(123) |
| 27 |
t2 = MyThread(234) |
| 28 |
t3 = MyThread(345) |
| 29 |
t4 = MyThread(456) |
| 30 |
|
| 31 |
t1.start() |
| 32 |
t2.start() |
| 33 |
t3.start() |
| 34 |
t4.start() |
| 35 |
|
| 36 |
t1.join() |
| 37 |
t2.join() |
| 38 |
t3.join() |
| 39 |
t4.join() |
| 40 |
|
| 41 |
self.assertEqual(123, t1.intValue) |
| 42 |
self.assertEqual(234, t2.intValue) |
| 43 |
self.assertEqual(345, t3.intValue) |
| 44 |
self.assertEqual(456, t4.intValue) |
| 45 |
|
| 46 |
|
| 47 |
if __name__ == '__main__': |
| 48 |
print('\nRunning ' + __file__) |
| 49 |
unittest.main() |