Skip to content

Instantly share code, notes, and snippets.

@msimonin
Last active December 22, 2015 07:38
Show Gist options
  • Save msimonin/6438913 to your computer and use it in GitHub Desktop.
Save msimonin/6438913 to your computer and use it in GitHub Desktop.
lock object suspend thread for a while.
private Object lockObject_;
/** Run method. */
public void run()
{
try
{
while (!isTerminated_)
{
// do something here
synchronized (lockObject_)
{
lockObject_.wait(monitoringInterval_);
}
}
}
catch (InterruptedException exception)
{
log_.debug(exception.getMessage());
}
terminate();
log_.debug("Group manager summary information producer is stopped!");
}
/**
* Terminating the thread.
*/
public synchronized void terminate()
{
log_.debug("Terminating the group manager summary information producer");
synchronized (lockObject_)
{
isTerminated_ = true;
lockObject_.notify();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment