{"id":1091,"date":"2011-08-21T00:19:17","date_gmt":"2011-08-20T22:19:17","guid":{"rendered":"http:\/\/www.tutego.de\/blog\/javainsel\/2011\/08\/mein-buchbeispiel-ist-falsch-und-nur-einem-fllt-es-auf-und-sagt-es\/"},"modified":"2011-08-21T00:21:59","modified_gmt":"2011-08-20T22:21:59","slug":"mein-buchbeispiel-ist-falsch-und-nur-einem-fllt-es-auf-und-sagt-es","status":"publish","type":"post","link":"https:\/\/www.tutego.de\/blog\/javainsel\/2011\/08\/mein-buchbeispiel-ist-falsch-und-nur-einem-fllt-es-auf-und-sagt-es\/","title":{"rendered":"Mein Buchbeispiel ist falsch (und nur einem f&auml;llt es auf und sagt es)"},"content":{"rendered":"<p>Das folgende Code f\u00fcr mein Semaphoren-Beispiel (<a href=\"http:\/\/openbook.galileodesign.de\/javainsel7\/javainsel_10_006.htm\">http:\/\/openbook.galileodesign.de\/javainsel7\/javainsel_10_006.htm<\/a>) habe ich vereinfacht und ist so <strong>nicht wirklich korrekt<\/strong>:<\/p>\n<pre><pre style=\"background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 10px\">  1: <span style=\"color: #0000ff\">static<\/span> Runnable r = <span style=\"color: #0000ff\">new<\/span> Runnable() { \n<\/pre>\n<pre style=\"background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 10px\">  2:     <span style=\"color: #0000ff\">public<\/span> <span style=\"color: #0000ff\">void<\/span> run() { \n<\/pre>\n<pre style=\"background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 10px\">  3:       <span style=\"color: #0000ff\">while<\/span> ( <span style=\"color: #0000ff\">true<\/span> ) { \n<\/pre>\n<pre style=\"background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 10px\">  4:         <span style=\"color: #0000ff\">try<\/span> \n<\/pre>\n<pre style=\"background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 10px\">  5:         { \n<\/pre>\n<pre style=\"background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 10px\">  6:           semaphore.acquire(); \n<\/pre>\n<pre style=\"background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 10px\">  7:  \n<\/pre>\n<pre style=\"background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 10px\">  8:           System.out.println( &quot;<span style=\"color: #8b0000\">Thread=<\/span>&quot; + Thread.currentThread().getName() + \n<\/pre>\n<pre style=\"background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 10px\">  9:                        &quot;<span style=\"color: #8b0000\">, Available Permits=<\/span>&quot; + semaphore.availablePermits() ); \n<\/pre>\n<pre style=\"background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 10px\"> 10:           Thread.sleep( 2000 ); \n<\/pre>\n<pre style=\"background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 10px\"> 11:         } \n<\/pre>\n<pre style=\"background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 10px\"> 12:         <span style=\"color: #0000ff\">catch<\/span> ( InterruptedException e ) { \n<\/pre>\n<pre style=\"background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 10px\"> 13:           e.printStackTrace(); \n<\/pre>\n<pre style=\"background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 10px\"> 14:         } \n<\/pre>\n<pre style=\"background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 10px\"> 15:         <span style=\"color: #0000ff\">finally<\/span> { \n<\/pre>\n<pre style=\"background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 10px\"> 16:           semaphore.release(); \n<\/pre>\n<pre style=\"background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 10px\"> 17:         } \n<\/pre>\n<pre style=\"background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 10px\"> 18:       } \n<\/pre>\n<pre style=\"background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 10px\"> 19:     } \n<\/pre>\n<pre style=\"background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 10px\"> 20:   };<\/pre>\n<p>Wer findet den Fehler noch?<\/p>\n<p>Nun, in der 10. Auflage ist der Fehler jedenfalls korrigiert und ein Dank geht an Marco V\u00f6lz.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Das folgende Code f\u00fcr mein Semaphoren-Beispiel (http:\/\/openbook.galileodesign.de\/javainsel7\/javainsel_10_006.htm) habe ich vereinfacht und ist so nicht wirklich korrekt: 1: static Runnable r = new Runnable() { 2: public void run() { 3: while ( true ) { 4: try 5: { 6: semaphore.acquire(); 7: 8: System.out.println( &quot;Thread=&quot; + Thread.currentThread().getName() + 9: &quot;, Available Permits=&quot; + semaphore.availablePermits() ); [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":"","_links_to":"","_links_to_target":""},"categories":[11],"tags":[],"class_list":["post-1091","post","type-post","status-publish","format-standard","hentry","category-insel"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.tutego.de\/blog\/javainsel\/wp-json\/wp\/v2\/posts\/1091","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.tutego.de\/blog\/javainsel\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.tutego.de\/blog\/javainsel\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.tutego.de\/blog\/javainsel\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tutego.de\/blog\/javainsel\/wp-json\/wp\/v2\/comments?post=1091"}],"version-history":[{"count":3,"href":"https:\/\/www.tutego.de\/blog\/javainsel\/wp-json\/wp\/v2\/posts\/1091\/revisions"}],"predecessor-version":[{"id":1094,"href":"https:\/\/www.tutego.de\/blog\/javainsel\/wp-json\/wp\/v2\/posts\/1091\/revisions\/1094"}],"wp:attachment":[{"href":"https:\/\/www.tutego.de\/blog\/javainsel\/wp-json\/wp\/v2\/media?parent=1091"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tutego.de\/blog\/javainsel\/wp-json\/wp\/v2\/categories?post=1091"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tutego.de\/blog\/javainsel\/wp-json\/wp\/v2\/tags?post=1091"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}