|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectjava.lang.Thread
org.vishia.java2C.test.TestWaitNotify
public class TestWaitNotify
This class demonstrates and tests the usage of threads with wait and notify.
It implements the run()-Method of the Thread defined in the interface Runnable, which is inherited from the super class Thread.
The class based on Thread, therefore no other instance is necessary to organize the thread.
The threads private data which should be able to access only by the current thread are stored
in an extra class, here defined as static inner class.
| Nested Class Summary | |
|---|---|
private static class |
TestWaitNotify.TestThreadLocalData
This class is defined only to use in the threads context. |
static class |
TestWaitNotify.WaitNotifyData
This class is visible from outside, it is used from the notifying thread and from this thread, which waits for data. |
| Nested classes/interfaces inherited from class java.lang.Thread |
|---|
java.lang.Thread.State, java.lang.Thread.UncaughtExceptionHandler |
| Field Summary | |
|---|---|
(package private) boolean |
shouldRun
This is a central thread-control variable. |
(package private) TestWaitNotify.WaitNotifyData |
theAwaitingData
Aggregation to data to check wait/notify. |
| Fields inherited from class java.lang.Thread |
|---|
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY |
| Constructor Summary | |
|---|---|
TestWaitNotify(TestWaitNotify.WaitNotifyData theAwaitingDataP)
Constructor. |
|
| Method Summary | |
|---|---|
void |
run()
This is the thread main-routine complying the Java rules. |
void |
start()
This routine overrides Thread.start(), it's a facade. |
| Methods inherited from class java.lang.Thread |
|---|
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, stop, stop, suspend, toString, yield |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Field Detail |
|---|
boolean shouldRun
final TestWaitNotify.WaitNotifyData theAwaitingData
| Constructor Detail |
|---|
TestWaitNotify(TestWaitNotify.WaitNotifyData theAwaitingDataP)
theAwaitingData - for aggregation| Method Detail |
|---|
public void start()
Thread.start(), it's a facade. It calls Thread.start() using
/**@java2c=stackSize(TestThreadLocalData+500). * /
super.start();
It is a facade, containing the stacksize annotation regarded in Java2C-translation.
The produced C-Code is:
start_ThreadJc(ythis, sizeof(TestWaitNotify_Test__TestThreadLocalData_s)+500, _thCxt);
start in class java.lang.Threadjava.lang.Thread#start()}public void run()
TestWaitNotify.TestThreadLocalData, which are accessed by this thread only.
In Java the instances are referenced, but the reference is only known in stack context,
provided to called routines via parameter. In C the instances are allocated in the stack
because a @ java2c=stackInstance. is written thereby. Large-size instances need
an adequate stack size. The Java-code for this code-snippet is:
...* @java2c=stackInstance. * /
TestThreadLocalData threadLocalData = new TestThreadLocalData();
The generated C-code is:
TestThread_Test__TestThreadLocalData_s threadLocalData;
...
init_ObjectJc(&(threadLocalData.base.object), sizeof(threadLocalData), 0);
ctorO_TestThread_Test__TestThreadLocalData(&(threadLocalData.base.object), _thCxt);
The thread contains a while-loop with test of shouldRun and a sleep in the Java-form:
while(shouldRun){
threadLocalData.awaitData();
}//while
In C it is mapped too, but it isn't used yet.
while(ythis->shouldRun) {
awaitData_TestWaitNotify_Test__TestThreadLocalData_F(& (threadLocalData), _thCxt);
}
run in interface java.lang.Runnablerun in class java.lang.Thread
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||