1 6 21 22 package de.schlichtherle.io; 23 24 29 final class LegacyExecutor implements File.Executor { 30 private final String threadName; 31 32 37 public LegacyExecutor(String threadName) { 38 assert threadName != null; 39 this.threadName = threadName; 40 } 41 42 public File.Task submit(Runnable target) { 43 assert target != null; 44 return new LegacyTask(target, threadName); 45 } 46 47 private static final class LegacyTask implements File.Task { 48 private final Thread thread; 49 50 private LegacyTask(Runnable target, String threadName) { 51 assert target != null; 52 assert threadName != null; 53 thread = new Thread (target, threadName); 54 thread.start(); 55 } 56 57 public void cancel() { 58 thread.interrupt(); 59 while (true) { 60 try { 61 thread.join(); 62 break; 63 } catch (InterruptedException ignored) { 64 } 65 } 66 } 67 } 68 } 69 | Popular Tags |