Habe mal ne Frage, und zwar habe ich dieses Singleton:
Wenn ich jetzt mehrere Threads habe welche nun auf die Methoden "addObject", "removeObject" und "getCurrentListSize" zugreifen, sind diese Abläufe dann auch noch synchronisiert? Muss ich etwa die Methoden ebenfalls "synchronized" machen?
Code:
package test;
import java.util.ArrayList;
public class Singleton {
private static Singleton INSTANCE = new Singleton();
private static ArrayList myList = new ArrayList();
public void addObject(int wert)
{
myList.add(wert);
}
public void removeObject(int index)
{
myList.remove(index);
}
public int getCurrentListSize()
{
return myList.size();
}
private Singleton()
{
}
public static synchronized Singleton getInstance()
{
return INSTANCE;
}
}
Wenn ich jetzt mehrere Threads habe welche nun auf die Methoden "addObject", "removeObject" und "getCurrentListSize" zugreifen, sind diese Abläufe dann auch noch synchronisiert? Muss ich etwa die Methoden ebenfalls "synchronized" machen?