Skip to content

Commit

Permalink
volatile added
Browse files Browse the repository at this point in the history
  • Loading branch information
vinay92 committed May 1, 2015
1 parent 7c13e9e commit 6ef5666
Showing 1 changed file with 18 additions and 15 deletions.
33 changes: 18 additions & 15 deletions src/edu/tomr/loadbalancer/ClientConnectionHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
public class ClientConnectionHandler implements Runnable {
private Socket clientSocket;
private UUID clientUID;
private static int turnOf = 0;
private static volatile Integer turnOf = 0;

static{
//ConfigParams.loadProperties();
Expand Down Expand Up @@ -62,23 +62,26 @@ public void run() {



private synchronized String getIPAddress() {
private String getIPAddress() {
String IPAddress = null;
try{

if(turnOf > ConfigParams.getIpAddresses().size() - 1){
turnOf = 0;
}
IPAddress = ConfigParams.getIpAddresses().get(turnOf);
turnOf++;
}
catch(Exception e){
Constants.globalLog.debug("Error while trying to access the IP Addresses for scheduling");
e.printStackTrace();

synchronized(turnOf){
try{

if(turnOf > ConfigParams.getIpAddresses().size() - 1){
turnOf = 0;
}
IPAddress = ConfigParams.getIpAddresses().get(turnOf);
turnOf++;
}
catch(Exception e){
Constants.globalLog.debug("Error while trying to access the IP Addresses for scheduling");
e.printStackTrace();

}
}
return IPAddress;

}
}


}

0 comments on commit 6ef5666

Please sign in to comment.