Veröffentlicht 28. September 200915 j 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
28. September 200915 j 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
29. September 200915 j kann mir jemand erklären wie es hier zu einem Deadlockproblem kommen kannJa: Gar nicht!
Erstelle ein Konto oder melde dich an, um einen Kommentar zu schreiben.