File tree Expand file tree Collapse file tree 2 files changed +42
-3
lines changed
src/Coherence/Util/Daemon Expand file tree Collapse file tree 2 files changed +42
-3
lines changed Original file line number Diff line number Diff line change @@ -590,7 +590,7 @@ public virtual void Stop()
590
590
// Once IsExiting is set the daemon's thread will attempt to clear any interrupts and then proceed to OnExit.
591
591
// In order to ensure that this doesn't occur before we actually get to interrupt the thread we synchronize this method
592
592
// as well as Run's call to clear the interrupt.
593
- lock ( ExitMonitor )
593
+ using ( BlockingLock l = BlockingLock . Lock ( ExitMonitor ) )
594
594
{
595
595
// only go through Stop() once to prevent spurious interrupts during OnExit()
596
596
if ( ! IsExiting )
@@ -611,6 +611,45 @@ public virtual void Stop()
611
611
}
612
612
}
613
613
614
+ /// <summary>
615
+ /// Wait for the Daemon thread to stop.
616
+ /// </summary>
617
+ ///
618
+ /// <param name="millis">
619
+ /// The number of milliseconds to wait for, or zero for infinite.
620
+ /// </param>
621
+ ///
622
+ /// <returns>
623
+ /// <b>true</b> if the thread is no longer running.
624
+ /// </returns>
625
+ ///
626
+ /// <since>Coherence 14.1.2.0</since>
627
+ public virtual bool Join ( int millis )
628
+ {
629
+ try
630
+ {
631
+ Thread thread = this . Thread ;
632
+ if ( thread != null )
633
+ {
634
+ if ( millis > 0 )
635
+ {
636
+ thread . Join ( millis ) ;
637
+ }
638
+ else
639
+ {
640
+ thread . Join ( ) ;
641
+ }
642
+ return ! thread . IsAlive ;
643
+ }
644
+ return true ;
645
+ }
646
+ catch ( ThreadInterruptedException )
647
+ {
648
+ Thread . CurrentThread . Interrupt ( ) ;
649
+ return false ;
650
+ }
651
+ }
652
+
614
653
/// <summary>
615
654
/// This method is called right after this daemon's thread starts.
616
655
/// </summary>
@@ -669,7 +708,7 @@ public virtual void Run()
669
708
try
670
709
{
671
710
// see comment in Stop()
672
- lock ( ExitMonitor )
711
+ using ( BlockingLock l = BlockingLock . Lock ( ExitMonitor ) )
673
712
{
674
713
try
675
714
{
Original file line number Diff line number Diff line change @@ -647,7 +647,7 @@ protected override void OnExit()
647
647
// give the chance for the daemon to drain it's queue
648
648
try
649
649
{
650
- daemon . Thread . Join ( 1000 ) ;
650
+ daemon . Join ( 1000 ) ;
651
651
}
652
652
catch ( ThreadInterruptedException )
653
653
{
You can’t perform that action at this time.
0 commit comments