org.vishia.java2C.test
Class TestWaitNotify.TestThreadLocalData

java.lang.Object
  extended by org.vishia.java2C.test.TestWaitNotify.TestThreadLocalData
Enclosing class:
TestWaitNotify

private static final class TestWaitNotify.TestThreadLocalData
extends java.lang.Object

This class is defined only to use in the threads context. No other thread should have access to it. Therefore the instance can be defined in a thread-local data range. For Java2C it is possible to create a stack-instance.


Field Summary
(package private)  int seqCt
          A sequence counter which holds the last value of TestWaitNotify.WaitNotifyData.ctNewData to check whether all data are got.
(package private)  int seqCtLast
          A sequence counter which holds the last value of TestWaitNotify.WaitNotifyData.ctNewData to check whether all data are got.
(package private)  int testCtInterrupted
          This counter is used to test whether the interrupting of the thread works.
(package private)  int testCtMissNotify
           
(package private)  int testCtNothingReceived
           
(package private)  int testCtSuccessNotify
           
private  TestWaitNotify.WaitNotifyData theAwaitingData
          Association to the data which are notifying from outside.
(package private)  int x
           
(package private)  int y
           
 
Constructor Summary
TestWaitNotify.TestThreadLocalData(TestWaitNotify.WaitNotifyData theAwaitingDataP)
           
 
Method Summary
private  void awaitData()
          In this routine the thread is waiting for data.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

x

int x

y

int y

seqCtLast

int seqCtLast
A sequence counter which holds the last value of TestWaitNotify.WaitNotifyData.ctNewData to check whether all data are got.


seqCt

int seqCt
A sequence counter which holds the last value of TestWaitNotify.WaitNotifyData.ctNewData to check whether all data are got.


testCtInterrupted

int testCtInterrupted
This counter is used to test whether the interrupting of the thread works.


testCtNothingReceived

int testCtNothingReceived

testCtSuccessNotify

int testCtSuccessNotify

testCtMissNotify

int testCtMissNotify

theAwaitingData

private final TestWaitNotify.WaitNotifyData theAwaitingData
Association to the data which are notifying from outside.

Constructor Detail

TestWaitNotify.TestThreadLocalData

TestWaitNotify.TestThreadLocalData(TestWaitNotify.WaitNotifyData theAwaitingDataP)
Method Detail

awaitData

private void awaitData()
In this routine the thread is waiting for data. The thread runs only, if new data are available. But such an thread may be blocked forever, if no notifying occurs. Therefore it may be recommended, that the wait action is interrupted cyclically, to check some other conditions. In this case this routine waits max 1 second. If a notify doesn't occur, it returns anyway because outside there may be some other things to work.

The core of the routine is a wait for new data in Java written as:
        synchronized(theAwaitingData){
          if(seqCtLast == -1){
            seqCt = seqCtLast = theAwaitingData.ctNewData;
          }
          theAwaitingData.wait(1000);
          seqCt = theAwaitingData.ctNewData;  //same as seqCtLast if no notify is called.
          valueFromAwaitingData = theAwaitingData.x;  
        }  
 
This is translated to C in form:
      synchronized_ObjectJc(& ((* (REFJc(ythis->theAwaitingData))).base.object)); {
        if(ythis->seqCtLast == -1) 
        { 
          ythis->seqCt = ythis->seqCtLast = REFJc(ythis->theAwaitingData)->ctNewData;
        }
        wait_ObjectJc(& ((*(REFJc(ythis->theAwaitingData))).base.object), 1000, _thCxt);
        ythis->seqCt = REFJc(ythis->theAwaitingData)->ctNewData;
        valueFromAwaitingData = REFJc(ythis->theAwaitingData)->x;
      } endSynchronized_ObjectJc(& ((* (REFJc(ythis->theAwaitingData))).base.object));
 
The rest of code tests the seqCt. If new data are available, the seqCt is incremented for 1. If a notify is missed, the counter is incremented for greater 1. If no notify is occured, but the wait time is out, the seqCt isn't incremented. This three conditions are tested, and the appropriate counters are counted. The counters give an overview of occurrence while running the process. Last not least the value given by notify is processed. But it is only an example.