here is the code. Thanks in advance..
BTW, it helps a lot to get answers on this forum when you UseCodeTags. Here's your code when using code tags:
Your first version (MyThreads a = new MyThreads();) is making four different instances of a class having the Print method. Each instance is calling its own Print method. There's no synchronization happening here. Your second version (MyRunnable Runnable = new MyRunnable()) uses only one instance having the Print method, and four threads. They all use the same Runnable instance, but as the method of that instance is synchronized, other threads will have to wait before being able to call the method in their turn.
Christophe Verré wrote:Synchronizing a method will prevent this method to be called by the same instance from different threads.
Thanks Christophe i realize i have a long way to go yet. would like to write a sample code to help me.. thanks in advance
this is my first post thanks for the advices.
thanks a lot.
Christian Daniel Ortiz Cuellar wrote:Thanks Christophe i realize i have a long way to go yet. would like to write a sample code to help me.. thanks in advance
I think that your sample illustrates the problem well enough. One case using a single instance, and one case using four different instances.