Before submitting this PR, I recreated the sample to personally experience the effects of the code. This helped to provided a more accurate and clear description of the actual problem in the text. In testing, I extended the code with a few simple endpoints to fully support the operations needed.
Full Testing Code
public class MultithreadedServerExample {
static int sum = 0;
// Main function and other boilerplate statements omitted for clarity.
Spark.get("/add/:value", (req, res) -> {
sum += Integer.parseInt(req.params(":value"));
return " " + sum;
});
Spark.get("/set/:value", (req, res) -> {
sum = Integer.parseInt(req.params(":value"));
return " " + sum;
});
Spark.get("/get", (req, res) -> " " + sum);
}
curl localhost:8080/set/0
for i in {1..100}; do curl localhost:8080/add/1; print ""; done &
for i in {1..100}; do curl localhost:8080/add/-1; print ""; done &
wait
curl localhost:8080/get; print"";
Resolves #110.
Before submitting this PR, I recreated the sample to personally experience the effects of the code. This helped to provided a more accurate and clear description of the actual problem in the text. In testing, I extended the code with a few simple endpoints to fully support the operations needed.
Full Testing Code