Recursive problem...
Posted
by Chronos
on Stack Overflow
See other posts from Stack Overflow
or by Chronos
Published on 2010-04-15T22:16:55Z
Indexed on
2010/04/15
22:23 UTC
Read the original article
Hit count: 260
java
|multithreading
Guys,
I'm new to java and multithreading..... and I have a following problem:
I have two classes running in two different threads. Class A and Class B.
Class A has the method "onNewEvent()". Once that method is invoked, it will ask class B to do some work. As soon as B finishes the work it invokes onJobDone() method of the class A.
Now... here comes the problem... what I want is to create new job within onJobDone() method and to send it again to B.
here is what I do (pseudo code) ... in the sequence of execution
A.onNewEvent(){
//create job
//ask B to do it
B.do()
}
B.do{
// Do some stuff
A.jobDone()
}
A.onJobDOne(){
B.do() //doItAgain
// print message "Thank you for doing it"
}
The problem is... that message "Thank you for doing it" never gets printed... in fact, when onJobDone() method is invoked, it invokes B.do()... because B.do() is very fast, it invokes onJobDone() immediatly... so execution flow never comes to PRINT MESSAGE part of code...
I suppose this is one of the nasty multithreading problems....
any help would be appreciated.
© Stack Overflow or respective owner