linkedin/parseq — pull request #30 by cpettitt (2013-04-15 17:54:26+00:00)
Title: Don't hold ref to scheduled task after it has been cancelled

We have observed that tasks scheduled with the ScheduledExecutorService
remain reachable from that executor even after they have been cancelled.
This change aggresively eliminates the path from the scheduled executor
service to the underlying task by using a reference in between that will
be nulled out when the task has either run or been cancelled.

**Comparison w/ Josh's test**

Before:

```
[testng] Garbage Metrics [Parseq Returned Promise w/ Timeout] created: 0, finalized: 0
[testng] Garbage Metrics [Parseq Returned Promise w/ Timeout] created: 14, finalized: 0
[testng] Garbage Metrics [Parseq Returned Promise w/ Timeout] created: 18, finalized: 14
[testng] Garbage Metrics [Parseq Returned Promise w/ Timeout] created: 28, finalized: 14
[testng] Garbage Metrics [Parseq Returned Promise w/ Timeout] created: 42, finalized: 28
[testng] Garbage Metrics [Parseq Returned Promise w/ Timeout] created: 42, finalized: 42
[testng] Garbage Metrics [Parseq Returned Promise w/ Timeout] created: 56, finalized: 42
[testng] Garbage Metrics [Parseq Returned Promise w/ Timeout] created: 70, finalized: 56
[testng] Garbage Metrics [Parseq Returned Promise w/ Timeout] created: 74, finalized: 70
[testng] Garbage Metrics [Parseq Returned Promise w/ Timeout] created: 84, finalized: 70
[testng] Garbage Metrics [Parseq Returned Promise w/ Timeout] created: 98, finalized: 84
[testng] Garbage Metrics [Parseq Returned Promise w/ Timeout] created: 98, finalized: 84
[testng] Garbage Metrics [Parseq Returned Promise w/ Timeout] created: 98, finalized: 84
[testng] Garbage Metrics [Parseq Returned Promise w/ Timeout] created: 98, finalized: 84
[testng] Garbage Metrics [Parseq Returned Promise w/ Timeout] created: 98, finalized: 84
[testng] Garbage Metrics [Parseq Returned Promise w/ Timeout] created: 98, finalized: 88
[testng] Garbage Metrics [Parseq Returned Promise w/ Timeout] created: 98, finalized: 98
[testng] Garbage Metrics [Parseq Returned Promise w/ Timeout] created: 98, finalized: 98
[testng] Garbage Metrics [Parseq Returned Promise w/ Timeout] created: 98, finalized: 98
[testng] Garbage Metrics [Parseq Returned Promise w/ Timeout] created: 98, finalized: 98
[testng] Garbage Metrics [Parseq Returned Promise w/ Timeout] created: 98, finalized: 98
```

After:

```
[testng] Garbage Metrics [Parseq Returned Promise w/ Timeout] created: 0, finalized: 0
[testng] Garbage Metrics [Parseq Returned Promise w/ Timeout] created: 38, finalized: 32
[testng] Garbage Metrics [Parseq Returned Promise w/ Timeout] created: 68, finalized: 63
[testng] Garbage Metrics [Parseq Returned Promise w/ Timeout] created: 143, finalized: 135
[testng] Garbage Metrics [Parseq Returned Promise w/ Timeout] created: 168, finalized: 166
[testng] Garbage Metrics [Parseq Returned Promise w/ Timeout] created: 198, finalized: 189
[testng] Garbage Metrics [Parseq Returned Promise w/ Timeout] created: 225, finalized: 214
[testng] Garbage Metrics [Parseq Returned Promise w/ Timeout] created: 255, finalized: 253
[testng] Garbage Metrics [Parseq Returned Promise w/ Timeout] created: 283, finalized: 278
[testng] Garbage Metrics [Parseq Returned Promise w/ Timeout] created: 299, finalized: 292
[testng] Garbage Metrics [Parseq Returned Promise w/ Timeout] created: 312, finalized: 306
[testng] Garbage Metrics [Parseq Returned Promise w/ Timeout] created: 350, finalized: 336
[testng] Garbage Metrics [Parseq Returned Promise w/ Timeout] created: 382, finalized: 376
[testng] Garbage Metrics [Parseq Returned Promise w/ Timeout] created: 459, finalized: 454
[testng] Garbage Metrics [Parseq Returned Promise w/ Timeout] created: 529, finalized: 523
[testng] Garbage Metrics [Parseq Returned Promise w/ Timeout] created: 554, finalized: 540
[testng] Garbage Metrics [Parseq Returned Promise w/ Timeout] created: 627, finalized: 619
[testng] Garbage Metrics [Parseq Returned Promise w/ Timeout] created: 698, finalized: 695
[testng] Garbage Metrics [Parseq Returned Promise w/ Timeout] created: 789, finalized: 780
[testng] Garbage Metrics [Parseq Returned Promise w/ Timeout] created: 842, finalized: 838
[testng] Garbage Metrics [Parseq Returned Promise w/ Timeout] created: 929, finalized: 924
```