We don't need to synchronize if we just catch the one non-critical NPE that
might happen once in a blue moon if we don't. git-svn-id: https://samskivert.googlecode.com/svn/trunk@1558 6335cc39-0255-0410-8fd6-9bcaacd3b74c
This commit is contained in:
@@ -78,8 +78,7 @@ public abstract class Interval
|
|||||||
* Schedule the interval to execute repeatedly with the specified
|
* Schedule the interval to execute repeatedly with the specified
|
||||||
* initial delay and repeat delay.
|
* initial delay and repeat delay.
|
||||||
*/
|
*/
|
||||||
public final synchronized void schedule (
|
public final void schedule (long initialDelay, long repeatDelay)
|
||||||
long initialDelay, long repeatDelay)
|
|
||||||
{
|
{
|
||||||
cancel();
|
cancel();
|
||||||
_task = new IntervalTask();
|
_task = new IntervalTask();
|
||||||
@@ -95,11 +94,19 @@ public abstract class Interval
|
|||||||
* Cancel the Interval, and ensure that any expirations that are queued
|
* Cancel the Interval, and ensure that any expirations that are queued
|
||||||
* up but have not yet run do not run.
|
* up but have not yet run do not run.
|
||||||
*/
|
*/
|
||||||
public final synchronized void cancel ()
|
public final void cancel ()
|
||||||
{
|
{
|
||||||
if (_task != null) { // task can only be null if we were never scheduled
|
if (_task != null) {
|
||||||
_task.cancel();
|
try {
|
||||||
_task = null;
|
_task.cancel();
|
||||||
|
_task = null;
|
||||||
|
} catch (NullPointerException npe) {
|
||||||
|
// This could happen if two threads call this method
|
||||||
|
// simultaneously. I could prevent it by synchronizing
|
||||||
|
// this method and schedule(), but this is less taxing
|
||||||
|
// in the common case.
|
||||||
|
// (Also, it's impossible to NPE inside task.cancel())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user