Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #28014 > unrolled thread

thread pool with waiting option

Started byPhilipp Kraus <philipp.kraus@flashpixx.de>
First post2014-04-10 14:37 +0200
Last post2014-04-12 11:48 -0400
Articles 20 on this page of 23 — 4 participants

Back to article view | Back to comp.lang.java.programmer


Contents

  thread pool with waiting option Philipp Kraus <philipp.kraus@flashpixx.de> - 2014-04-10 14:37 +0200
    Re: thread pool with waiting option markspace <markspace@nospam.nospam> - 2014-04-10 08:36 -0700
      Re: thread pool with waiting option Philipp Kraus <philipp.kraus@flashpixx.de> - 2014-04-10 18:06 +0200
        Re: thread pool with waiting option markspace <markspace@nospam.nospam> - 2014-04-10 09:22 -0700
        Re: thread pool with waiting option Jeff Higgins <jeff@invalid.invalid> - 2014-04-11 12:40 -0400
    Re: thread pool with waiting option Jeff Higgins <jeff@invalid.invalid> - 2014-04-10 12:02 -0400
      Re: thread pool with waiting option Jeff Higgins <jeff@invalid.invalid> - 2014-04-10 12:40 -0400
        Re: thread pool with waiting option Jeff Higgins <jeff@invalid.invalid> - 2014-04-10 12:52 -0400
          Re: thread pool with waiting option Jeff Higgins <jeff@invalid.invalid> - 2014-04-10 15:31 -0400
            Re: thread pool with waiting option markspace <markspace@nospam.nospam> - 2014-04-11 08:16 -0700
              Re: thread pool with waiting option Jeff Higgins <jeff@invalid.invalid> - 2014-04-11 12:27 -0400
                Re: thread pool with waiting option markspace <markspace@nospam.nospam> - 2014-04-11 09:58 -0700
                  Re: thread pool with waiting option Jeff Higgins <jeff@invalid.invalid> - 2014-04-11 13:17 -0400
                    Re: thread pool with waiting option Jeff Higgins <jeff@invalid.invalid> - 2014-04-11 13:33 -0400
                      Re: thread pool with waiting option Jeff Higgins <jeff@invalid.invalid> - 2014-04-11 17:23 -0400
                    Re: thread pool with waiting option markspace <markspace@nospam.nospam> - 2014-04-12 16:24 -0700
                    Re: thread pool with waiting option markspace <markspace@nospam.nospam> - 2014-04-12 16:44 -0700
                      Re: thread pool with waiting option Jeff Higgins <jeff@invalid.invalid> - 2014-04-12 21:17 -0400
                        Re: thread pool with waiting option markspace <markspace@nospam.nospam> - 2014-04-12 20:12 -0700
    Re: thread pool with waiting option Josip Almasi <joe@vrspace.org> - 2014-04-12 14:00 +0200
      Re: thread pool with waiting option Josip Almasi <joe@vrspace.org> - 2014-04-12 14:01 +0200
        Re: thread pool with waiting option Jeff Higgins <jeff@invalid.invalid> - 2014-04-12 10:38 -0400
          Re: thread pool with waiting option Jeff Higgins <jeff@invalid.invalid> - 2014-04-12 11:48 -0400

Page 1 of 2  [1] 2  Next page →


#28014 — thread pool with waiting option

FromPhilipp Kraus <philipp.kraus@flashpixx.de>
Date2014-04-10 14:37 +0200
Subjectthread pool with waiting option
Message-ID<li63ac$1dqe$1@ariadne.rz.tu-clausthal.de>
Hello,

I would like to create a thread pool for a simulation environment. I 
use a pool with objects an each object must be run once in a time step, 
eg in pseudo code:

while (true)
{
     each thread in thread pool
     {
         get object from working list
     	object.run
         push object into finished list
     }
     wait for all threads are finished
     swap finished list with working list

     if user sends a wait signal
        wait
     if user sends a stop signal
     {
         clear working list
         clear finish list
         remove all threads
         break
    }
}

Which datastructures can be used in Java for this structure? IMHO I 
would like to use ExecutorService
but how can I create a pool which can be run again? In which way can I 
create a good and fast solution?

Hope for some ideas for this problem. Thanks a lot

Phil

[toc] | [next] | [standalone]


#28016

Frommarkspace <markspace@nospam.nospam>
Date2014-04-10 08:36 -0700
Message-ID<li6dpb$35o$1@dont-email.me>
In reply to#28014
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.


[toc] | [prev] | [next] | [standalone]


#28019

FromPhilipp Kraus <philipp.kraus@flashpixx.de>
Date2014-04-10 18:06 +0200
Message-ID<li6fhc$3mc$1@online.de>
In reply to#28016
On 2014-04-10 15:36:07 +0000, markspace said:

> 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.

this is a step-based simulation and I would like to create a pause / 
wait on a step.


> This appears to run each task sequentially.  Not much "multi-threading" 
> happening.

Each object in the simulation can run independed from the other object. 
I have got a large
number of objects which must be handled by the thread pool

> ?? Once a thread is finished, you want to run it again?  I don't think 
> this will work like you expect.

I have got a thread pool and all simulation objects must be processed 
by the threads in the pool and
if all objects have been processed, there must be a short wait, after 
that the algorithms starts again.
So on each simulation step all objects must be processed, than a 
barrier must wait for all working threads,
if all thread reaches the barrier, the next step begins.

Thx

Phil

[toc] | [prev] | [next] | [standalone]


#28020

Frommarkspace <markspace@nospam.nospam>
Date2014-04-10 09:22 -0700
Message-ID<li6ggj$oug$1@dont-email.me>
In reply to#28019
On 4/10/2014 9:06 AM, Philipp Kraus wrote:

>
> this is a step-based simulation and I would like to create a pause /
> wait on a step.

I really can't help you at all if I don't know something about the 
problem.  What *precisely* are you trying to simulate?

> Each object in the simulation can run independed from the other object.
> I have got a large
> number of objects which must be handled by the thread pool

This describes every single concurrency problem in existence.  So what?

>
> So on each simulation step all objects must be processed, than a barrier
> must wait for all working threads,
> if all thread reaches the barrier, the next step begins.

Well, you just said barrier.  Have you looked at those?


[toc] | [prev] | [next] | [standalone]


#28032

FromJeff Higgins <jeff@invalid.invalid>
Date2014-04-11 12:40 -0400
Message-ID<li964n$tb3$1@dont-email.me>
In reply to#28019
On 04/10/2014 12:06 PM, Philipp Kraus wrote:

> this is a step-based simulation and I would like to create a pause /
> wait on a step.
There is a PausableThreadPoolExecutor example in the Javadocs.
<http://docs.oracle.com/javase/8/docs/api/java/util/concurrent/ThreadPoolExecutor.html>
Don't know if it would help.

[toc] | [prev] | [next] | [standalone]


#28018

FromJeff Higgins <jeff@invalid.invalid>
Date2014-04-10 12:02 -0400
Message-ID<li6fgg$h13$1@dont-email.me>
In reply to#28014
On 04/10/2014 08:37 AM, Philipp Kraus wrote:
> Hello,
>
> I would like to create a thread pool for a simulation environment.

I think I would take a step up the abstraction ladder to start.
<http://activiti.org/> or something similar in your domain.

Alternatively:
<http://altair.cs.oswego.edu/mailman/listinfo/concurrency-interest>


[toc] | [prev] | [next] | [standalone]


#28021

FromJeff Higgins <jeff@invalid.invalid>
Date2014-04-10 12:40 -0400
Message-ID<li6hnm$1r1$1@dont-email.me>
In reply to#28018
On 04/10/2014 12:02 PM, Jeff Higgins wrote:
> On 04/10/2014 08:37 AM, Philipp Kraus wrote:
>> Hello,
>>
>> I would like to create a thread pool for a simulation environment.
>
> I think I would take a step up the abstraction ladder to start.
> <http://activiti.org/> or something similar in your domain.
>
> Alternatively:
> <http://altair.cs.oswego.edu/mailman/listinfo/concurrency-interest>
>
Or, java.util.concurrent.CompletionService<V> and thereabouts.


[toc] | [prev] | [next] | [standalone]


#28022

FromJeff Higgins <jeff@invalid.invalid>
Date2014-04-10 12:52 -0400
Message-ID<li6ier$8pb$1@dont-email.me>
In reply to#28021
On 04/10/2014 12:40 PM, Jeff Higgins wrote:
> Or, java.util.concurrent.CompletionService<V> and thereabouts.
<http://blog.teamlazerbeez.com/2009/04/29/java-completionservice/>

[toc] | [prev] | [next] | [standalone]


#28023

FromJeff Higgins <jeff@invalid.invalid>
Date2014-04-10 15:31 -0400
Message-ID<li6rp2$l8s$1@dont-email.me>
In reply to#28022
On 04/10/2014 12:52 PM, Jeff Higgins wrote:
> On 04/10/2014 12:40 PM, Jeff Higgins wrote:
>> Or, java.util.concurrent.CompletionService<V> and thereabouts.
> <http://blog.teamlazerbeez.com/2009/04/29/java-completionservice/>
>
>
Future reference. A memento for me.
<http://www.nurkiewicz.com/2013/05/java-8-definitive-guide-to.html>
<http://www.nurkiewicz.com/2013/05/java-8-completablefuture-in-action.html>

[toc] | [prev] | [next] | [standalone]


#28029

Frommarkspace <markspace@nospam.nospam>
Date2014-04-11 08:16 -0700
Message-ID<li9109$k0p$1@dont-email.me>
In reply to#28023
On 4/10/2014 12:31 PM, Jeff Higgins wrote:
> Future reference. A memento for me.
> <http://www.nurkiewicz.com/2013/05/java-8-definitive-guide-to.html>
> <http://www.nurkiewicz.com/2013/05/java-8-completablefuture-in-action.html>
>


A video on new Java 8 features (warning: makes noise):

https://www.youtube.com/watch?v=DCBIegEqKuo

Note especially the updates to concurrency, including a map-reduce 
framework with lazy concurrency that is part of Collections now.

Plus sorting arrays in parallel now.

[toc] | [prev] | [next] | [standalone]


#28031

FromJeff Higgins <jeff@invalid.invalid>
Date2014-04-11 12:27 -0400
Message-ID<li95cb$nmk$1@dont-email.me>
In reply to#28029
On 04/11/2014 11:16 AM, markspace wrote:

> A video on new Java 8 features
>
I'm guessing that
<http://gpars.codehaus.org/>, <http://akka.io/>
are high overkill for Philipp Kraus' purposes.

[toc] | [prev] | [next] | [standalone]


#28033

Frommarkspace <markspace@nospam.nospam>
Date2014-04-11 09:58 -0700
Message-ID<li970j$4h2$1@dont-email.me>
In reply to#28031
On 4/11/2014 9:27 AM, Jeff Higgins wrote:
> On 04/11/2014 11:16 AM, markspace wrote:
>
>> A video on new Java 8 features
>>
> I'm guessing that
> <http://gpars.codehaus.org/>, <http://akka.io/>
> are high overkill for Philipp Kraus' purposes.
>


I'm honestly still not sure what his purpose is.  There's some messages 
from a Philipp Kraus about 2 years ago on a Lua list asking almost the 
same question as he did here.

And there's a project on GitHub by a person of the same name, with 
almost the same idea, but there's no code yet (according to the 
documentation, I didn't dig through all the files) after again 2 years.

https://github.com/flashpixx/ParallelMultiAgentSimulation

I think Phil needs to get his thoughts in order first, to be honest. 
He's just (barely) hacking at this, and it doesn't look like an easy 
problem.

[toc] | [prev] | [next] | [standalone]


#28034

FromJeff Higgins <jeff@invalid.invalid>
Date2014-04-11 13:17 -0400
Message-ID<li988r$eno$1@dont-email.me>
In reply to#28033
On 04/11/2014 12:58 PM, markspace wrote:
> On 4/11/2014 9:27 AM, Jeff Higgins wrote:
>> On 04/11/2014 11:16 AM, markspace wrote:
>>
>>> A video on new Java 8 features
>>>
>> I'm guessing that
>> <http://gpars.codehaus.org/>, <http://akka.io/>
>> are high overkill for Philipp Kraus' purposes.
>>
>
>
> I'm honestly still not sure what his purpose is.  There's some messages
> from a Philipp Kraus about 2 years ago on a Lua list asking almost the
> same question as he did here.
>
> And there's a project on GitHub by a person of the same name, with
> almost the same idea, but there's no code yet (according to the
> documentation, I didn't dig through all the files) after again 2 years.
>
> https://github.com/flashpixx/ParallelMultiAgentSimulation

A wwhole bunch of code.
https://mecdev.rz-housing.tu-clausthal.de/gitlab/desim/maserati/blob/master/README.md

Maybe he's preparing a Java fork.

>
> I think Phil needs to get his thoughts in order first, to be honest.
> He's just (barely) hacking at this, and it doesn't look like an easy
> problem.
>
>
Huh. java+multiagent seems to be a popular kinda project. Thanks.

[toc] | [prev] | [next] | [standalone]


#28035

FromJeff Higgins <jeff@invalid.invalid>
Date2014-04-11 13:33 -0400
Message-ID<li996h$lr0$1@dont-email.me>
In reply to#28034
On 04/11/2014 01:17 PM, Jeff Higgins wrote:

> Huh. java+multiagent seems to be a popular kinda project. Thanks.
Now I find myself weighing Actors on the one hand with Agents on the 
other. Whew.
Thankfully,
<http://stackoverflow.com/questions/15295504/what-is-the-difference-between-actors-akka-and-agents-jade-in-distributed-sy>
is enough for me.

[toc] | [prev] | [next] | [standalone]


#28036

FromJeff Higgins <jeff@invalid.invalid>
Date2014-04-11 17:23 -0400
Message-ID<li9mnf$riu$1@dont-email.me>
In reply to#28035
On 04/11/2014 01:33 PM, Jeff Higgins wrote:
> Now I find myself weighing Actors on the one hand with Agents on the
> other. Whew.
> Thankfully,
> is enough for me.

Well, almost. Now I go to Wikipedia, Actor Model, Agent Model
and learn that perhaps one might use an Actor model implementation
to implement an Agent model system. Or such.
?? Either way I'm glad baseball seasons' started.

[toc] | [prev] | [next] | [standalone]


#28047

Frommarkspace <markspace@nospam.nospam>
Date2014-04-12 16:24 -0700
Message-ID<lici09$dp3$1@dont-email.me>
In reply to#28034
On 4/11/2014 10:17 AM, Jeff Higgins wrote:

> A wwhole bunch of code.
> https://mecdev.rz-housing.tu-clausthal.de/gitlab/desim/maserati/blob/master/README.md
>
>
> Maybe he's preparing a Java fork.


Yup, possible.  Someone of the same name is listed on the wiki 
maintainers page.

https://mecdev.rz-housing.tu-clausthal.de/gitlab/desim/maserati/wikis/home

I sure wish he could have posted some of the things they are going to 
simulate though.  I don't relish going through an entire code base just 
to work out what question he was asking.

[toc] | [prev] | [next] | [standalone]


#28048

Frommarkspace <markspace@nospam.nospam>
Date2014-04-12 16:44 -0700
Message-ID<licj4s$jlm$1@dont-email.me>
In reply to#28034
On 4/11/2014 10:17 AM, Jeff Higgins wrote:

> A wwhole bunch of code.
> https://mecdev.rz-housing.tu-clausthal.de/gitlab/desim/maserati/blob/master/README.md
>
>
> Maybe he's preparing a Java fork.

A academic paper (perhaps a thesis), here (warning: ridiculous series of 
sign-up pages required):

http://www.academia.edu/6711713/A_scalable_runtime_platform_for_multiagent-based_simulation#

Looks like he's simulating traffic, and herding cows.  But the paper 
makes reference to an existing Java system, so it's odd to me that he's 
asking here for basic "data structures," and with out any real code to show.

Also if he's getting free code from me I want credit on any future 
papers. :-p

[toc] | [prev] | [next] | [standalone]


#28049

FromJeff Higgins <jeff@invalid.invalid>
Date2014-04-12 21:17 -0400
Message-ID<licop8$j6k$1@dont-email.me>
In reply to#28048
On 04/12/2014 07:44 PM, markspace wrote:
> Looks like he's simulating traffic, and herding cows.
Hmm. A lot going on there. Now seems like a naive question coming
from some who collaborated on such a system.
Either way, I hope this thread has been as fruitful for him as it
has been for me.

[toc] | [prev] | [next] | [standalone]


#28052

Frommarkspace <markspace@nospam.nospam>
Date2014-04-12 20:12 -0700
Message-ID<licvan$iqr$1@dont-email.me>
In reply to#28049
On 4/12/2014 6:17 PM, Jeff Higgins wrote:

> On 04/12/2014 07:44 PM, markspace wrote:
>> Looks like he's simulating traffic, and herding cows.

> Hmm. A lot going on there. Now seems like a naive question coming
> from some who collaborated on such a system.


Right.  I'm starting to think it might not be the same person, and 
possibly someone not using their real name.

[toc] | [prev] | [next] | [standalone]


#28041

FromJosip Almasi <joe@vrspace.org>
Date2014-04-12 14:00 +0200
Message-ID<53492ADC.8020509@vrspace.org>
In reply to#28014
Hi,

think you could use Disruptors.
However, do not think in 'thread' terms, think producer/consumer.
Do not think 'get object from list', think 'receive event'.

HTH;)

Regards...

On 04/10/2014 02:37 PM, Philipp Kraus wrote:
> Hello,
>
> I would like to create a thread pool for a simulation environment. I use
> a pool with objects an each object must be run once in a time step, eg
> in pseudo code:
>
> while (true)
> {
>      each thread in thread pool
>      {
>          get object from working list
>          object.run
>          push object into finished list
>      }
>      wait for all threads are finished
>      swap finished list with working list
>
>      if user sends a wait signal
>         wait
>      if user sends a stop signal
>      {
>          clear working list
>          clear finish list
>          remove all threads
>          break
>     }
> }
>
> Which datastructures can be used in Java for this structure? IMHO I
> would like to use ExecutorService
> but how can I create a pool which can be run again? In which way can I
> create a good and fast solution?
>
> Hope for some ideas for this problem. Thanks a lot
>
> Phil
>
>

[toc] | [prev] | [next] | [standalone]


Page 1 of 2  [1] 2  Next page →

Back to top | Article view | comp.lang.java.programmer


csiph-web