thread pool with waiting option

P

Philipp Kraus

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
 
M

markspace

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:

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

Philipp Kraus

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
 
M

markspace

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?
 
M

markspace

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

Jeff Higgins

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

Jeff Higgins

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

Josip Almasi

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

Jeff Higgins

Interesting article. Much appreciated.
Wow. I've been working on a project for a couple months now
that centers around a DSL. Using various tools, and kinda flopping
around, I haven't been real happy with the process or the progress
I've been making. Your post lead me to: <http://martinfowler.com/dsl.html>.
Pure gold for me...
Hope I can keep from carrying it to the ballgame tomorrow afternoon.
Thanks bunches.
 
M

markspace



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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top