I've been looking about multi threading tutorials and those specific about synchronization, but I haven't been able to implement something that I need.
It's a showcase of a synchronization happening in my program.
Basically, I have one class that inherits some functions from other class, those functions needs to be synchronized in order for both of threads doesn't modify an object at the same time (no data corruption).
I previously implemented the code without the synchronize keyword, so I could manage to see the data corruption occurring.
EditOptionsMethods e1;
int threadNo;
public EditOptions() {
e1 = new BuildAuto();
run();
}
public void run() {
System.out.println("Thread running.");
switch (threadNo) {
case 0:
break;
case 1:
break;
}
}
public void setOptions(String optSetName1, String desiredOption1, String optSetName2, String desiredOption2) {
e1.s_Option(optSetName1, desiredOption1); //
e1.s_Option(optSetName2, desiredOption2);
}
s_Option will have to be synchronized so both threads won't occur. I firstly will have it without synchronize, then I can initialize a loop (with high index amount, lets say 1000 and then I add with first thread, and subtract with second thread) to see the corruption occurring as an example.
But I don't find a way of showing this.
If someone has an idea of how I could possibly implement this, that'd be awesome.