when iWhen I try to execute the piece of icode, I am getting output like 1222112121212122121212221121212121221212. here when iWhen I declare the method is declared as synchronizedsynchronized, it should not allow the other thread to take over the control
package com.test; public class TestProject extends Thread { public void run() { synchronized (this) { for (int i = 0; i < 10; i++) { System.out.print(getName()); } } } public static void main(String[] args) throws InterruptedException { TestProject myProject = new TestProject(); TestProject myProject1 = new TestProject(); myProject.setName("1"); myProject1.setName("2"); myProject.start(); myProject1myProacject1.start(); } } so toSo, how do I alter the code to get a output of 11111111112222222222 or 22222222221111111111 in sequential format?