I have a while loop in a method. In that while loop I have many if blocks. If I have 2 threads accessing one while loop at the same time how to stop one a unique if block at the same time. Should i have to import any thing?
while (true){
if (condition){
if (statement 1){//}
else if (statement){//} //I want only one thread to access this block at a time
else if (statement2 ){//}
else{//}
}
else if condition1 ){
if (statement 1){//}
else if (statement){//} //I want only one thread to access this block at a time
else if (statement2 ){//}
else{//}
}
}
else if (condition 2){
if (statement 1){//}
else if (statement){//} //I want only one thread to access this block at a time
else if (statement2 ){//}
else{//}
}
}
else{
if (statement 1){//}
else if (statement){//} //I want only one thread to access this block at a time
else if (statement2 ){//}
else{//}
}
}