activemq-cpp-3.9.5
Thread.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_LANG_THREAD_H_
18#define _DECAF_LANG_THREAD_H_
19
25#include <decaf/lang/Runnable.h>
26#include <decaf/util/Config.h>
27
28namespace decaf {
29namespace internal {
30namespace util {
31namespace concurrent {
32 class Threading;
33 struct ThreadHandle;
34}}}
35namespace lang {
36
37 class ThreadGroup;
38 class ThreadProperties;
39
64 class DECAF_API Thread : public Runnable {
65 private:
66
70 ThreadProperties* properties;
71
72 public:
73
75 static const int MIN_PRIORITY = 1;
76
78 static const int NORM_PRIORITY = 5;
79
81 static const int MAX_PRIORITY = 10;
82
84 enum State {
85
87 NEW = 0,
88
91
94
97
103
106
109
110 };
111
112 public:
113
119 public:
120
122
129 virtual void uncaughtException(const Thread* thread, const Throwable& error) = 0;
130
131 };
132
133 private:
134
135 Thread(const Thread&);
136 Thread& operator=(const Thread&);
137
138 public:
139
147
158
167 Thread(const std::string& name);
168
179 Thread(Runnable* task, const std::string& name);
180
200 Thread(Runnable* task, const std::string& name, long long stackSize);
201
202 virtual ~Thread();
203
212 virtual void start();
213
221 virtual void join();
222
233 virtual void join(long long millisecs);
234
247 virtual void join(long long millisecs, int nanos);
248
252 virtual void run();
253
260 long long getId() const;
261
266 std::string getName() const;
267
273 void setName(const std::string& name);
274
280 int getPriority() const;
281
290 void setPriority(int value);
291
298
306
312 std::string toString() const;
313
320 bool isAlive() const;
321
328
341 void interrupt();
342
348 bool isInterrupted() const;
349
350 public:
351
364 static void sleep(long long millisecs);
365
381 static void sleep(long long millisecs, int nanos);
382
387 static void yield();
388
394 static Thread* currentThread();
395
403 static bool interrupted();
404
415
425
426 private:
427
428 // Initialize the Threads internal state
429 void initializeSelf(Runnable* task, const std::string& name, long long stackSize);
430
431 // Creates a Thread instance for a ThreadProperties pointer, used for
432 // wrapping OS threads
434
435 private:
436
437 // Allows the Threading class to get this thread objects handle.
439
440 // Allow some Decaf Classes greater access to the Thread class.
442 friend class ThreadGroup;
443
444 };
445
446}}
447
448#endif /*_DECAF_LANG_THREAD_H_*/
Interface for handlers invoked when a Thread abruptly terminates due to an uncaught exception.
Definition Thread.h:118
Interface for a runnable object - defines a task that can be run by a thread.
Definition Runnable.h:29
Interface for handlers invoked when a Thread abruptly terminates due to an uncaught exception.
Definition Thread.h:118
virtual ~UncaughtExceptionHandler()
Definition Thread.h:121
virtual void uncaughtException(const Thread *thread, const Throwable &error)=0
Method invoked when the given thread terminates due to the given uncaught exception.
Definition ThreadGroup.h:30
virtual void join(long long millisecs, int nanos)
Forces the Current Thread to wait until the thread exits.
void setPriority(int value)
Sets the current Thread's priority to the newly specified value.
std::string getName() const
Returns the Thread's assigned name.
Thread(Runnable *task, const std::string &name)
Constructs a new Thread with the given target Runnable task and name.
virtual void run()
Default implementation of the run method - does nothing.
Thread::State getState() const
Returns the currently set State of this Thread.
std::string toString() const
Returns a string that describes the Thread.
void interrupt()
Interrupts the Thread if it is blocked and in an interruptible state.
static UncaughtExceptionHandler * getDefaultUncaughtExceptionHandler()
Set the default handler invoked when a thread abruptly terminates due to an uncaught exception,...
static const int MAX_PRIORITY
The maximum priority that a thread can have.
Definition Thread.h:81
Thread()
Constructs a new Thread.
Thread(Runnable *task, const std::string &name, long long stackSize)
Constructs a new Thread with the given target Runnable task and name.
State
Represents the various states that the Thread can be in during its lifetime.
Definition Thread.h:84
@ NEW
Before a Thread is started it exists in this State.
Definition Thread.h:87
@ RUNNABLE
While a Thread is running and is not blocked it is in this State.
Definition Thread.h:90
@ TERMINATED
A Thread whose run method has exited is in this state.
Definition Thread.h:108
@ WAITING
A Thread that is waiting for another Thread to perform an action is in this state.
Definition Thread.h:96
@ SLEEPING
A Thread that is blocked in a Sleep call is in this state.
Definition Thread.h:105
@ BLOCKED
A Thread that is waiting to acquire a lock is in this state.
Definition Thread.h:93
@ TIMED_WAITING
A Thread that is waiting for another Thread to perform an action up to a specified time interval is i...
Definition Thread.h:102
Thread(const std::string &name)
Constructs a new Thread with the given name.
static const int MIN_PRIORITY
The minimum priority that a thread can have.
Definition Thread.h:75
virtual void join()
Forces the Current Thread to wait until the thread exits.
bool isAlive() const
Returns true if the Thread is alive, meaning it has been started and has not yet died.
void setName(const std::string &name)
Sets the name of the Thread to the new Name given by the argument name
void setUncaughtExceptionHandler(UncaughtExceptionHandler *handler)
Set the handler invoked when this thread abruptly terminates due to an uncaught exception.
int getPriority() const
Gets the currently set priority for this Thread.
static void setDefaultUncaughtExceptionHandler(UncaughtExceptionHandler *handler)
Set the default handler invoked when a thread abruptly terminates due to an uncaught exception,...
long long getId() const
Obtains the Thread Id of the current thread, this value is OS specific but is guaranteed not to chang...
static bool interrupted()
Returns whether the thread has been interrupted and clears the interrupted state such that a subseque...
UncaughtExceptionHandler * getUncaughtExceptionHandler() const
Set the handler invoked when this thread abruptly terminates due to an uncaught exception.
static const int NORM_PRIORITY
The default priority that a thread is given at create time.
Definition Thread.h:78
static void sleep(long long millisecs, int nanos)
Causes the currently executing thread to halt execution for the specified number of milliseconds plus...
virtual void start()
Creates a system thread and starts it in a joinable mode.
static void yield()
Causes the currently executing thread object to temporarily pause and allow other threads to execute.
static Thread * currentThread()
Returns a pointer to the currently executing thread object.
Thread(Runnable *task)
Constructs a new Thread with the given target Runnable task.
bool isInterrupted() const
Returns but does not clear the state of this Thread's interrupted flag.
friend class ThreadGroup
Definition Thread.h:442
static void sleep(long long millisecs)
Causes the currently executing thread to halt execution for the specified number of milliseconds,...
virtual void join(long long millisecs)
Forces the Current Thread to wait until the thread exits.
This class represents an error that has occurred.
Definition Throwable.h:44
#define DECAF_API
Definition Config.h:29
Definition Atomics.h:26
Definition ByteArrayAdapter.h:30
Definition AprPool.h:26
Definition ThreadingTypes.h:31
Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements.
Definition AprPool.h:25