-(ns thread-exec.core)
+(ns thread-exec.core
+  (:import 
+    [java.util.concurrent ThreadFactory BlockingQueue Callable ThreadPoolExecutor SynchronousQueue TimeUnit ExecutorService ThreadPoolExecutor$CallerRunsPolicy]))
+
+
+
+(defn- create-exec-service [threads]
+   (doto (ThreadPoolExecutor. 0 threads 60 TimeUnit/SECONDS (SynchronousQueue.))
+     (.setRejectedExecutionHandler  (ThreadPoolExecutor$CallerRunsPolicy.))))
+       
 
 (defn abs [n]
   (Math/abs ^int  n))

   otherwise the nearest group is used and its range is increased to include the new distance, i.e. its grown"
  (let [v (nearest-group t groups)
        d (distance t v)]
    
    (if (and (> d threshold) (< (count groups) max-groups))
      (let [m (max-value groups)
            v2 [m (+ m d threshold)]]
        [v2 (conj groups v2)])
      [v  groups])))             
    

  (reduce (partial nearest t) groups))

(defn max-value [groups]
  (reduce (fn [a1 [b1 b2]] (max a1 b1 b2)) 0 groups))


(defn select-group [t groups threshold max-groups]
