Created
February 2, 2025 01:26
-
-
Save aerodame/088c85af65273b5b5eae4114c1426225 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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