oxedyne/fe2o3/fe2o3_text/tests/detect_corpus/java/annotations.txt
1.2 KiB, 1 run
created by r1870400018:11984, which is this file's identity for as long as the history lasts, whatever it is later renamed to
download · who wrote it · its history
| 1 | import java.util.List; |
| 2 | import java.util.ArrayList; |
| 3 | import java.util.Collections; |
| 4 | |
| 5 | public class TaskQueue { |
| 6 | |
| 7 | private final List<Runnable> tasks = new ArrayList<>(); |
| 8 | private volatile boolean shutdown = false; |
| 9 | |
| 10 | @SuppressWarnings("unchecked") |
| 11 | public synchronized void submit(Runnable task) { |
| 12 | if (shutdown) { |
| 13 | throw new IllegalStateException("queue is shut down"); |
| 14 | } |
| 15 | tasks.add(task); |
| 16 | } |
| 17 | |
| 18 | @Override |
| 19 | public synchronized String toString() { |
| 20 | return String.format("TaskQueue[%d pending, shutdown=%b]", |
| 21 | tasks.size(), shutdown); |
| 22 | } |
| 23 | |
| 24 | @Deprecated |
| 25 | public void runAll() { |
| 26 | List<Runnable> snapshot; |
| 27 | synchronized (this) { |
| 28 | snapshot = new ArrayList<>(tasks); |
| 29 | tasks.clear(); |
| 30 | } |
| 31 | for (Runnable task : snapshot) { |
| 32 | try { |
| 33 | task.run(); |
| 34 | } catch (Exception e) { |
| 35 | System.err.println("task failed: " + e.getMessage()); |
| 36 | } |
| 37 | } |
| 38 | } |
| 39 | |
| 40 | public synchronized void shutdown() { |
| 41 | this.shutdown = true; |
| 42 | } |
| 43 | |
| 44 | public synchronized List<Runnable> pending() { |
| 45 | return Collections.unmodifiableList(new ArrayList<>(tasks)); |
| 46 | } |
| 47 | } |