This week's book giveaway is in the OCPJP forum. We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line! See this thread for details.
I have 1 class (an applet) that runs in its own thread, I have it set up a threadgroup, with itself as the parent, that spawns 5 new threads, I want the threads to run, and immediately wait on invokation from the parent thread.
The problem is I cant seem to find any way to make the parent the owner of the waiting threads ( IllegalMonitorStateException seems to say the thread needs to be an owner of the object but that confuses me, how can an object wait? it doesnt run )
boolean p = Thread.currentThread().getThreadGroup().parentOf(cars);
where cars is the 5 threads in the group, and is called from the parent thread, is returning true, where as
boolean p = Thread.currentThread().holdsLock(engines);
where engines is an array of the threads held in the group returns false
the javadoc says that a thread can take ownership of an object by
# By executing a synchronized instance method of that object. # By executing the body of a synchronized statement that synchronizes on the object. # For objects of type Class, by executing a synchronized static method of that class.
but I cant find any examples anywhere of a parent thread, doing this
Originally posted by Dale Harvey: its cool i wasnt looking for a full explanation, just a pointer to an article or a brief overview, as the javadoc wasnt doing much to help my misunderstanding.
here had a decent explanation, I still dont fully understand it, keep to think about it like processes in c but its completely different
A process and a thread are hardware level things. There is nothing special or different about c. It is likely that many JVMs are written in c or c++ so when you are running a Java program you are actually running a c/c++ program in one way of thinking.
A thread is basically a lighter process. A thread is owned by a process, and gets all its resources from its parent process.