public static void parallel(boolean forkSlowly, MyRunnable... rs) { MyFutureList list = new MyFutureList(); for (MyRunnable r : rs) forkAccm(list, forkSlowly, r); list.nowPause(); }
public static ThreadPoolExecutor getExecutorPool() { ThreadPoolExecutor tps = getTps(); if (tps == null) tps = startThreadPool(); return tps; }
public static void fork(List<?> list, boolean report, boolean forkSlowly, MyRunnable r) MyFutureList futures = new MyFutureList(); if (list.size() == 0) return; try clone = (MyRunnable) r.clone(); clone.o = list.get(0); clone.run(); while (getTaskCount() > threads / 2) EwThreading.sleep(10); MyRunnable clone; try clone = (MyRunnable) r.clone(); clone.o = list.get(i); clone.i = i; futures.add(fork(clone)); futures.nowPause(report);
public static void fork(int min, int lessthan, boolean report, MyRunnable r) { MyFutureList futures = new MyFutureList(); for (int i = min; i < lessthan; i++) { MyRunnable clone; try { clone = (MyRunnable) r.clone(); clone.i = i; futures.add(fork(clone)); } catch (CloneNotSupportedException e) { e.printStackTrace(); } } futures.nowPause(report); }
public static void fork(int min, int lessthan, MyRunnable r) { fork(min, lessthan, false, r); }
@Override public void run() { while (c.response != null) { EwThreading.sleep(1000); try { c.pw.print(' '); c.response.flushBuffer(); } catch (Exception ex) { c.abort = true; return; } } } });
public static void execSynchronous(MyFutureList placeToAdd, MyRunnable myRunnable) { myRunnable.run(); }
public static void invokeLater(Runnable runnable) { ThreadPoolExecutor tps = getTps(); if (tps == null) tps = startThreadPool(); try { tps.submit(runnable); } catch (RejectedExecutionException e) { invokeLater(runnable); } }
public void nowPause() { nowPause(false); }
private static ThreadPoolExecutor getTps() { int level = getThreadLevel(); if (tpses.size() <= level) return null; return tpses.get(level); }
public static void sendBroadcast(String buf) throws IOException { sendBroadcast(buf.getBytes(Charset.defaultCharset())); }
public static Future<?> fork(boolean forkSlowly, final MyRunnable r) { return fork(false, r, Integer.MAX_VALUE); }
@Override public T poll(long timeout, TimeUnit unit) throws InterruptedException { long nanos = unit.toNanos(timeout); long future = System.nanoTime() + nanos; while (System.nanoTime() < future) { T t = null; if ((t = super.poll()) == null) EwThreading.sleep(10); if (t != null) return t; } return null; }
public static void fork(List<?> list, boolean report, MyRunnable r) { fork(list, report, false, r); }
public static Future<?> fork(final MyRunnable r) { return fork(false, r, Integer.MAX_VALUE); }
public static void fork(List<?> list, MyRunnable r) { fork(list, false, false, r); }