activemq-cpp-3.6.0
Main Page
Namespaces
Data Structures
Files
File List
Globals
ThreadPoolExecutor.h
Go to the documentation of this file.
1
/*
2
* Licensed to the Apache Software Foundation (ASF) under one or more
3
* contributor license agreements. See the NOTICE file distributed with
4
* this work for additional information regarding copyright ownership.
5
* The ASF licenses this file to You under the Apache License, Version 2.0
6
* (the "License"); you may not use this file except in compliance with
7
* the License. You may obtain a copy of the License at
8
*
9
* http://www.apache.org/licenses/LICENSE-2.0
10
*
11
* Unless required by applicable law or agreed to in writing, software
12
* distributed under the License is distributed on an "AS IS" BASIS,
13
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
* See the License for the specific language governing permissions and
15
* limitations under the License.
16
*/
17
#ifndef _DECAF_UTIL_CONCURRENT_THREADPOOLEXECUTOR_H_
18
#define _DECAF_UTIL_CONCURRENT_THREADPOOLEXECUTOR_H_
19
20
#include <
decaf/lang/Runnable.h
>
21
#include <
decaf/lang/Throwable.h
>
22
#include <
decaf/util/concurrent/ThreadFactory.h
>
23
#include <
decaf/util/concurrent/BlockingQueue.h
>
24
#include <
decaf/util/concurrent/TimeUnit.h
>
25
#include <
decaf/util/concurrent/AbstractExecutorService.h
>
26
#include <
decaf/util/concurrent/RejectedExecutionHandler.h
>
27
#include <
decaf/util/concurrent/RejectedExecutionException.h
>
28
#include <
decaf/util/LinkedList.h
>
29
#include <
decaf/util/ArrayList.h
>
30
#include <
decaf/util/Config.h
>
31
32
#include <vector>
33
34
namespace
decaf{
35
namespace
util{
36
namespace
concurrent{
37
38
using
decaf::lang::Pointer
;
39
40
class
ExecutorKernel;
41
58
class
DECAF_API
ThreadPoolExecutor
:
public
AbstractExecutorService
{
59
private
:
60
61
ThreadPoolExecutor
(
const
ThreadPoolExecutor
& );
62
ThreadPoolExecutor
& operator= (
const
ThreadPoolExecutor
& );
63
64
private
:
65
66
friend
class
ExecutorKernel;
67
ExecutorKernel* kernel;
68
69
public
:
70
97
ThreadPoolExecutor
(
int
corePoolSize,
int
maxPoolSize,
98
long
long
keepAliveTime,
const
TimeUnit
& unit,
99
BlockingQueue<decaf::lang::Runnable*>
* workQueue);
100
131
ThreadPoolExecutor
(
int
corePoolSize,
int
maxPoolSize,
132
long
long
keepAliveTime,
const
TimeUnit
& unit,
133
BlockingQueue<decaf::lang::Runnable*>
* workQueue,
134
RejectedExecutionHandler
* handler);
135
166
ThreadPoolExecutor
(
int
corePoolSize,
int
maxPoolSize,
167
long
long
keepAliveTime,
const
TimeUnit
& unit,
168
BlockingQueue<decaf::lang::Runnable*>
* workQueue,
169
ThreadFactory
* threadFactory);
170
205
ThreadPoolExecutor
(
int
corePoolSize,
int
maxPoolSize,
206
long
long
keepAliveTime,
const
TimeUnit
& unit,
207
BlockingQueue<decaf::lang::Runnable*>
* workQueue,
208
ThreadFactory
* threadFactory,
209
RejectedExecutionHandler
* handler);
210
211
virtual
~
ThreadPoolExecutor
();
212
213
virtual
void
execute(
decaf::lang::Runnable
* task);
214
215
virtual
void
execute(
decaf::lang::Runnable
* task,
bool
takeOwnership);
216
217
virtual
void
shutdown();
218
219
virtual
ArrayList<decaf::lang::Runnable*>
shutdownNow();
220
221
virtual
bool
awaitTermination(
long
long
timeout,
const
decaf::util::concurrent::TimeUnit
& unit);
222
223
virtual
bool
isShutdown()
const
;
224
225
virtual
bool
isTerminated()
const
;
226
232
virtual
int
getPoolSize()
const
;
233
239
virtual
int
getCorePoolSize()
const
;
240
254
virtual
void
setCorePoolSize(
int
poolSize);
255
261
virtual
int
getMaximumPoolSize()
const
;
262
274
virtual
void
setMaximumPoolSize(
int
maxSize);
275
283
virtual
long
long
getTaskCount()
const
;
284
291
virtual
int
getActiveCount()
const
;
292
299
virtual
long
long
getCompletedTaskCount()
const
;
300
307
virtual
int
getLargestPoolSize()
const
;
308
316
virtual
BlockingQueue<decaf::lang::Runnable*>
* getQueue();
317
327
virtual
bool
isTerminating()
const
;
328
341
virtual
void
allowCoreThreadTimeout(
bool
value);
342
351
virtual
bool
allowsCoreThreadTimeout()
const
;
352
362
virtual
long
long
getKeepAliveTime(
const
TimeUnit
& unit)
const
;
363
377
virtual
void
setKeepAliveTime(
long
long
timeout,
const
TimeUnit
& unit);
378
390
virtual
void
setThreadFactory(
ThreadFactory
* factory);
391
398
virtual
ThreadFactory
* getThreadFactory()
const
;
399
405
virtual
RejectedExecutionHandler
* getRejectedExecutionHandler()
const
;
406
417
virtual
void
setRejectedExecutionHandler(
RejectedExecutionHandler
* handler);
418
427
virtual
bool
prestartCoreThread();
428
436
virtual
int
prestartAllCoreThreads();
437
447
bool
remove
(
decaf::lang::Runnable
* task);
448
456
virtual
void
purge();
457
458
protected
:
459
473
virtual
void
beforeExecute(
decaf::lang::Thread
* thread,
decaf::lang::Runnable
* task);
474
489
virtual
void
afterExecute(
decaf::lang::Runnable
* task,
decaf::lang::Throwable
* error);
490
496
virtual
void
terminated();
497
498
protected
:
499
503
virtual
void
onShutdown();
504
505
public
:
// RejectedExecutionHandler implementations.
506
513
class
AbortPolicy
:
public
RejectedExecutionHandler
{
514
public
:
515
516
AbortPolicy
() :
RejectedExecutionHandler
() {
517
}
518
519
virtual
~AbortPolicy
() {
520
}
521
522
virtual
void
rejectedExecution
(
decaf::lang::Runnable
* task,
ThreadPoolExecutor
* executer
DECAF_UNUSED
) {
523
delete
task;
524
throw
RejectedExecutionException
(__FILE__, __LINE__,
"Unable to execute task."
);
525
}
526
527
};
528
536
class
CallerRunsPolicy
:
public
RejectedExecutionHandler
{
537
public
:
538
539
CallerRunsPolicy
() :
RejectedExecutionHandler
() {
540
}
541
542
virtual
~CallerRunsPolicy
() {
543
}
544
545
virtual
void
rejectedExecution
(
decaf::lang::Runnable
* task,
ThreadPoolExecutor
* executer
DECAF_UNUSED
) {
546
547
if
(executer->isShutdown()) {
548
delete
task;
549
return
;
550
}
551
552
try
{
553
task->
run
();
554
delete
task;
555
}
catch
(
decaf::lang::Exception
& ex) {
556
delete
task;
557
throw
ex;
558
}
559
}
560
};
561
568
class
DiscardPolicy
:
public
RejectedExecutionHandler
{
569
public
:
570
571
DiscardPolicy
() :
RejectedExecutionHandler
() {
572
}
573
574
virtual
~DiscardPolicy
() {
575
}
576
577
virtual
void
rejectedExecution
(
decaf::lang::Runnable
* task,
ThreadPoolExecutor
* executer
DECAF_UNUSED
) {
578
delete
task;
579
}
580
581
};
582
590
class
DiscardOldestPolicy
:
public
RejectedExecutionHandler
{
591
public
:
592
593
DiscardOldestPolicy
() :
RejectedExecutionHandler
() {
594
}
595
596
virtual
~DiscardOldestPolicy
() {
597
}
598
599
virtual
void
rejectedExecution
(
decaf::lang::Runnable
* task,
ThreadPoolExecutor
* executer ) {
600
601
if
(executer->
isShutdown
()) {
602
delete
task;
603
return
;
604
}
605
606
try
{
607
608
decaf::lang::Runnable
* oldest =
NULL
;
609
executer->
getQueue
()->poll(oldest);
610
delete
oldest;
611
612
executer->
execute
(task);
613
}
catch
(
decaf::lang::Exception
& ex) {
614
delete
task;
615
throw
ex;
616
}
617
}
618
619
};
620
621
};
622
623
}}}
624
625
#endif
/*_DECAF_UTIL_CONCURRENT_THREADPOOLEXECUTOR_H_*/
src
main
decaf
util
concurrent
ThreadPoolExecutor.h
Generated on Mon Mar 4 2013 10:25:46 for activemq-cpp-3.6.0 by
1.8.1.2