I looked here in the OS only that I did not find anything like the doubt I have.
I have a Java program that uses Threads
.
public class Objeto
{
int i;
public Objeto() { i = 0; }
public void Foo()
{
i++;
System.out.println("Aqui " + i);
}
}
public class MinhaClasse
{
int a;
Objeto obj;
public MinhaClasse()
{
a = 0;
obj = new Objeto();
while(a < 5)
{
Runnable task = () -> {
FacaAlgo();
};
new Thread(task).start();
a++;
}
}
public void FacaAlgo()
{
obj.Foo();
}
}
Problem
When I instantiate an object of class MinhaClasse
it will start 5 threads that execute the same method ( FacaAlgo()
) of that object, and that it calls another method of another object ( obj.Foo()
). I would like to know if in this thread competition, by default, one thread waits for the other to enter and exit the FacaAlgo()
method or do I have to synchronized
?