1) Главная статья к прочтению:
March 2005: Article By Herb Sutter "The Free Lunch Is Over: A Fundamental Turn Toward Concurrency in Software" [http://www.gotw.ca/publications/concurrency-ddj.htm].
2) частично дублирует первую:
September 2005: Article By HERB SUTTER AND JAMES LARUS, MICROSOFT: "Software and the Concurrency Revolution" [http://portal.acm.org/citation.cfm?id=1095421]
3) Сложный текст, требующий комментариев, но за 3 страницы дает представление о горизонтах на ближайшие 5 лет:
September 2006: Sun expert David Dice, senior staff engineer(JVM) blog: "Parallelism Manifesto" [http://blogs.sun.com/dave/entry/parallelism_manifesto]
Прошу обратить внимание на фразу "Traditional concurrent programming has been error-prone and difficult, making it expensive and best left to a small priesthood of specialists."
Технические материалы:
1) Пожалуй, главная статья, которая показала, что JMM не соответствует "принципу наименьшего удивления" и нуждается в изменении. Практически авторский состав этой статьи и занимался New JMM для Java 5. В статье идет речь о реализации паттерна Singleton с помощью Double-Checked Locking.
"Double-Checked Locking is Broken" [http://www.cs.umd.edu/~pugh/java/memoryModel/DoubleCheckedLocking.html]
2) Одна из причин введения в Java 5 класса java.util.concurrent.LockSupport. Документация из JDK, объясняющая
"Why Are Thread.stop, Thread.suspend, Thread.resume and Runtime.runFinalizersOnExit Deprecated?" [http://java.sun.com/j2se/1.5.0/docs/guide/misc/threadPrimitiveDeprecation.html]
Примеры:
1) Использование флага для остановки потока взято из Joshua Bloch "Effective Java (second edition)", Item 66: Synchronize access to shared mutable data, page 259.
Цитата "You might expect this program to run for about a second, after which the main thread sets stopRequested to true, causing the background thread’s loop to terminate. On my machine, however, the program never terminates: the background thread loops forever!"
2) Сознательное отсутствие использования синхронизации при работе с разделяемыми данными(private int hash) из многих потоков:
java.lang.String.java:
public final class String ... {
...
/** Cache the hash code for the string */
private int hash; // Default to 0
...
/**
* Returns a hash code for this string. The hash code for a
* String object is computed as
* s[0]*31^(n-1) + s[1]*31^(n-2) + ... + s[n-1]
* using int arithmetic, where s[i] is the
* ith character of the string, n is the length of
* the string, and ^ indicates exponentiation.
* (The hash value of the empty string is zero.)
*
* @return a hash code value for this object.
*/
public int hashCode() {
int h = hash;
if (h == 0) {
int off = offset;
char val[] = value;
int len = count;
for (int i = 0; i < len; i++) {
h = 31*h + val[off++];
}
hash = h;
}
return h;
}
...
}
Golovach Ivan
Комментариев нет:
Отправить комментарий