<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="ru">
		<id>http://www.jexp.ru/index.php?action=history&amp;feed=atom&amp;title=Java_by_API%2Fjava.util.concurrent.locks%2FLock</id>
		<title>Java by API/java.util.concurrent.locks/Lock - История изменений</title>
		<link rel="self" type="application/atom+xml" href="http://www.jexp.ru/index.php?action=history&amp;feed=atom&amp;title=Java_by_API%2Fjava.util.concurrent.locks%2FLock"/>
		<link rel="alternate" type="text/html" href="http://www.jexp.ru/index.php?title=Java_by_API/java.util.concurrent.locks/Lock&amp;action=history"/>
		<updated>2026-04-26T04:37:02Z</updated>
		<subtitle>История изменений этой страницы в вики</subtitle>
		<generator>MediaWiki 1.30.0</generator>

	<entry>
		<id>http://www.jexp.ru/index.php?title=Java_by_API/java.util.concurrent.locks/Lock&amp;diff=408&amp;oldid=prev</id>
		<title> в 17:43, 31 мая 2010</title>
		<link rel="alternate" type="text/html" href="http://www.jexp.ru/index.php?title=Java_by_API/java.util.concurrent.locks/Lock&amp;diff=408&amp;oldid=prev"/>
				<updated>2010-05-31T17:43:48Z</updated>
		
		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;table class=&quot;diff diff-contentalign-left&quot; data-mw=&quot;interface&quot;&gt;
				&lt;tr style=&quot;vertical-align: top;&quot; lang=&quot;ru&quot;&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;← Предыдущая&lt;/td&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;Версия 17:43, 31 мая 2010&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; style=&quot;text-align: center;&quot; lang=&quot;ru&quot;&gt;&lt;div class=&quot;mw-diff-empty&quot;&gt;(нет различий)&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;</summary>
			</entry>

	<entry>
		<id>http://www.jexp.ru/index.php?title=Java_by_API/java.util.concurrent.locks/Lock&amp;diff=409&amp;oldid=prev</id>
		<title>Admin: 1 версия</title>
		<link rel="alternate" type="text/html" href="http://www.jexp.ru/index.php?title=Java_by_API/java.util.concurrent.locks/Lock&amp;diff=409&amp;oldid=prev"/>
				<updated>2010-05-31T14:16:45Z</updated>
		
		<summary type="html">&lt;p&gt;1 версия&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Новая страница&lt;/b&gt;&lt;/p&gt;&lt;div&gt;== Lock: lock() ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- start source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
    &amp;lt;source lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
  &lt;br /&gt;
/*&lt;br /&gt;
License for Java 1.5 &amp;quot;Tiger&amp;quot;: A Developer&amp;quot;s Notebook&lt;br /&gt;
     (O&amp;quot;Reilly) example package&lt;br /&gt;
Java 1.5 &amp;quot;Tiger&amp;quot;: A Developer&amp;quot;s Notebook (O&amp;quot;Reilly) &lt;br /&gt;
by Brett McLaughlin and David Flanagan.&lt;br /&gt;
ISBN: 0-596-00738-8&lt;br /&gt;
You can use the examples and the source code any way you want, but&lt;br /&gt;
please include a reference to where it comes from if you use it in&lt;br /&gt;
your own products or services. Also note that this software is&lt;br /&gt;
provided by the author &amp;quot;as is&amp;quot;, with no expressed or implied warranties. &lt;br /&gt;
In no event shall the author be liable for any direct or indirect&lt;br /&gt;
damages arising in any way out of the use of this software.&lt;br /&gt;
*/&lt;br /&gt;
&lt;br /&gt;
import java.util.concurrent.locks.Condition;&lt;br /&gt;
import java.util.concurrent.locks.Lock;&lt;br /&gt;
import java.util.concurrent.locks.ReentrantLock;&lt;br /&gt;
 class LinkList&amp;lt;E&amp;gt; {&lt;br /&gt;
  // The value of this node&lt;br /&gt;
  E value;&lt;br /&gt;
  // The rest of the list&lt;br /&gt;
  LinkList&amp;lt;E&amp;gt; rest;&lt;br /&gt;
 &lt;br /&gt;
  // A lock for this node&lt;br /&gt;
  Lock lock;&lt;br /&gt;
  // Signals when the value of this node changes&lt;br /&gt;
  Condition valueChanged;&lt;br /&gt;
  // Signals when the node this is connected to changes&lt;br /&gt;
  Condition linkChanged;&lt;br /&gt;
  public LinkList(E value) {&lt;br /&gt;
    this.value = value;&lt;br /&gt;
    rest = null;&lt;br /&gt;
    lock = new ReentrantLock();&lt;br /&gt;
    valueChanged = lock.newCondition();&lt;br /&gt;
    linkChanged = lock.newCondition();&lt;br /&gt;
  }&lt;br /&gt;
  public void setValue(E value) {&lt;br /&gt;
    lock.lock();&lt;br /&gt;
    try {&lt;br /&gt;
      this.value = value;&lt;br /&gt;
      // Let waiting threads that the value has changed&lt;br /&gt;
      valueChanged.signalAll();&lt;br /&gt;
    } finally {&lt;br /&gt;
      lock.unlock();&lt;br /&gt;
    }&lt;br /&gt;
  }&lt;br /&gt;
  public void executeOnValue(E desiredValue, Runnable task)&lt;br /&gt;
    throws InterruptedException {&lt;br /&gt;
 &lt;br /&gt;
    lock.lock();&lt;br /&gt;
    try {&lt;br /&gt;
      // Checks the value against the desired value&lt;br /&gt;
      while (!value.equals(desiredValue)) {&lt;br /&gt;
        // This will wait until the value changes&lt;br /&gt;
        valueChanged.await();&lt;br /&gt;
      }&lt;br /&gt;
      // When we get here, the value is correct -- Run the task&lt;br /&gt;
      task.run();&lt;br /&gt;
    } finally {&lt;br /&gt;
      lock.unlock();&lt;br /&gt;
    }&lt;br /&gt;
  }&lt;br /&gt;
  public void append(E value) {&lt;br /&gt;
    // Start the pointer at this node&lt;br /&gt;
    LinkList&amp;lt;E&amp;gt; node = this;&lt;br /&gt;
    node.lock.lock();&lt;br /&gt;
    while (node.rest != null) {&lt;br /&gt;
      LinkList&amp;lt;E&amp;gt; next = node.rest;&lt;br /&gt;
      // Here&amp;quot;s the hand-over-hand locking&lt;br /&gt;
      try {&lt;br /&gt;
        // Lock the next node&lt;br /&gt;
        next.lock.lock();&lt;br /&gt;
      } finally {&lt;br /&gt;
        // unlock the current node&lt;br /&gt;
        node.lock.unlock();&lt;br /&gt;
      }&lt;br /&gt;
      // Traverse&lt;br /&gt;
      node = next;      &lt;br /&gt;
    }&lt;br /&gt;
    // We&amp;quot;re at the final node, so append and then unlock&lt;br /&gt;
    try {&lt;br /&gt;
      node.rest = new LinkList&amp;lt;E&amp;gt;(value);&lt;br /&gt;
      // Let any waiting threads know that this node&amp;quot;s link has changed&lt;br /&gt;
      node.linkChanged.signalAll();&lt;br /&gt;
    } finally {&lt;br /&gt;
      node.lock.unlock();&lt;br /&gt;
    }&lt;br /&gt;
  }&lt;br /&gt;
  public void printUntilInterrupted(String prefix) {&lt;br /&gt;
    // Start the pointer at this node&lt;br /&gt;
    LinkList&amp;lt;E&amp;gt; node = this;&lt;br /&gt;
    node.lock.lock();&lt;br /&gt;
    while (true) {&lt;br /&gt;
      LinkList&amp;lt;E&amp;gt; next;&lt;br /&gt;
      try {&lt;br /&gt;
        System.out.println(prefix + &amp;quot;: &amp;quot; + node.value);&lt;br /&gt;
        // Wait for the next node if not available&lt;br /&gt;
        while (node.rest == null) {&lt;br /&gt;
          node.linkChanged.await();&lt;br /&gt;
        }&lt;br /&gt;
        // Get the next node&lt;br /&gt;
        next = node.rest;&lt;br /&gt;
        // Lock it - more hand-to-hand locking&lt;br /&gt;
        next.lock.lock();&lt;br /&gt;
      } catch (InterruptedException e) {&lt;br /&gt;
        // reset the interrupt status&lt;br /&gt;
        Thread.currentThread().interrupt();&lt;br /&gt;
        return;&lt;br /&gt;
      } finally {&lt;br /&gt;
        node.lock.unlock();&lt;br /&gt;
      }&lt;br /&gt;
      // Traverse&lt;br /&gt;
      node = next;&lt;br /&gt;
    }&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
   &lt;br /&gt;
    &lt;br /&gt;
  &amp;lt;/source&amp;gt;&lt;br /&gt;
    &lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- end source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Lock: newCondition() ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- start source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
    &amp;lt;source lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
  &lt;br /&gt;
/*&lt;br /&gt;
License for Java 1.5 &amp;quot;Tiger&amp;quot;: A Developer&amp;quot;s Notebook&lt;br /&gt;
     (O&amp;quot;Reilly) example package&lt;br /&gt;
Java 1.5 &amp;quot;Tiger&amp;quot;: A Developer&amp;quot;s Notebook (O&amp;quot;Reilly) &lt;br /&gt;
by Brett McLaughlin and David Flanagan.&lt;br /&gt;
ISBN: 0-596-00738-8&lt;br /&gt;
You can use the examples and the source code any way you want, but&lt;br /&gt;
please include a reference to where it comes from if you use it in&lt;br /&gt;
your own products or services. Also note that this software is&lt;br /&gt;
provided by the author &amp;quot;as is&amp;quot;, with no expressed or implied warranties. &lt;br /&gt;
In no event shall the author be liable for any direct or indirect&lt;br /&gt;
damages arising in any way out of the use of this software.&lt;br /&gt;
*/&lt;br /&gt;
&lt;br /&gt;
import java.util.concurrent.locks.Condition;&lt;br /&gt;
import java.util.concurrent.locks.Lock;&lt;br /&gt;
import java.util.concurrent.locks.ReentrantLock;&lt;br /&gt;
 class LinkList&amp;lt;E&amp;gt; {&lt;br /&gt;
  // The value of this node&lt;br /&gt;
  E value;&lt;br /&gt;
  // The rest of the list&lt;br /&gt;
  LinkList&amp;lt;E&amp;gt; rest;&lt;br /&gt;
 &lt;br /&gt;
  // A lock for this node&lt;br /&gt;
  Lock lock;&lt;br /&gt;
  // Signals when the value of this node changes&lt;br /&gt;
  Condition valueChanged;&lt;br /&gt;
  // Signals when the node this is connected to changes&lt;br /&gt;
  Condition linkChanged;&lt;br /&gt;
  public LinkList(E value) {&lt;br /&gt;
    this.value = value;&lt;br /&gt;
    rest = null;&lt;br /&gt;
    lock = new ReentrantLock();&lt;br /&gt;
    valueChanged = lock.newCondition();&lt;br /&gt;
    linkChanged = lock.newCondition();&lt;br /&gt;
  }&lt;br /&gt;
  public void setValue(E value) {&lt;br /&gt;
    lock.lock();&lt;br /&gt;
    try {&lt;br /&gt;
      this.value = value;&lt;br /&gt;
      // Let waiting threads that the value has changed&lt;br /&gt;
      valueChanged.signalAll();&lt;br /&gt;
    } finally {&lt;br /&gt;
      lock.unlock();&lt;br /&gt;
    }&lt;br /&gt;
  }&lt;br /&gt;
  public void executeOnValue(E desiredValue, Runnable task)&lt;br /&gt;
    throws InterruptedException {&lt;br /&gt;
 &lt;br /&gt;
    lock.lock();&lt;br /&gt;
    try {&lt;br /&gt;
      // Checks the value against the desired value&lt;br /&gt;
      while (!value.equals(desiredValue)) {&lt;br /&gt;
        // This will wait until the value changes&lt;br /&gt;
        valueChanged.await();&lt;br /&gt;
      }&lt;br /&gt;
      // When we get here, the value is correct -- Run the task&lt;br /&gt;
      task.run();&lt;br /&gt;
    } finally {&lt;br /&gt;
      lock.unlock();&lt;br /&gt;
    }&lt;br /&gt;
  }&lt;br /&gt;
  public void append(E value) {&lt;br /&gt;
    // Start the pointer at this node&lt;br /&gt;
    LinkList&amp;lt;E&amp;gt; node = this;&lt;br /&gt;
    node.lock.lock();&lt;br /&gt;
    while (node.rest != null) {&lt;br /&gt;
      LinkList&amp;lt;E&amp;gt; next = node.rest;&lt;br /&gt;
      // Here&amp;quot;s the hand-over-hand locking&lt;br /&gt;
      try {&lt;br /&gt;
        // Lock the next node&lt;br /&gt;
        next.lock.lock();&lt;br /&gt;
      } finally {&lt;br /&gt;
        // unlock the current node&lt;br /&gt;
        node.lock.unlock();&lt;br /&gt;
      }&lt;br /&gt;
      // Traverse&lt;br /&gt;
      node = next;      &lt;br /&gt;
    }&lt;br /&gt;
    // We&amp;quot;re at the final node, so append and then unlock&lt;br /&gt;
    try {&lt;br /&gt;
      node.rest = new LinkList&amp;lt;E&amp;gt;(value);&lt;br /&gt;
      // Let any waiting threads know that this node&amp;quot;s link has changed&lt;br /&gt;
      node.linkChanged.signalAll();&lt;br /&gt;
    } finally {&lt;br /&gt;
      node.lock.unlock();&lt;br /&gt;
    }&lt;br /&gt;
  }&lt;br /&gt;
  public void printUntilInterrupted(String prefix) {&lt;br /&gt;
    // Start the pointer at this node&lt;br /&gt;
    LinkList&amp;lt;E&amp;gt; node = this;&lt;br /&gt;
    node.lock.lock();&lt;br /&gt;
    while (true) {&lt;br /&gt;
      LinkList&amp;lt;E&amp;gt; next;&lt;br /&gt;
      try {&lt;br /&gt;
        System.out.println(prefix + &amp;quot;: &amp;quot; + node.value);&lt;br /&gt;
        // Wait for the next node if not available&lt;br /&gt;
        while (node.rest == null) {&lt;br /&gt;
          node.linkChanged.await();&lt;br /&gt;
        }&lt;br /&gt;
        // Get the next node&lt;br /&gt;
        next = node.rest;&lt;br /&gt;
        // Lock it - more hand-to-hand locking&lt;br /&gt;
        next.lock.lock();&lt;br /&gt;
      } catch (InterruptedException e) {&lt;br /&gt;
        // reset the interrupt status&lt;br /&gt;
        Thread.currentThread().interrupt();&lt;br /&gt;
        return;&lt;br /&gt;
      } finally {&lt;br /&gt;
        node.lock.unlock();&lt;br /&gt;
      }&lt;br /&gt;
      // Traverse&lt;br /&gt;
      node = next;&lt;br /&gt;
    }&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
   &lt;br /&gt;
    &lt;br /&gt;
  &amp;lt;/source&amp;gt;&lt;br /&gt;
    &lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- end source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Lock: unlock() ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- start source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
    &amp;lt;source lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
  &lt;br /&gt;
/*&lt;br /&gt;
License for Java 1.5 &amp;quot;Tiger&amp;quot;: A Developer&amp;quot;s Notebook&lt;br /&gt;
     (O&amp;quot;Reilly) example package&lt;br /&gt;
Java 1.5 &amp;quot;Tiger&amp;quot;: A Developer&amp;quot;s Notebook (O&amp;quot;Reilly) &lt;br /&gt;
by Brett McLaughlin and David Flanagan.&lt;br /&gt;
ISBN: 0-596-00738-8&lt;br /&gt;
You can use the examples and the source code any way you want, but&lt;br /&gt;
please include a reference to where it comes from if you use it in&lt;br /&gt;
your own products or services. Also note that this software is&lt;br /&gt;
provided by the author &amp;quot;as is&amp;quot;, with no expressed or implied warranties. &lt;br /&gt;
In no event shall the author be liable for any direct or indirect&lt;br /&gt;
damages arising in any way out of the use of this software.&lt;br /&gt;
*/&lt;br /&gt;
&lt;br /&gt;
import java.util.concurrent.locks.Condition;&lt;br /&gt;
import java.util.concurrent.locks.Lock;&lt;br /&gt;
import java.util.concurrent.locks.ReentrantLock;&lt;br /&gt;
 class LinkList&amp;lt;E&amp;gt; {&lt;br /&gt;
  // The value of this node&lt;br /&gt;
  E value;&lt;br /&gt;
  // The rest of the list&lt;br /&gt;
  LinkList&amp;lt;E&amp;gt; rest;&lt;br /&gt;
 &lt;br /&gt;
  // A lock for this node&lt;br /&gt;
  Lock lock;&lt;br /&gt;
  // Signals when the value of this node changes&lt;br /&gt;
  Condition valueChanged;&lt;br /&gt;
  // Signals when the node this is connected to changes&lt;br /&gt;
  Condition linkChanged;&lt;br /&gt;
  public LinkList(E value) {&lt;br /&gt;
    this.value = value;&lt;br /&gt;
    rest = null;&lt;br /&gt;
    lock = new ReentrantLock();&lt;br /&gt;
    valueChanged = lock.newCondition();&lt;br /&gt;
    linkChanged = lock.newCondition();&lt;br /&gt;
  }&lt;br /&gt;
  public void setValue(E value) {&lt;br /&gt;
    lock.lock();&lt;br /&gt;
    try {&lt;br /&gt;
      this.value = value;&lt;br /&gt;
      // Let waiting threads that the value has changed&lt;br /&gt;
      valueChanged.signalAll();&lt;br /&gt;
    } finally {&lt;br /&gt;
      lock.unlock();&lt;br /&gt;
    }&lt;br /&gt;
  }&lt;br /&gt;
  public void executeOnValue(E desiredValue, Runnable task)&lt;br /&gt;
    throws InterruptedException {&lt;br /&gt;
 &lt;br /&gt;
    lock.lock();&lt;br /&gt;
    try {&lt;br /&gt;
      // Checks the value against the desired value&lt;br /&gt;
      while (!value.equals(desiredValue)) {&lt;br /&gt;
        // This will wait until the value changes&lt;br /&gt;
        valueChanged.await();&lt;br /&gt;
      }&lt;br /&gt;
      // When we get here, the value is correct -- Run the task&lt;br /&gt;
      task.run();&lt;br /&gt;
    } finally {&lt;br /&gt;
      lock.unlock();&lt;br /&gt;
    }&lt;br /&gt;
  }&lt;br /&gt;
  public void append(E value) {&lt;br /&gt;
    // Start the pointer at this node&lt;br /&gt;
    LinkList&amp;lt;E&amp;gt; node = this;&lt;br /&gt;
    node.lock.lock();&lt;br /&gt;
    while (node.rest != null) {&lt;br /&gt;
      LinkList&amp;lt;E&amp;gt; next = node.rest;&lt;br /&gt;
      // Here&amp;quot;s the hand-over-hand locking&lt;br /&gt;
      try {&lt;br /&gt;
        // Lock the next node&lt;br /&gt;
        next.lock.lock();&lt;br /&gt;
      } finally {&lt;br /&gt;
        // unlock the current node&lt;br /&gt;
        node.lock.unlock();&lt;br /&gt;
      }&lt;br /&gt;
      // Traverse&lt;br /&gt;
      node = next;      &lt;br /&gt;
    }&lt;br /&gt;
    // We&amp;quot;re at the final node, so append and then unlock&lt;br /&gt;
    try {&lt;br /&gt;
      node.rest = new LinkList&amp;lt;E&amp;gt;(value);&lt;br /&gt;
      // Let any waiting threads know that this node&amp;quot;s link has changed&lt;br /&gt;
      node.linkChanged.signalAll();&lt;br /&gt;
    } finally {&lt;br /&gt;
      node.lock.unlock();&lt;br /&gt;
    }&lt;br /&gt;
  }&lt;br /&gt;
  public void printUntilInterrupted(String prefix) {&lt;br /&gt;
    // Start the pointer at this node&lt;br /&gt;
    LinkList&amp;lt;E&amp;gt; node = this;&lt;br /&gt;
    node.lock.lock();&lt;br /&gt;
    while (true) {&lt;br /&gt;
      LinkList&amp;lt;E&amp;gt; next;&lt;br /&gt;
      try {&lt;br /&gt;
        System.out.println(prefix + &amp;quot;: &amp;quot; + node.value);&lt;br /&gt;
        // Wait for the next node if not available&lt;br /&gt;
        while (node.rest == null) {&lt;br /&gt;
          node.linkChanged.await();&lt;br /&gt;
        }&lt;br /&gt;
        // Get the next node&lt;br /&gt;
        next = node.rest;&lt;br /&gt;
        // Lock it - more hand-to-hand locking&lt;br /&gt;
        next.lock.lock();&lt;br /&gt;
      } catch (InterruptedException e) {&lt;br /&gt;
        // reset the interrupt status&lt;br /&gt;
        Thread.currentThread().interrupt();&lt;br /&gt;
        return;&lt;br /&gt;
      } finally {&lt;br /&gt;
        node.lock.unlock();&lt;br /&gt;
      }&lt;br /&gt;
      // Traverse&lt;br /&gt;
      node = next;&lt;br /&gt;
    }&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
   &lt;br /&gt;
    &lt;br /&gt;
  &amp;lt;/source&amp;gt;&lt;br /&gt;
    &lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- end source code --&amp;gt;&lt;/div&gt;</summary>
		<author><name>Admin</name></author>	</entry>

	</feed>