Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Submission for Assignment04 #9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Uh oh!
There was an error while loading. Please reload this page.
Submission for Assignment04 #9
Changes from all commits
754f91e86ff3e75fc58ba038f6b7da234d6895782f60df8beFile filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
There are no files selected for viewing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
fd -t f "Agent.java" assignment04Repository: fareenlavji/rtConcurrentSystems
Length of output: 98
🏁 Script executed:
Repository: fareenlavji/rtConcurrentSystems
Length of output: 3793
Preserve interrupt status instead of ignoring it.
The empty catch block at line 65 consumes
InterruptedExceptionand clears the thread's interrupt status, preventing graceful shutdown or external thread cancellation. WhenThread.sleep()is interrupted, the exception should be handled by either re-interrupting the thread to restore its interrupted state or exiting the operation.Proposed fix
try { logger.logEvent(name, "WORK_START"); Thread.sleep((int)(Math.random() * 3000)); logger.logEvent(name, "WORK_END"); - } catch (InterruptedException e) {} + } catch (InterruptedException e) { + Thread.currentThread().interrupt(); + logger.logEvent(name, "THREAD_INTERRUPTED"); + break; + }🤖 Prompt for AI Agents
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧹 Nitpick | 🔵 Trivial
Consider making
SIZEastatic finalconstant for consistency.SIZEis declared asfinalbut notstatic, whileMAX_DRONESisstatic final. SinceSIZEis a compile-time constant and doesn't vary per instance, it should also bestatic finalfor consistency and to avoid redundant memory allocation per instance.♻️ Suggested fix
📝 Committable suggestion
🤖 Prompt for AI Agents
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unbalanced wait logging on early exit.
When
dronesMade == MAX_DRONESat line 41, the method returns afterwaitStart()has been logged but beforewaitEnd()can be logged. This creates unbalanced log entries that could confuse theLogAnalyzeror produce misleading metrics.🔧 Proposed fix
while (tableFull) { - logger.waitStart(Thread.currentThread().getName()); - //Exit if no more drones are required to be assembled - if (this.dronesMade == MAX_DRONES){ return; } + if (this.dronesMade == MAX_DRONES) { return; } try { + logger.waitStart(Thread.currentThread().getName()); wait(); //Tells agent to wait until notified logger.waitEnd(Thread.currentThread().getName()); } catch (InterruptedException e) { e.printStackTrace(); } }🤖 Prompt for AI Agents
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧹 Nitpick | 🔵 Trivial
Restore interrupted status when catching
InterruptedException.Swallowing
InterruptedExceptionwith an empty catch block loses the interrupt signal. Best practice is to restore the interrupt status so that higher-level code can detect the interruption.♻️ Proposed fix
try { logger.logEvent(Thread.currentThread().getName(), "WORK_START"); Thread.sleep((int)(Math.random() * 1000)); logger.logEvent(Thread.currentThread().getName(), "WORK_END"); - } catch (InterruptedException e) {} + } catch (InterruptedException e) { + Thread.currentThread().interrupt(); + }📝 Committable suggestion
🤖 Prompt for AI Agents
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧹 Nitpick | 🔵 Trivial
Restore interrupted status when catching
InterruptedException.Same issue as in
addComponents— the interrupt signal is lost whenInterruptedExceptionis caught with an empty block.♻️ Proposed fix
try { logger.logEvent(Thread.currentThread().getName(), "WORK_START"); Thread.sleep((int)(Math.random() * 1000)); logger.logEvent(Thread.currentThread().getName(), "WORK_END"); - } catch (InterruptedException e) {} + } catch (InterruptedException e) { + Thread.currentThread().interrupt(); + }📝 Committable suggestion
🤖 Prompt for AI Agents
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Handle
InterruptedExceptionper-join to ensure all threads are awaited.If an
InterruptedExceptionis thrown during onejoin(), the remaining threads won't be joined, potentially leaving them running whenlogger.stop()is called. Consider joining each thread individually or re-attempting joins after restoring the interrupt flag.🔧 Proposed fix
🤖 Prompt for AI Agents
Uh oh!
There was an error while loading. Please reload this page.