Hi

 // This method is synchronized
    synchronized void timeStamp(String name){
            for (int i = 0; i < 4; i++) {
                try {
                    Thread.sleep(1000);
                }//try
                catch (InterruptedException e) {
                }//catch
                System.out.println(name + " at " + i +
                        " has " + this.getCurrentTime());
            }//for
        }//print

Output is
Time3 at 0 has Saturday, October 17, 2009 1:56:49 PM EDT
Time1 at 0 has Saturday, October 17, 2009 1:56:49 PM EDT
Time2 at 0 has Saturday, October 17, 2009 1:56:49 PM EDT
Time3 at 1 has Saturday, October 17, 2009 1:56:50 PM EDT
Time2 at 1 has Saturday, October 17, 2009 1:56:50 PM EDT
Time1 at 1 has Saturday, October 17, 2009 1:56:50 PM EDT
Time3 at 2 has Saturday, October 17, 2009 1:56:51 PM EDT
Time1 at 2 has Saturday, October 17, 2009 1:56:51 PM EDT
Time2 at 2 has Saturday, October 17, 2009 1:56:51 PM EDT
Time3 at 3 has Saturday, October 17, 2009 1:56:52 PM EDT
Time1 at 3 has Saturday, October 17, 2009 1:56:52 PM EDT
Time2 at 3 has Saturday, October 17, 2009 1:56:52 PM EDT

Time1 is not first to start.  Does this method have to be synchronized.  
Homework is not explicit?


      


--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to