| 394 |
|
|
| 395 |
// Some convenient Runnable classes |
// Some convenient Runnable classes |
| 396 |
|
|
| 397 |
|
abstract class CheckedRunnable implements Runnable { |
| 398 |
|
abstract void realRun() throws Throwable; |
| 399 |
|
|
| 400 |
|
public final void run() { |
| 401 |
|
try { |
| 402 |
|
realRun(); |
| 403 |
|
} catch (Throwable t) { |
| 404 |
|
threadUnexpectedException(t); |
| 405 |
|
} |
| 406 |
|
} |
| 407 |
|
} |
| 408 |
|
|
| 409 |
|
abstract class CheckedInterruptedRunnable implements Runnable { |
| 410 |
|
abstract void realRun() throws Throwable; |
| 411 |
|
|
| 412 |
|
public final void run() { |
| 413 |
|
try { |
| 414 |
|
realRun(); |
| 415 |
|
threadShouldThrow(); |
| 416 |
|
} catch (InterruptedException success) { |
| 417 |
|
} catch (Throwable t) { |
| 418 |
|
threadUnexpectedException(t); |
| 419 |
|
} |
| 420 |
|
} |
| 421 |
|
} |
| 422 |
|
|
| 423 |
|
abstract class CheckedCallable<T> implements Callable<T> { |
| 424 |
|
abstract T realCall() throws Throwable; |
| 425 |
|
|
| 426 |
|
public final T call() { |
| 427 |
|
try { |
| 428 |
|
return realCall(); |
| 429 |
|
} catch (Throwable t) { |
| 430 |
|
threadUnexpectedException(t); |
| 431 |
|
return null; |
| 432 |
|
} |
| 433 |
|
} |
| 434 |
|
} |
| 435 |
|
|
| 436 |
static class NoOpRunnable implements Runnable { |
static class NoOpRunnable implements Runnable { |
| 437 |
public void run() {} |
public void run() {} |
| 438 |
} |
} |
| 455 |
public Integer call() { return one; } |
public Integer call() { return one; } |
| 456 |
} |
} |
| 457 |
|
|
| 458 |
class ShortRunnable implements Runnable { |
class ShortRunnable extends CheckedRunnable { |
| 459 |
public void run() { |
void realRun() throws Throwable { |
|
try { |
|
| 460 |
Thread.sleep(SHORT_DELAY_MS); |
Thread.sleep(SHORT_DELAY_MS); |
| 461 |
} |
} |
|
catch (Exception e) { |
|
|
threadUnexpectedException(e); |
|
|
} |
|
|
} |
|
| 462 |
} |
} |
| 463 |
|
|
| 464 |
class ShortInterruptedRunnable implements Runnable { |
class ShortInterruptedRunnable extends CheckedInterruptedRunnable { |
| 465 |
public void run() { |
void realRun() throws InterruptedException { |
|
try { |
|
| 466 |
Thread.sleep(SHORT_DELAY_MS); |
Thread.sleep(SHORT_DELAY_MS); |
|
threadShouldThrow(); |
|
|
} |
|
|
catch (InterruptedException success) { |
|
|
} |
|
| 467 |
} |
} |
| 468 |
} |
} |
| 469 |
|
|
| 470 |
class SmallRunnable implements Runnable { |
class SmallRunnable extends CheckedRunnable { |
| 471 |
public void run() { |
void realRun() throws Throwable { |
|
try { |
|
| 472 |
Thread.sleep(SMALL_DELAY_MS); |
Thread.sleep(SMALL_DELAY_MS); |
| 473 |
} |
} |
|
catch (Exception e) { |
|
|
threadUnexpectedException(e); |
|
|
} |
|
|
} |
|
| 474 |
} |
} |
| 475 |
|
|
| 476 |
class SmallPossiblyInterruptedRunnable implements Runnable { |
class SmallPossiblyInterruptedRunnable extends CheckedRunnable { |
| 477 |
public void run() { |
void realRun() { |
| 478 |
try { |
try { |
| 479 |
Thread.sleep(SMALL_DELAY_MS); |
Thread.sleep(SMALL_DELAY_MS); |
| 480 |
} |
} |
| 481 |
catch (Exception e) { |
catch (InterruptedException ok) { |
| 482 |
} |
} |
| 483 |
} |
} |
| 484 |
} |
} |
| 485 |
|
|
| 486 |
class SmallCallable implements Callable { |
class SmallCallable extends CheckedCallable { |
| 487 |
public Object call() { |
Object realCall() throws Throwable { |
|
try { |
|
| 488 |
Thread.sleep(SMALL_DELAY_MS); |
Thread.sleep(SMALL_DELAY_MS); |
|
} |
|
|
catch (Exception e) { |
|
|
threadUnexpectedException(e); |
|
|
} |
|
| 489 |
return Boolean.TRUE; |
return Boolean.TRUE; |
| 490 |
} |
} |
| 491 |
} |
} |
| 492 |
|
|
| 493 |
class SmallInterruptedRunnable implements Runnable { |
class SmallInterruptedRunnable extends CheckedInterruptedRunnable { |
| 494 |
public void run() { |
void realRun() throws InterruptedException { |
|
try { |
|
| 495 |
Thread.sleep(SMALL_DELAY_MS); |
Thread.sleep(SMALL_DELAY_MS); |
|
threadShouldThrow(); |
|
|
} |
|
|
catch (InterruptedException success) { |
|
|
} |
|
| 496 |
} |
} |
| 497 |
} |
} |
| 498 |
|
|
| 499 |
|
class MediumRunnable extends CheckedRunnable { |
| 500 |
class MediumRunnable implements Runnable { |
void realRun() throws Throwable { |
|
public void run() { |
|
|
try { |
|
| 501 |
Thread.sleep(MEDIUM_DELAY_MS); |
Thread.sleep(MEDIUM_DELAY_MS); |
| 502 |
} |
} |
|
catch (Exception e) { |
|
|
threadUnexpectedException(e); |
|
|
} |
|
|
} |
|
| 503 |
} |
} |
| 504 |
|
|
| 505 |
class MediumInterruptedRunnable implements Runnable { |
class MediumInterruptedRunnable extends CheckedInterruptedRunnable { |
| 506 |
public void run() { |
void realRun() throws InterruptedException { |
|
try { |
|
| 507 |
Thread.sleep(MEDIUM_DELAY_MS); |
Thread.sleep(MEDIUM_DELAY_MS); |
|
threadShouldThrow(); |
|
|
} |
|
|
catch (InterruptedException success) { |
|
|
} |
|
| 508 |
} |
} |
| 509 |
} |
} |
| 510 |
|
|
| 511 |
class MediumPossiblyInterruptedRunnable implements Runnable { |
class MediumPossiblyInterruptedRunnable extends CheckedRunnable { |
| 512 |
public void run() { |
void realRun() { |
| 513 |
try { |
try { |
| 514 |
Thread.sleep(MEDIUM_DELAY_MS); |
Thread.sleep(MEDIUM_DELAY_MS); |
| 515 |
} |
} |
| 516 |
catch (InterruptedException success) { |
catch (InterruptedException ok) { |
| 517 |
} |
} |
| 518 |
} |
} |
| 519 |
} |
} |
| 520 |
|
|
| 521 |
class LongPossiblyInterruptedRunnable implements Runnable { |
class LongPossiblyInterruptedRunnable extends CheckedRunnable { |
| 522 |
public void run() { |
void realRun() { |
| 523 |
try { |
try { |
| 524 |
Thread.sleep(LONG_DELAY_MS); |
Thread.sleep(LONG_DELAY_MS); |
| 525 |
} |
} |
| 526 |
catch (InterruptedException success) { |
catch (InterruptedException ok) { |
| 527 |
} |
} |
| 528 |
} |
} |
| 529 |
} |
} |
| 594 |
* For use as RejectedExecutionHandler in constructors |
* For use as RejectedExecutionHandler in constructors |
| 595 |
*/ |
*/ |
| 596 |
static class NoOpREHandler implements RejectedExecutionHandler { |
static class NoOpREHandler implements RejectedExecutionHandler { |
| 597 |
public void rejectedExecution(Runnable r, ThreadPoolExecutor executor){} |
public void rejectedExecution(Runnable r, |
| 598 |
|
ThreadPoolExecutor executor) {} |
| 599 |
} |
} |
| 600 |
|
|
|
|
|
| 601 |
} |
} |