Thread waiting

how do you make a class wait for a thred to have run for a certan amount of time
so i whant to
Thread.start()
wait for thread to get to line 500
do somthing whith thread;

Excuse me, but how about buying a good Java book?

You’ll learn pretty much nothing this way, seriously! Do yourself a favor.

i did and i got board ;D the chapter on threading explains how to make a thread wait for stuf or sleep but not on how to make a class wait for a thread to run() or start() :’( :’( :’( :’( oh yer and i have leart alot on these forms ;D

That’s because you can’t make a class wait. A class doesn’t have its own flow of control. A thread does. Threads can wait for each other.

that and start and stop are depricated.

start() is very much not deprecated. stop() and suspend() are

your quite and very right

/hides his face.

You might want to check out a simple example on how threads work first.

There’s a good example at
http://www.particle.kth.se/~lindsey/JavaCourse/Book/Part1/Java/Chapter08/demoClock.html

Actually, I think this is a good question, since it’s a real-life one that often isnt answered by the books (because they’re too academic). Although the best answer would be “use co-routines”, since those aren’t natively in java lets not go there :).

The correct way would be to use Object.wait() and Object.notify() (that’s enough for you to google - but the simple explanation is you pick any object that is accessible to both your main class and to the thread, and when you want the class to start waiting you call (the object).wait(), and when the thread reaches line 500 you have it call (the object).notify().

Java lets you use any object for htis, soyou can have an infinite number of wait / notify pairs running in tandem at any one time. For example, you might create a String with the value “wait for thread to reach line 500” and use that as your object.

there is no fixed relation to lines and time. Perhaps he was as uncarefull as I was in my first reply, but that hints. also in conjunction with thread start() doing nothing till line 500 why not simply call start() at line 500?