Hey guys!
I've been a fan of this site for a while and now I'm joined and writing my first post.
I'm working on a basic program.
It is supposed to have three classes:
One main class (with the main method)
One class, T1, which extends
Thread
One class, T2, which implements Runnable.
When the main class runs, it is supposed to:
Create and start a thread from class T1
Wait for 5 seconds
Create and start a thread from class T2
Wait for 5 seconds
Stop the thread from T1
Wait for 5 seconds
Stop the thread from T2
Once per second each thread should print out:
T1: T1
T2: T2
This is my code so far, it does what it is supposed to but I know it's ugly as hell.
A 'more enhanced' version of this program should be able to.
Create and start a thread from T1 class, Wait for 5 seconds
Create and start a thread from T2 class, Wait for 5 seconds
Pause thread from T2 , Wait for 5 seconds
Resume thread from T2 class, Wait for 5 seconds
Stop thread from T1 class, Wait for 5 seconds
Stop thread from T2 class
I've read up on synchronization in
Java and I just can't seem to figure out how to do this with only three classes! I think that I need one more class, in order to have a shared object that they can synchronize on, but I'm only allowed 3 classes in this assignment! Any help on how to get the 'more enhanced' version going with only three classes is very appreciated!
Best regards
// oVERGROW