import java.net.*;
import java.io.*;
import java.io.*;
import java.util.*;
import java.text.*;
public class Test extends Thread implements Runnable {
public Test() {
}
//as gets a reponce create a thread strate away then start listioning again
//=========================================================================
ServerSocket svrSocket;
int clientCount;
Socket clientSocket;
public boolean ExitCommand = false;
int IMIStatsFlag = 1;
int PortNumber = 20009;
int QueSize = 1000;
static Object[] mutex = new Object[100];
static Object mutex1;
public static void main(String arg[]){
System.out.println("Start");
mutex[0] = 0;
Test T1 = new Test();
T1.start1();
System.out.println("Stoped");
}
public void start1()
{
int iclientCount = 120; // Number of threads started
mutex1 = 1;
try {
svrSocket = new ServerSocket( PortNumber, QueSize );
} catch (Exception /* IOException */ e) {
System.out.println(e.toString());
return;
}
while( IMIStatsFlag == 1 )
{
try {
while( true ) {
clientSocket = svrSocket.accept();
BufferedReader in = new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));
String XMLString = in.readLine();
in.close();
clientSocket.close();
Test test = new Test();
test.start();
}
} catch (IOException e) {
// Error
System.out.println("MIStatsListener ,Start ,IO Error: "+ e.toString());
}
}
}
public void run() {
System.out.println(Thread.currentThread()+ " Before Lock");
LockTest(0);
}
public void LockTest(int MutexLockNumber) {
try{
Thread.sleep(10);
}catch(Exception ex){
}
System.out.println(Thread.currentThread()+ " Before Lock");
System.out.println(Thread.currentThread()+ " Thread count" + Thread.activeCount());
synchronized(mutex[MutexLockNumber]){
//synchronized(mutex1){
System.out.println(Thread.currentThread()+ " Inside Lock");
int x =0;
while(x != 10){
System.out.println(Thread.currentThread()+" "+x);
x++;
try{
Thread.sleep(1000);
}catch(Exception ex){
}
}
System.out.println(Thread.currentThread()+ " Lock Finnshing");
}
System.out.println(Thread.currentThread()+ " Lock Leaving now");
}
}
|