I think it should execute 3 threads:
for (int i = 0; i < 3; i++)
pool.execute(new Counter(i));
or am I wrong?
--- Update ---
Type: Posts; User: Slapy
I think it should execute 3 threads:
for (int i = 0; i < 3; i++)
pool.execute(new Counter(i));
or am I wrong?
--- Update ---
oh am so sorry. I messed it up. It should be just 3 threads not 4 and it is just luck which thread will be selected. For example this is one of my outputs.
It is just simpl program that have to count form 0 to 50 and to do so have to use 3 threads and output have to be:
Thread 1: 0
Thread 0: 1
Thread 2: 2
Thread 2: 3
Thread 1: 4
...
Thread 0: 50
Yes, I was just asking if there is any way how to do it better.
So here is it after few changes I made:
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.atomic.AtomicInteger;
public class...
This are my two classes:
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
public class Main {
public static int number = 0;