Guest User

Untitled

a guest
Jan 21st, 2018
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.84 KB | None | 0 0
  1. Runnable myRunnable = new MyRunnableObject();
  2. new Thread(myRunnable).start();
  3. //синхронизация внутреннего состояния MyRunnableObject по вкусу
  4. new Thread(myRunnable).start();
  5. ...
  6.  
  7. /**
  8. * A representation of a thread's state. A given thread may only be in one
  9. * state at a time.
  10. */
  11. public enum State {
  12. /**
  13. * The thread has been created, but has never been started.
  14. */
  15. NEW,
  16. /**
  17. * The thread may be run.
  18. */
  19. RUNNABLE,
  20. /**
  21. * The thread is blocked and waiting for a lock.
  22. */
  23. BLOCKED,
  24. /**
  25. * The thread is waiting.
  26. */
  27. WAITING,
  28. /**
  29. * The thread is waiting for a specified amount of time.
  30. */
  31. TIMED_WAITING,
  32. /**
  33. * The thread has been terminated.
  34. */
  35. TERMINATED
  36. }
  37.  
  38. public synchronized void start() {
  39. /**
  40. * This method is not invoked for the main method thread or "system"
  41. * group threads created/set up by the VM. Any new functionality added
  42. * to this method in the future may have to also be added to the VM.
  43. *
  44. * A zero status value corresponds to state "NEW".
  45. */
  46. // Android-changed: throw if 'started' is true
  47. if (threadStatus != 0 || started)
  48. throw new IllegalThreadStateException();
  49.  
  50. /* Notify the group that this thread is about to be started
  51. * so that it can be added to the group's list of threads
  52. * and the group's unstarted count can be decremented. */
  53. group.add(this);
  54.  
  55. started = false;
  56. try {
  57. nativeCreate(this, stackSize, daemon);
  58. started = true;
  59. } finally {
  60. try {
  61. if (!started) {
  62. group.threadStartFailed(this);
  63. }
  64. } catch (Throwable ignore) {
  65. /* do nothing. If start0 threw a Throwable then
  66. it will be passed up the call stack */
  67. }
  68. }
  69. }
Add Comment
Please, Sign In to add comment