activemq-cpp-3.8.2
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 
24 #include <decaf/lang/Exception.h>
25 #include <decaf/lang/Runnable.h>
26 #include <decaf/util/Config.h>
27 
28 namespace decaf {
29 namespace internal {
30 namespace util {
31 namespace concurrent {
32  class Threading;
33  struct ThreadHandle;
34 }}}
35 namespace 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 
90  RUNNABLE = 1,
91 
93  BLOCKED = 2,
94 
96  WAITING = 3,
97 
102  TIMED_WAITING = 4,
103 
105  SLEEPING = 5,
106 
108  TERMINATED = 6
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 
146  Thread();
147 
157  Thread(Runnable* task);
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 
297  UncaughtExceptionHandler* getUncaughtExceptionHandler() const;
298 
305  void setUncaughtExceptionHandler(UncaughtExceptionHandler* handler);
306 
312  std::string toString() const;
313 
320  bool isAlive() const;
321 
327  Thread::State getState() const;
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 
414  static UncaughtExceptionHandler* getDefaultUncaughtExceptionHandler();
415 
424  static void setDefaultUncaughtExceptionHandler(UncaughtExceptionHandler* handler);
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_*/
This class represents an error that has occurred.
Definition: Throwable.h:44
virtual ~UncaughtExceptionHandler()
Definition: Thread.h:121
Interface for handlers invoked when a Thread abruptly terminates due to an uncaught exception...
Definition: Thread.h:118
A Thread is a concurrent unit of execution.
Definition: Thread.h:64
#define DECAF_API
Definition: Config.h:29
Interface for a runnable object - defines a task that can be run by a thread.
Definition: Runnable.h:29
Definition: ThreadGroup.h:30
State
Represents the various states that the Thread can be in during its lifetime.
Definition: Thread.h:84
Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements...
Definition: AprPool.h:25