Date of registration: Jul 16th 2008
Location: Erlangen, Germany
Occupation: Software Developer
Hobbies: Jabaco, game theory, text-mining
|
|
Jabaco Source |
1 2 3 4 5 6 7 8 9 |
' Module: Main.jsrc Dim myWorkerClass As New WorkerClass() ' Create the Worker-Class (see below) Dim myWorkerThread As New Thread(myWorkerClass) ' Use the Worker-Class with the Worker-Thread Dim myTestThread As New Thread(New TestClass(myWorkerClass)) Public Sub main(ByJava args() As String) Call myWorkerThread.start() ' This Thread will change our shared resource in a loop Call myTestThread.start() ' ... and this will observe our shared resource End Sub |
|
|
Jabaco Source |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
' CLASS: WorkerClass.jsrc Implements java#lang#Runnable ' This Interface is necessary for usage with a Thread-Class Dim myItem As Long ' The shared resource that we will change and observe Public Property Get Item() As Long ' Public access for the shared resource Item = myItem End Property Public Sub run() ' This method is implemented by "Runnable" and will be invoked inside the JavaThread Do While True Call RefreshItem() myCounter = myCounter + 1 Loop End Sub Private Sub RefreshItem() myItem = 0 ' Set var to 0 myItem = 1 ' Set var to 1 myItem = 23 ' Our observer should get 23 from the public item-property End Sub |
|
|
Jabaco Source |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
' CLASS: TestClass.jsrc Implements java#lang#Runnable Dim myOwner As WorkerClass ' Our worker with shared resource Public Sub TestClass(refOwner As WorkerClass) ' The TestClass-Constructor myOwner = refOwner End Sub Public Sub run() Do While True Call TestItem() ' Check the resource Loop End Sub Public Sub TestItem() If myOwner.Item <> 23 Then ' The Item is produced by WorkerClass.RefreshItem(). It should be 23. out.println "Item: " & myOwner.Item ' If it isn't 23 we would like to know what it is End If End Sub |