Skip to content

Instantly share code, notes, and snippets.

@aerodame
Created February 2, 2025 01:26
Show Gist options
  • Save aerodame/088c85af65273b5b5eae4114c1426225 to your computer and use it in GitHub Desktop.
Save aerodame/088c85af65273b5b5eae4114c1426225 to your computer and use it in GitHub Desktop.
public class Process {
private String name;
public Process() {
}
public Process(String name) {
this.name = name;
}
public String getName() {
return name;
}
/**
* Method: criticalSection() computes only during a valid protected temporal process execution
* @param calculatedFactorials - HashMap to store (num, partialFactorial)
*/
public void criticalSection(ConcurrentHashMap<Integer, String> sharedCalculatedFactorials) {
Random random = new Random();
int num;
do {
num = random.nextInt(1000) + 500;
} while (sharedCalculatedFactorials.containsKey(num));
BigInteger factorial = FactorialCalculator.calculateFactorial(num); // Call the new method
String partialFactorial = factorial.toString().substring(0, 64);
sharedCalculatedFactorials.put(num, partialFactorial); // Store in the map
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment