I a have project that I'm working on dealing with multithreading and am struggling a bit to understand how a goal like this could be accomplished.
The program represents a kitchen, and I have an oven which I want to run for an X amount of time, I want the thread to block for X amount of time, and at the end of the block, return whether the dish was fully cooked (was the oven turned on the entire X amount of time?)
The issue I am having is that when my thread blocks, my boolean could be flipped off and back on, and I have no way to capture that, just the ending result.
Is there something in Java that I could use that would allow me to block on the thread until either the time has elapsed or the boolean changes?
My current code is as follows:
public boolean cookFor(int minutes)
{
//Milliseconds of block should be relative to temperature
int milliseconds = (minutes * 100);
try
{
//Block thread for milliseconds time
Thread.sleep(milliseconds);
}
catch (InterruptedException e)
{
}
//Status indicates if Oven is On or Off
return status;
}