Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: markspace Newsgroups: comp.lang.java.programmer Subject: Re: thread pool with waiting option Date: Thu, 10 Apr 2014 08:36:07 -0700 Organization: A noiseless patient Spider Lines: 53 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Thu, 10 Apr 2014 15:36:11 +0000 (UTC) Injection-Info: mx05.eternal-september.org; posting-host="9358cda03e1e0dfd3c4b757daa608707"; logging-data="3256"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX185DxEQTAOqlQ7In0WRn16Rw3/A9C0DB+w=" User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:24.0) Gecko/20100101 Thunderbird/24.4.0 In-Reply-To: Cancel-Lock: sha1:IzRdBwlbQtxEkrQh8e4WeBY4UfA= Xref: csiph.com comp.lang.java.programmer:28016 What's your goal here? What are you actually trying to accomplish or simulate? It looks to me like you want something similar to fork/join, but your question only has a single implementation and no other clues as to what is going on. Random comments inline: On 4/10/2014 5:37 AM, Philipp Kraus wrote: > > while (true) > { > each thread in thread pool > { > get object from working list > object.run > push object into finished list > } This appears to run each task sequentially. Not much "multi-threading" happening. > wait for all threads are finished > swap finished list with working list ?? Once a thread is finished, you want to run it again? I don't think this will work like you expect. > > if user sends a wait signal > wait > if user sends a stop signal Use Thread.interrupt() to stop a thread. If you don't do any IO you'll have to poll it yourself. > { > clear working list > clear finish list > remove all threads > break > } > } > > Which datastructures can be used in Java for this structure? IMHO I Your ideas are funky and I doubt there's one that can be used directly. You may have to extend AbstractExecutor and just roll your own.