Oracle® Fusion Middleware C++ API Reference for Oracle Coherence
12c (12.2.1.3.0)

E80355-01

TimeoutBlock Class Reference

#include <coherence/lang/TimeoutBlock.hpp>

List of all members.


Detailed Description

TimeoutBlock provides a mechanism for allowing a thread to interrupt itself if it doesn't return to a specific call site within a given timeout.

TimeoutBlock instances are intended to be used only with the COH_TIMEOUT_AFTER helper macro. Once constructed a TimeoutBlock attempts to ensure that the corresponding block completes within the specified timeout and if it does not the thread will self-interrupt. Exiting the timeout block will automatically clear any interrupt present on the thread and in such a case an InterruptedException will be thrown.

 try
     {
     COH_TIMEOUT_AFTER(5000)
         {
         doSomething();
         }
     } // this thread will self-interrupt if it doesn't reach this line within 5 seconds
 catch (InterruptedException::View vEx)
     {
     // thread timed out or was otherwise interrupted
     }
 

Note that when catching the InterruptedException the preferred form is to surround the COH_TIMEOUT block with a try/catch rather then embed the try/catch within the block. This allows handling of cases where the thread gets interrupted but the doSomething() method does not choose to throw the InterruptedException, in which case the TimeoutBlock destructor will throw it, but this happens as the block terminates and thus would not be catchable within the block.

Note that TimeoutBlock can only self-interrupt at interruptible points, and does not defend against CPU bound loops for example.

Author:
mf 2015.03.03

Public Member Functions

 TimeoutBlock (int64_t cMillis, bool fForceOverride=false)
 Specify a new timeout.
 TimeoutBlock (const TimeoutBlock &that)
 Copy constructor for COH_TIMEOUT macros.
 ~TimeoutBlock ()
 Destroy a TimeoutBlock object.

Protected Attributes

int64_t m_cMillisTimeout
 This TimeoutBlock's timeout.
int64_t m_lTimeoutOrig
 The original timeout before this instance changed it.
Thread::Handle m_hThread
 The current thread, or NULL if this block is inactive.

Constructor & Destructor Documentation

TimeoutBlock ( int64_t  cMillis,
bool  fForceOverride = false 
)

Specify a new timeout.

This constructor variant allows the caller to override a parent timeout. This is rarely needed, and is roughly the equivalent of silently consuming a thread interrupt without rethrowing the InterruptedException.

Parameters:
cMillis the new timeout.
fForceOverride true if this timeout is allowed to extend a parent timeout.

~TimeoutBlock (  ) 

Destroy a TimeoutBlock object.

This will automatically reset the timeout to any former value.


The documentation for this class was generated from the following file:
Copyright © 2000, 2017, Oracle and/or its affiliates. All rights reserved.