Aysa Geschrieben 28. September 2009 Geschrieben 28. September 2009 Hi, kann mir jemand erklären wie es hier zu einem Deadlockproblem kommen kann, also ohne das ich ich die Methoden (put,get)Synchronisiert habe? public class BoundedQueue { private List data = new ArrayList(); public boolean isEmpty() { return data.isEmpty(); } public void put(Object x) { data.add(x); } public Object get() { return data.remove(0); } } Merci
kingofbrain Geschrieben 28. September 2009 Geschrieben 28. September 2009 Schau doch mal in die API Doc der Klasse ArrayList, dort steht folgendes (Version 1.4.2, das war der erste Google Treffer, privat habe ich die API Doc nicht gebookmarked): Note that this implementation is not synchronized. If multiple threads access an ArrayList instance concurrently, and at least one of the threads modifies the list structurally, it must be synchronized externally. (A structural modification is any operation that adds or deletes one or more elements, or explicitly resizes the backing array; merely setting the value of an element is not a structural modification.) This is typically accomplished by synchronizing on some object that naturally encapsulates the list. If no such object exists, the list should be "wrapped" using the Collections.synchronizedList method. This is best done at creation time, to prevent accidental unsynchronized access to the list: List list = Collections.synchronizedList(new ArrayList(...)); Peter
flashpixx Geschrieben 28. September 2009 Geschrieben 28. September 2009 Wäre ja auch zu schwer: Deadlock ? Wikipedia
perdian Geschrieben 29. September 2009 Geschrieben 29. September 2009 kann mir jemand erklären wie es hier zu einem Deadlockproblem kommen kannJa: Gar nicht!
Empfohlene Beiträge
Erstelle ein Benutzerkonto oder melde Dich an, um zu kommentieren
Du musst ein Benutzerkonto haben, um einen Kommentar verfassen zu können
Benutzerkonto erstellen
Neues Benutzerkonto für unsere Community erstellen. Es ist einfach!
Neues Benutzerkonto erstellenAnmelden
Du hast bereits ein Benutzerkonto? Melde Dich hier an.
Jetzt anmelden