- Timestamp:
- 06/24/13 13:38:40 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
java/main/src/main/java/com/framsticks/util/dispatching/Thread.java
r84 r85 5 5 import java.util.LinkedList; 6 6 import java.util.ListIterator; 7 import com.framsticks.util.dispatching.RunAt; 7 8 8 9 /** 9 10 * @author Piotr Sniegowski 10 11 */ 11 public class Thread implements Dispatcher{12 public class Thread<C> implements Dispatcher<C> { 12 13 13 14 private static final Logger log = Logger.getLogger(Thread.class.getName()); … … 15 16 protected final java.lang.Thread thread; 16 17 17 private final LinkedList<Task > queue = new LinkedList<Task>();18 private final LinkedList<Task<? extends C>> queue = new LinkedList<>(); 18 19 19 20 public Thread() { 20 thread = new java.lang.Thread(new Runnable() {21 thread = new java.lang.Thread(new java.lang.Runnable() { 21 22 @Override 22 23 public void run() { … … 25 26 }); 26 27 } 28 27 29 public Thread(String s) { 28 30 this(); 29 31 thread.setName(s); 30 thread.start();32 // thread.start(); 31 33 } 32 34 … … 34 36 this.thread = thread; 35 37 thread.setName(s); 38 } 39 40 public Thread<C> start() { 41 thread.start(); 42 return this; 36 43 } 37 44 … … 43 50 protected void routine() { 44 51 while (!java.lang.Thread.interrupted()) { 45 Task task;52 Task<? extends C> task; 46 53 synchronized (queue) { 47 54 if (queue.isEmpty()) { … … 74 81 } 75 82 76 protected void enqueueTask(Task task) {83 protected void enqueueTask(Task<? extends C> task) { 77 84 synchronized (queue) { 78 ListIterator<Task > i = queue.listIterator();85 ListIterator<Task<? extends C>> i = queue.listIterator(); 79 86 while (i.hasNext()) { 80 Task t = i.next();87 Task<? extends C> t = i.next(); 81 88 if (t.getMoment() > task.getMoment()) { 82 89 i.previous(); … … 104 111 105 112 @Override 106 public void invokeLater(final Run nablerunnable) {113 public void invokeLater(final RunAt<? extends C> runnable) { 107 114 if (!(runnable instanceof Task)) { 108 enqueueTask(new Task () {115 enqueueTask(new Task<C>() { 109 116 @Override 110 117 public void run() { … … 114 121 return; 115 122 } 116 enqueueTask((Task )runnable);123 enqueueTask((Task<? extends C>) runnable); 117 124 } 118 125 … … 125 132 } 126 133 127 public void start() {128 thread.start();129 }130 131 134 public void setName(String name) { 132 135 thread.setName(name); 133 136 134 137 } 138 139 public static boolean interrupted() { 140 return java.lang.Thread.interrupted(); 141 } 135 142 }
Note: See TracChangeset
for help on using the changeset viewer.