On Nov 18, 12:16 pm, "Norman Ho" <[EMAIL PROTECTED]> wrote:
> For Lab_1021 Java Thread homework, we are asked to initiate 3 threads, each
> thread to display the current time in 100 millisecond interval for 10 times;
> using the sleep() method for the interval.
>
> Are the threads supposed to run sequentially, i.e. thread 2 do not start
> until thread 1 has finished etc?
>
> I have no problem to have the thread grapping a time slice while the other
> "sleep()", this produce an interleaved process, not sequential.
>
> I am having great difficulty trying to have them running sequentially.
> Please help.
As the sequencing depends of the native scheduler, you cannot control
entirely how the threads are called, that is if thread 3 is called
before or after thread 2, for example.
But you can force a given thread to wait for the end of another given
thread using synchronized modifier on the method called from the run
method of the thread.
--~--~---------~--~----~------------~-------~--~----~
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/javaprogrammingwithpassion?hl=en
-~----------~----~----~----~------~----~------~--~---