public static Future<?> fork(boolean forkSlowly, final MyRunnable r, int forkLimit) ThreadPoolExecutor tps = getTps(); if (tps == null) tps = startThreadPool(); try while (getTaskCount(getThreadLevel()) > threads || getTaskCount(getThreadLevel()) > forkLimit) EwThreading.sleep(1); final int nextLevel = getThreadLevel() + 1; MyRunnable run = new MyRunnable() tpses.remove(getThreadLevel()); return fork(r);
public static void invokeLater(Runnable runnable) { ThreadPoolExecutor tps = getTps(); if (tps == null) tps = startThreadPool(); try { tps.submit(runnable); } catch (RejectedExecutionException e) { invokeLater(runnable); } }
public static ThreadPoolExecutor getExecutorPool() { ThreadPoolExecutor tps = getTps(); if (tps == null) tps = startThreadPool(); return tps; }
public static void fork(int min, int lessthan, MyRunnable r) { fork(min, lessthan, false, r); }
while (getTaskCount() > threads / 2) EwThreading.sleep(10); MyRunnable clone; try clone.o = list.get(i); clone.i = i; futures.add(fork(clone));
@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; } } } });
counter++; if (counter % 1000 == 0) log.debug(EwStringUtil.tabs(EwThreading.getThreadLevel()) + ": On " + counter + "/" + json.length()); MyRunnable r = new MyRunnable() if (threaded) EwThreading.forkAccm(fl, true, r,threadCap);
static synchronized ThreadPoolExecutor startThreadPool() if (getTps() != null) return getTps(); log.info("Using " + threads + " number of threads."); while (tpses.size() - 1 < getThreadLevel()) tpses.add(new ThreadPoolExecutor(threads, threads, 60L, TimeUnit.SECONDS, new ConcurrentBlockingQueue<Runnable>())); int level = tpses.size() - 1;
public static void parallel(boolean forkSlowly, MyRunnable... rs) { MyFutureList list = new MyFutureList(); for (MyRunnable r : rs) forkAccm(list, forkSlowly, r); list.nowPause(); }
private static ThreadPoolExecutor getTps() { int level = getThreadLevel(); if (tpses.size() <= level) return null; return tpses.get(level); }
public static void heartbeat() { if (System.currentTimeMillis() - lastHeartbeat < 5000) return; // log.debug("Heartbeating."); lastHeartbeat = System.currentTimeMillis(); try { String versionNumber = EwVersion.getVersion(); String tasks = Long.toString(EwThreading.getTaskCount()); if (mrs == null) mrs = new ArrayList<MapReduceServer>(); for (MapReduceServer mr : mrs) { // log.debug("Heartbeating. Sending broadcast packet for " + // mr.name); sendBroadcast(versionNumber.trim() + "\t" + tasks + "\t" + mr.name + "\t" + mr.port + "\t"); } } catch (IOException e) { System.out.println(e.getMessage()); } }
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; }
final int index = i; if (i > 0 && i % 1000 == 0) log.debug(EwStringUtil.tabs(EwThreading.getThreadLevel()) + ": On " + i + "/" + json.length()); if (sequenceI == -1 || sequenceMod == -1 || i % sequenceMod == sequenceI) if (threaded) EwThreading.forkAccm(fl, false, new MyRunnable()
EwThreading.forkAccm(mfl, true, new EwThreading.MyRunnable()
public static void fork(List<?> list, MyRunnable r) { fork(list, false, false, r); }
private void populateJob(LinkedHashMap<JobStatus, MapReduceStatus> job, Object o) { int i = 0; job.clear(); while (job.size() == 0) { while (MapReduceStatus.getWorkload(peers.get(i % peers.size()).host) > 10 || peers.get(i % peers.size()).notOK()) { if (i > peers.size()) checkup(peers.get(i % peers.size())); i++; if (i % peers.size() == 0) EwThreading.sleep(100); } MapReduceStatus peer = peers.get(i % peers.size()); JobStatus j = new JobStatus(); j.setI(1); j.setObject(o); j.setMod(1); j.setState(JobStatus.STATE.INCOMPLETE); job.put(j, peer); if (debug) log.info("Rerouting: Assigning " + j + " to " + peer); } }
public static void fork(List<?> list, boolean report, MyRunnable r) { fork(list, report, false, r); }
EwThreading.sleep(100);