00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifndef _DECAF_LANG_THREAD_H_
00018 #define _DECAF_LANG_THREAD_H_
00019
00020 #include <decaf/lang/exceptions/IllegalThreadStateException.h>
00021 #include <decaf/lang/exceptions/IllegalArgumentException.h>
00022 #include <decaf/lang/exceptions/InterruptedException.h>
00023 #include <decaf/lang/exceptions/RuntimeException.h>
00024 #include <decaf/lang/Exception.h>
00025 #include <decaf/lang/Runnable.h>
00026 #include <decaf/util/Config.h>
00027
00028 namespace decaf {
00029 namespace internal {
00030 namespace util {
00031 namespace concurrent {
00032 class Threading;
00033 struct ThreadHandle;
00034 }}}
00035 namespace lang {
00036
00037 class ThreadGroup;
00038 class ThreadProperties;
00039
00064 class DECAF_API Thread : public Runnable {
00065 private:
00066
00070 ThreadProperties* properties;
00071
00072 public:
00073
00075 static const int MIN_PRIORITY = 1;
00076
00078 static const int NORM_PRIORITY = 5;
00079
00081 static const int MAX_PRIORITY = 10;
00082
00084 enum State {
00085
00087 NEW = 0,
00088
00090 RUNNABLE = 1,
00091
00093 BLOCKED = 2,
00094
00096 WAITING = 3,
00097
00102 TIMED_WAITING = 4,
00103
00105 SLEEPING = 5,
00106
00108 TERMINATED = 6
00109
00110 };
00111
00112 public:
00113
00118 class UncaughtExceptionHandler {
00119 public:
00120
00121 virtual ~UncaughtExceptionHandler() {}
00122
00129 virtual void uncaughtException(const Thread* thread, const Throwable& error) = 0;
00130
00131 };
00132
00133 private:
00134
00135 Thread(const Thread&);
00136 Thread& operator=(const Thread&);
00137
00138 public:
00139
00146 Thread();
00147
00157 Thread(Runnable* task);
00158
00167 Thread(const std::string& name);
00168
00179 Thread(Runnable* task, const std::string& name);
00180
00200 Thread(Runnable* task, const std::string& name, long long stackSize);
00201
00202 virtual ~Thread();
00203
00212 virtual void start();
00213
00221 virtual void join();
00222
00233 virtual void join(long long millisecs);
00234
00247 virtual void join(long long millisecs, int nanos);
00248
00252 virtual void run();
00253
00260 long long getId() const;
00261
00266 std::string getName() const;
00267
00273 void setName(const std::string& name);
00274
00280 int getPriority() const;
00281
00290 void setPriority(int value);
00291
00297 UncaughtExceptionHandler* getUncaughtExceptionHandler() const;
00298
00305 void setUncaughtExceptionHandler(UncaughtExceptionHandler* handler);
00306
00312 std::string toString() const;
00313
00320 bool isAlive() const;
00321
00327 Thread::State getState() const;
00328
00341 void interrupt();
00342
00348 bool isInterrupted() const;
00349
00350 public:
00351
00364 static void sleep(long long millisecs);
00365
00381 static void sleep(long long millisecs, int nanos);
00382
00387 static void yield();
00388
00394 static Thread* currentThread();
00395
00403 static bool interrupted();
00404
00414 static UncaughtExceptionHandler* getDefaultUncaughtExceptionHandler();
00415
00424 static void setDefaultUncaughtExceptionHandler(UncaughtExceptionHandler* handler);
00425
00426 private:
00427
00428
00429 void initializeSelf(Runnable* task, const std::string& name, long long stackSize);
00430
00431
00432
00433 Thread(decaf::internal::util::concurrent::ThreadHandle* osThread);
00434
00435 private:
00436
00437
00438 decaf::internal::util::concurrent::ThreadHandle* getHandle() const;
00439
00440
00441 friend class decaf::internal::util::concurrent::Threading;
00442 friend class ThreadGroup;
00443
00444 };
00445
00446 }}
00447
00448 #endif