Package DE_EPAGES::Core::API::Object::MonitorThread
The monitor thread observes the worker (main) thread. If the main thread need longer then a specified timeout to finish, the monitor thread intercepts and sends the WebAdapter an intermediate result (hourglas page) by calling $Monitor->timeout. The main functionality of this modules is to synchronize the main and the monitor thread.
Example |
$MonitorThread = DE_EPAGES::Core::API::Object::MonitorThread->new( 'Monitor' => $MonitorShared, 'Timeout' => 5, ); foreach @Requests { $MonitorThread->run( Sub => sub { return 'do anything for request, like handle()'; } ); } |
Functions
close
Shuts down the monitor thread. Signals the thread function, waits for the thread function to exit and joins the thread.
monitor
Returns the monitor object.
Syntax |
$Monitor = $MonitorThread->monitor; |
Return |
|
new
Creates a new monitor thread (used at application server start). The $Monitor object is used to send the hourglas page after a timeout. The result of this function is not the thread itself. It's wrapper that manages the thread and the synchronization between main and monitor thread. The thread will be joined automatically when this object is destroyed.
Syntax |
$MonitorThread = DE_EPAGES::Core::API::Object::MonitorThread->new(%options); |
Example |
$MonitorThread = DE_EPAGES::Core::API::Object::MonitorThread->new( 'Monitor' => $Monitor, 'Timeout' => 15 ); |
Input |
|
Return |
|
run
Use this method to execute a possible long-running procedure. In the beginning it calls $Monitor->reset. When the specified timeout (see new) is reached before the procedure has finished, it calls $Monitor->timeout on a second thread.
Syntax |
$MonitorThread->run( Sub => $Sub ); |
Example |
$MonitorThread->run( Sub => sub { sleep(30); }, ); |
Input |
|
startMonitor
Starts the monitor immediately even before timeout has been reached.
Syntax |
$self->startMonitor; |
thread
returns the real thread.
Syntax |
$Thread = $MonitorThread->thread; |
Return |
|