threadsync_synchronize_b.htm 1-2-3
This is an extended version of threadsync_synchronize.htm, compiled with Text-Pad trial edition, and ran in command console.

import java.util.*;
import java.io.*;
//javac thread_synchro_b.java
public class thread_synchro_b
{
//public static int n1 = 1;
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.println("-->Welcome to thread building<--");
System.out.print("type location : ");
String str = br.readLine();
System.out.println("Welcome " + str+ " to Voting Zone ");
Booth_b booth = new Booth_b();
String s;
for(int i = 1; i < 6; i++)
{
s = str + i;
Booth_sync_b booth_sync = new Booth_sync_b(booth, s, i);
try {
booth_sync.t_booth.join();
}
catch(InterruptedException e){ //   custom msg }
}}}
/////////////
class Booth_sync_b implements Runnable
{
Booth_b booth;
String name;
Thread t_booth;
private int voter_no;
public Booth_sync_b(Booth_b booth, String name, int voter_no)
{
this.name = name;
this.booth = booth;
this.voter_no= voter_no;
t_booth = new Thread(this);
t_booth.setName(name);
t_booth.start();
}
public void run()
{
synchronized(booth)
{
booth.voterin(voter_no);

System.out.println("voter-in sync_b : " + voter_no + " : " +Thread.currentThread().getId());
booth.voterout(voter_no);
System.out.println("\t\tvoter-out sync_b : " + voter_no+ " : " +Thread.currentThread().getId());
}}}
///class booth that takes input from users
class Booth_b
{
private int voter_no ;
public void voterin( int voter_in)
{
this.voter_no = voter_in;
System.out.println("Thread-ID at Booth_b :" + Thread.currentThread().getId());
System.out.println("voter-in at Booth_b : " + voter_no);
}
public int voterout(int vouter_out)
{
this.voter_no= vouter_out;
System.out.println("\t\tThread-ID at Booth_b : " + Thread.currentThread().getId());
System.out.println("\t\tvoter-out at Booth_b : " + voter_no);
return voter_no;
}
}