Hi to all, actually i'm studying for
SCJP for April 10 :S . Iwas reading about Threads because i haven't understand yet all concerning Threads. I was coding a
java class that works with 3 threads, as you can see in the code:
As you can see, i have 3 girlfriend threads and i want to first to run "Estefany"
thread, second "Helen" thread and finally "Ada" thread, so in the run method when the thread is "Ada" then i call join over "Helen" thread to forcing "Ada" thread to run after "Helen" thread dies and after that when the thread is "Helen", join to force "Helen" thread run after "Estefani" thread dies.
So, because i was studying also the synchronized keyword because i don't understand very well that i leave my run method as synchronized and using join. I know that if i use join to handle the 3 threads there will no problem because the for loop will execute first for Estefany, second for Helen and third for Ada, but i think that the difference in my class between using the joins and using synchronized is that only with synchronized i can't guarantee the order of threads execution but each one will run the foor loop individually, and with joins i can guarantee the order of threads execution and also the for loop execution individually, but, when i
test my source code it looks like a deadlock, but that only when first thread to run is Ada or Helen, because Estefani pass the if's of the run method without enter in one of them. But for example, if Ada thread runs first, it enters in the first if and in the join call the program freezes, i think that it's a deadlock but i don't understand why.
Thanks in advance