aspose file tools
The moose likes Threads and Synchronization and the fly likes Thread synch question Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Threads and Synchronization
Reply Bookmark "Thread synch question" Watch "Thread synch question" New topic
Author

Thread synch question

cornel jew
Ranch Hand

Joined: Jul 13, 2002
Posts: 37
Hi all
I was running the following code,but the output is intermixed although the test method is synchronized.
What i understand is when a method is synch no other thread can access that method b4 it is finish
What am i missing here.

Thanks for your help
cornel
Dave put in UBB code tags
[ December 09, 2002: Message edited by: Dave Vick ]
Dave Vick
Ranch Hand

Joined: May 10, 2001
Posts: 3244
Moving to the threads forum...


Dave
Greg Charles
Bartender

Joined: Oct 01, 2001
Posts: 2542
    
  10

Synchronization, the way you've done it, works on objects, not classes. You've created two objects, so the threads are free to switch between the print outs. If you want them to be synchronized by class, then synchronize a static method ... or, and this is the easier way in your case, don't use two threads.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Thread synch question
 
Similar Threads
Clarification on Thread
Question on syncrhonized methods
Question on synchronize block
Threading synchronization
Thread synch question