So I have a superclass called Tile and many subclasses like BlueTile, GreenTile etc..
All instances of the different subclasses are stored in an ArrayList (eg. (blueTile1, blueTile2, greenTile1....)).
There is a method called "activateTile()" in the superclass, that all subclasses use in a different way.
Now when I loop trough the array and activate all blue Tiles with blueTile.activateTile() they will be activated one after another right?
How can I let all blueTiles in the Array call the method at the same time? Or is there a way to simply say "all instances of that class, do that method now"?
Thank you :)
Unless you intend to launch a new Thread per instance, they will always being running methods sequentially.
Do you intend something like this?
void activateInParallel() {
ArrayList<Thread> tileThreads = new ArrayList<>();
for(Tile t : allTiles) {
tileThreads .add(new Thread(()->t.activateTile()));
}
tileThreads.forEach(Thread::start);
}
I don't know enough details, but that is very likely not the best way to do it. I would consider using an Executor with a thread pool and offloading the work to it in a similar way.
Executor executor = Executors.newFixedThreadPool(8);
void activateInParallel() {
for(Tile t : allTiles) {
executor.execute(t::activateTile);
}
}
Firebase Cloud Functions: PubSub, "res.on is not a function"
TypeError: Cannot read properties of undefined (reading 'createMessageComponentCollector')
I have a spring boot applicate that is using many types of date objects it like:
I have a loop which goes through an array (files) of objects (person)If the person works as a doctor or a vet I would like to display their row at the top of the table, if not, they should be displayed under the doctors and vets
Like in other programing languages - python or JS, when we create a rest api specifically post for the request body we attract some JSON Object
I would like to write my company Jenkins Pipeline Library using Java not Groovy, as groovy is slower than JavaI tried to find examples of such Java Jenkins library source code, but I found only Groovy