fabric-synctask #1

Merged
quentinlegot merged 10 commits from fabric-synctask into master 2023-02-13 15:26:38 +01:00
3 changed files with 13 additions and 9 deletions
Showing only changes of commit e9c97df089 - Show all commits

View File

@ -1,7 +1,6 @@
package fr.altarik.toolbox.task.async; package fr.altarik.toolbox.task.async;
import fr.altarik.toolbox.task.AltarikRunnable; import fr.altarik.toolbox.task.AltarikRunnable;
import fr.altarik.toolbox.task.TaskI;
import java.util.concurrent.ExecutorService; import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors; import java.util.concurrent.Executors;
@ -10,7 +9,7 @@ import java.util.concurrent.TimeUnit;
/** /**
* A non-blocking small sized time-consuming tasks to executed asynchronously. * A non-blocking small sized time-consuming tasks to executed asynchronously.
*/ */
public class AsyncTasks implements TaskI { public class AsyncTasks implements AsyncTaskI {
private final ExecutorService worker; private final ExecutorService worker;
@ -30,11 +29,11 @@ public class AsyncTasks implements TaskI {
* *
* @return an instance of AsyncTasks * @return an instance of AsyncTasks
*/ */
public static TaskI initialize(int numberOfWorker) { public static AsyncTaskI initialize(int numberOfWorker) {
return new AsyncTasks(numberOfWorker); return new AsyncTasks(numberOfWorker);
} }
public static TaskI initialize() { public static AsyncTaskI initialize() {
return initialize(Runtime.getRuntime().availableProcessors()); return initialize(Runtime.getRuntime().availableProcessors());
} }

View File

@ -1,7 +1,6 @@
package fr.altarik.toolbox; package fr.altarik.toolbox.task;
import fr.altarik.toolbox.task.AltarikRunnable; import fr.altarik.toolbox.task.async.AsyncTaskI;
import fr.altarik.toolbox.task.TaskI;
import fr.altarik.toolbox.task.async.AsyncTasks; import fr.altarik.toolbox.task.async.AsyncTasks;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
@ -21,7 +20,7 @@ class AsyncTaskTest {
void testAsyncOp() throws Exception { void testAsyncOp() throws Exception {
int numberOfTasks = 10000; int numberOfTasks = 10000;
System.out.println("Initializing async tasks worker"); System.out.println("Initializing async tasks worker");
TaskI worker = AsyncTasks.initialize(1); // only testing on a single worker, otherwise result have a high chance to not be in the order we want AsyncTaskI worker = AsyncTasks.initialize(1); // only testing on a single worker, otherwise result have a high chance to not be in the order we want
Stack<Integer> results = new Stack<>(); Stack<Integer> results = new Stack<>();
for(int i = 0; i < numberOfTasks; i++) { for(int i = 0; i < numberOfTasks; i++) {
System.out.println(log("sending task " + i)); System.out.println(log("sending task " + i));
@ -40,6 +39,5 @@ class AsyncTaskTest {
expected[i] = i; expected[i] = i;
} }
assertArrayEquals(expected, results.toArray()); assertArrayEquals(expected, results.toArray());
} }
} }

View File

@ -0,0 +1,7 @@
package fr.altarik.toolbox.task;
public class SyncTaskTest {
// TODO: 03/02/2023 Envoyé les tasks au workers grâce à un autre thread.
}