Unterschiede
Hier werden die Unterschiede zwischen der gewählten und der aktuellen Version gezeigt.
| java:thread-wait-notify 2010/04/26 07:20 | java:thread-wait-notify 2020/01/22 20:59 aktuell | ||
|---|---|---|---|
| Zeile 1: | Zeile 1: | ||
| + | [[java|Java - Allgemein]]\\ | ||
| ====== Thread, wait() und notify() ====== | ====== Thread, wait() und notify() ====== | ||
| - | Das Beispiel zeigt einen MasterThread, welcher von seinem eigenen ChildThread nach Fertigstellung des Selbigen gewecht wird: | + | Das Beispiel zeigt einen MasterThread, welcher einen ChildThread startet und sich dann "schlafen legt" um anschließend von seinem eigenen ChildThread nach Fertigstellung des Selbigen wieder geweckt wird: |
| <code java> | <code java> | ||
| package com.sowas.javawiki.waitnotify; | package com.sowas.javawiki.waitnotify; | ||
| Zeile 13: | Zeile 14: | ||
| public void run() { | public void run() { | ||
| System.out.println("MasterThread startet"); | System.out.println("MasterThread startet"); | ||
| - | synchronized (this) { | + | synchronized(this) { |
| service.execute(new ChildThread(this)); | service.execute(new ChildThread(this)); | ||
| try { | try { | ||
| - | this.wait(); | + | wait(); |
| } catch (InterruptedException e) { | } catch (InterruptedException e) { | ||
| e.printStackTrace(); | e.printStackTrace(); | ||